forked from eclipse-lemminx/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report telemetry events for text document services.
- Resolves eclipse-lemminx#1066 - Report file extensions for didOpen Signed-off-by: Roland Grunberg <[email protected]>
- Loading branch information
Showing
7 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...rg/eclipse/lemminx/extensions/contentmodel/participants/DocumentTelemetryParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.contentmodel.participants; | ||
|
||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.extensions.contentmodel.model.ContentModelManager; | ||
import org.eclipse.lemminx.services.extensions.IDocumentLifecycleParticipant; | ||
import org.eclipse.lemminx.telemetry.TelemetryManager; | ||
|
||
public class DocumentTelemetryParticipant implements IDocumentLifecycleParticipant { | ||
|
||
private TelemetryManager telemetryManager; | ||
|
||
private ContentModelManager contentManager; | ||
|
||
public DocumentTelemetryParticipant(TelemetryManager telemetryManager, ContentModelManager contentManager) { | ||
this.telemetryManager = telemetryManager; | ||
this.contentManager = contentManager; | ||
} | ||
|
||
@Override | ||
public void didOpen(DOMDocument document) { | ||
telemetryManager.onDidOpen(document, contentManager); | ||
} | ||
|
||
@Override | ||
public void didChange(DOMDocument document) {} | ||
|
||
@Override | ||
public void didSave(DOMDocument document) {} | ||
|
||
@Override | ||
public void didClose(DOMDocument document) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/telemetry/DocumentTelemetryInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.telemetry; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.extensions.contentmodel.model.ContentModelManager; | ||
import org.eclipse.lemminx.extensions.contentmodel.model.ReferencedGrammarInfo; | ||
|
||
public class DocumentTelemetryInfo { | ||
|
||
private static final String DOC_PROP_EXT = "file.extension"; | ||
private static final String DOC_PROP_GRAMMAR = "file.grammar"; | ||
private static final String DOC_PROP_GRAMMAR_EXTERNAL = "file.grammar.external"; | ||
|
||
public static Map<String, Object> getDocumentTelemetryInfo (DOMDocument doc, ContentModelManager manager) { | ||
String uri = doc.getDocumentURI(); | ||
int index = uri.lastIndexOf('.'); | ||
String fileExtension = uri.substring(index + 1, uri.length()); | ||
Set<ReferencedGrammarInfo> referencedGrammarInfos = manager.getReferencedGrammarInfos(doc); | ||
HashMap<String, Object> props = new HashMap<>(); | ||
props.put(DOC_PROP_EXT, fileExtension); | ||
|
||
if (referencedGrammarInfos.isEmpty()) { | ||
props.put(DOC_PROP_GRAMMAR, "none"); | ||
} else { | ||
List<String> values = new ArrayList<String>(); | ||
for (ReferencedGrammarInfo info : referencedGrammarInfos) { | ||
String kind = info.getIdentifier().getKind(); | ||
if (kind == null) { | ||
kind = info.getIdentifier().getPublicId(); | ||
} | ||
values.add(kind); | ||
} | ||
props.put(DOC_PROP_GRAMMAR, values); | ||
props.put(DOC_PROP_GRAMMAR_EXTERNAL, doc.hasExternalGrammar()); | ||
} | ||
return props; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters