From 503a4ea2a9d2e57e959944d0e71b0a31663cb867 Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Mon, 23 Aug 2021 10:33:23 -0400 Subject: [PATCH] Report grammar identifier to didOpen telemetry events. - Fixes #1105 - When exactly 1 grammar reference exists per file, simply send the relevant values (not a list of size 1). Otherwise, send the values as a list Signed-off-by: Roland Grunberg --- USAGE_DATA.md | 1 + .../telemetry/DocumentTelemetryInfo.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/USAGE_DATA.md b/USAGE_DATA.md index 2c3a147a38..6038da7859 100644 --- a/USAGE_DATA.md +++ b/USAGE_DATA.md @@ -17,6 +17,7 @@ When telemetry events are enabled, the following information is emitted when the * When a document is opened : * The file extension (eg. `xml`, `xsd`, `dtd`) * The associated grammar types (eg. `none`, `doctype`, `xml-model`, `xsi:schemaLocation`, `xsi:noNamespaceSchemaLocation`) + * The grammar identifiers for an XML document (eg. `http://maven.apache.org/xsd/maven-4.0.0.xsd`) * The resolver used to resolve the grammar identifier (eg. `catalog`, `file association`, `embedded catalog.xsd`, `embedded xml.xsd`, `embedded xslt.xsd`) * Note: Does NOT include the `JAVA_HOME` environment variable for privacy reasons diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/telemetry/DocumentTelemetryInfo.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/telemetry/DocumentTelemetryInfo.java index 6fd42e4379..c515883c69 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/telemetry/DocumentTelemetryInfo.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/telemetry/DocumentTelemetryInfo.java @@ -25,6 +25,7 @@ public class DocumentTelemetryInfo { private static final String DOC_PROP_EXT = "file.extension"; private static final String DOC_PROP_RESOLVER = "file.resolver"; + private static final String DOC_PROP_IDENTIFIER = "file.identifier"; private static final String DOC_PROP_GRAMMAR_NONE = "file.grammar.none"; private static final String DOC_PROP_GRAMMAR_DOCTYPE = "file.grammar.doctype"; private static final String DOC_PROP_GRAMMAR_XMLMODEL = "file.grammar.xmlmodel"; @@ -45,9 +46,11 @@ public static Map getDocumentTelemetryInfo (DOMDocument doc, Con } } else { List resolvers = new ArrayList(); + List identifiers = new ArrayList(); for (ReferencedGrammarInfo info : referencedGrammarInfos) { String kind = info.getBindingKind() == null ? "none" : info.getBindingKind(); String resolver = info.getResolvedBy(); + String identifier = info.getIdentifierURI(); if ("xml".equals(fileExtension)) { switch (kind) { case "none": @@ -67,10 +70,25 @@ public static Map getDocumentTelemetryInfo (DOMDocument doc, Con break; } } + if (identifier != null) { + int limit = Math.min(identifier.length(), 200); // 200 char limit + identifiers.add(identifier.substring(0, limit)); + } resolvers.add(resolver == null ? "default" : resolver); } - props.put(DOC_PROP_RESOLVER, resolvers); + if (resolvers.size() == 1) { + props.put(DOC_PROP_RESOLVER, resolvers.iterator().next()); + } else { + props.put(DOC_PROP_RESOLVER, resolvers); + } + if (!identifiers.isEmpty()) { + if (identifiers.size() == 1) { + props.put(DOC_PROP_IDENTIFIER, identifiers.iterator().next()); + } else { + props.put(DOC_PROP_IDENTIFIER, identifiers); + } + } } return props; }