Skip to content

Commit

Permalink
Add telemetry/event support
Browse files Browse the repository at this point in the history
This PR fix #430

The OSUtils was renamed to Platform which is more generic (eclipse like
name) which contains information about OS, JVM (name, version, memory).

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Jul 10, 2019
1 parent 0c018a2 commit 33f2df3
Show file tree
Hide file tree
Showing 13 changed files with 525 additions and 18 deletions.
171 changes: 171 additions & 0 deletions org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/Platform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*******************************************************************************
* Copyright (c) 2019 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
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/

package org.eclipse.lsp4xml;

/**
* PLatform information about OS and JVM.
*/
public class Platform {

private static final OS os = new OS();

public static final boolean isWindows = getOS().isWindows();
public static String SLASH = isWindows ? "\\" : "/";

/**
* OS information
*/
public static class OS {

private final String name;

private final String version;

private final String arch;

private final transient boolean isWindows;

public OS() {
this.name = getSystemProperty("os.name");
this.version = getSystemProperty("os.version");
this.arch = getSystemProperty("os.arch");
isWindows = name != null && name.toLowerCase().indexOf("win") >= 0;
}

/**
* Returns the OS name.
*
* @return the OS name.
*/
public String getName() {
return name;
}

/**
* Returns the OS version.
*
* @return the OS version.
*/
public String getVersion() {
return version;
}

/**
* Returns the OS arch.
*
* @return the OS arch.
*/
public String getArch() {
return arch;
}

public boolean isWindows() {
return isWindows;
}
}

/**
* JVM information
*
*/
public static class JVM {

/**
* JVM memory information
*
*/
public static class Memory {

private final long free;

private final long total;

private final long max;

private Memory() {
super();
this.free = Runtime.getRuntime().freeMemory();
this.total = Runtime.getRuntime().totalMemory();
this.max = Runtime.getRuntime().maxMemory();
}

public long getFree() {
return free;
}

public long getTotal() {
return total;
}

public long getMax() {
return max;
}

}

private final String name;

private final String version;

private final Memory memory;

public JVM() {
this.name = getSystemProperty("java.vm.name");
this.version = getSystemProperty("java.version");
this.memory = new Memory();
}

/**
* Returns the JVM name
*
* @return the JVM name
*/
public String getName() {
return name;
}

/**
* Returns the JVM version
*
* @return the JVM version
*/
public String getVersion() {
return version;
}

public Memory getMemory() {
return memory;
}
}

/**
* Returns the OS information.
*
* @return the OS information.
*/
public static OS getOS() {
return os;
}

/**
* Returns the system property from the given key and null otherwise.
*
* @param key the property system key
* @return the system property from the given key and null otherwise.
*/
private static String getSystemProperty(String key) {
try {
return System.getProperty(key);
} catch (SecurityException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@
import org.eclipse.lsp4xml.settings.XMLGeneralClientSettings;
import org.eclipse.lsp4xml.settings.XMLIncrementalSupportSettings;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;
import org.eclipse.lsp4xml.settings.XMLTelemetrySettings;
import org.eclipse.lsp4xml.settings.capabilities.InitializationOptionsExtendedClientCapabilities;
import org.eclipse.lsp4xml.settings.capabilities.ServerCapabilitiesInitializer;
import org.eclipse.lsp4xml.settings.capabilities.XMLCapabilityManager;
import org.eclipse.lsp4xml.telemetry.TelemetryManager;
import org.eclipse.lsp4xml.utils.FilesUtils;

/**
Expand All @@ -74,6 +76,7 @@ public class XMLLanguageServer
private final ScheduledExecutorService delayer;
private Integer parentProcessId;
public XMLCapabilityManager capabilityManager;
private TelemetryManager telemetryManager;

public XMLLanguageServer() {
xmlLanguageService = new XMLLanguageService();
Expand Down Expand Up @@ -116,6 +119,7 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
@Override
public void initialized(InitializedParams params) {
capabilityManager.initializeCapabilities();
getTelemetryManager().onInitialized(params);
}

/**
Expand Down Expand Up @@ -164,6 +168,11 @@ public synchronized void updateSettings(Object initializationOptionsSettings) {
FilesUtils.setCachePathSetting(workDir);
}

XMLTelemetrySettings newTelemetry = xmlClientSettings.getTelemetry();
if (newTelemetry != null) {
getTelemetryManager().setEnabled(newTelemetry.isEnabled());
}

XMLExperimentalSettings experimentalSettings = xmlClientSettings.getExperimental();
if (experimentalSettings != null) {
XMLIncrementalSupportSettings incrementalSettings = experimentalSettings.getIncrementalSupport();
Expand Down Expand Up @@ -212,6 +221,7 @@ public WorkspaceService getWorkspaceService() {
public void setClient(LanguageClient languageClient) {
this.languageClient = languageClient;
capabilityManager = new XMLCapabilityManager(this.languageClient, xmlTextDocumentService);
telemetryManager = new TelemetryManager(languageClient);
}

public LanguageClient getLanguageClient() {
Expand Down Expand Up @@ -247,4 +257,13 @@ public DOMDocument getDocument(String uri) {
ModelTextDocument<DOMDocument> document = xmlTextDocumentService.getDocument(uri);
return document != null ? document.getModel().getNow(null) : null;
}

/**
* Returns the telemetry manager.
*
* @return the telemetry manager.
*/
public TelemetryManager getTelemetryManager() {
return telemetryManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLIncrementalSupportSettings;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;
import org.eclipse.lsp4xml.settings.capabilities.ServerCapabilitiesConstants;
import org.eclipse.lsp4xml.utils.XMLPositionUtility;

/**
Expand Down Expand Up @@ -144,8 +145,11 @@ public XMLTextDocumentService(XMLLanguageServer xmlLanguageServer) {
this.sharedSettings = new SharedSettings();
}

public void updateClientCapabilities(ClientCapabilities capabilities, ExtendedClientCapabilities extendedClientCapabilities) {
TextDocumentClientCapabilities textDocumentClientCapabilities = capabilities.getTextDocument();
public void updateClientCapabilities(ClientCapabilities capabilities,
ExtendedClientCapabilities extendedClientCapabilities) {
TextDocumentClientCapabilities textDocumentClientCapabilities = capabilities != null
? capabilities.getTextDocument()
: null;
if (textDocumentClientCapabilities != null) {
// Completion settings
sharedSettings.completionSettings.setCapabilities(textDocumentClientCapabilities.getCompletion());
Expand All @@ -160,7 +164,7 @@ public void updateClientCapabilities(ClientCapabilities capabilities, ExtendedCl
}
if (extendedClientCapabilities != null) {
// Extended client capabilities
sharedSettings.getCodeLensSettings().setCodeLens(extendedClientCapabilities.getCodeLens());
sharedSettings.getCodeLensSettings().setCodeLens(extendedClientCapabilities.getCodeLens());
}
}

Expand Down Expand Up @@ -225,6 +229,7 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> docume

@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
xmlLanguageServer.getTelemetryManager().onServiceCall(ServerCapabilitiesConstants.TEXT_DOCUMENT_FORMATTING);
return computeAsync((cancelChecker) -> {
String uri = params.getTextDocument().getUri();
TextDocument document = getDocument(uri);
Expand All @@ -235,6 +240,8 @@ public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormatting

@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
xmlLanguageServer.getTelemetryManager()
.onServiceCall(ServerCapabilitiesConstants.TEXT_DOCUMENT_RANGE_FORMATTING);
return computeAsync((cancelChecker) -> {
String uri = params.getTextDocument().getUri();
TextDocument document = getDocument(uri);
Expand All @@ -245,6 +252,7 @@ public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRange

@Override
public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
xmlLanguageServer.getTelemetryManager().onServiceCall(ServerCapabilitiesConstants.TEXT_DOCUMENT_RENAME);
return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
return getXMLLanguageService().doRename(xmlDocument, params.getPosition(), params.getNewName());
});
Expand Down Expand Up @@ -319,7 +327,8 @@ public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams param
return CompletableFuture.completedFuture(Collections.emptyList());
}
return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
return getXMLLanguageService().getCodeLens(xmlDocument, sharedSettings.getCodeLensSettings(), cancelChecker);
return getXMLLanguageService().getCodeLens(xmlDocument, sharedSettings.getCodeLensSettings(),
cancelChecker);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.lsp4xml.commons;

import static org.eclipse.lsp4xml.utils.OSUtils.isWindows;
import static org.eclipse.lsp4xml.Platform.isWindows;

import java.io.IOException;
import java.util.concurrent.Executors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

package org.eclipse.lsp4xml.extensions.general.completion;

import static org.eclipse.lsp4xml.Platform.isWindows;
import static org.eclipse.lsp4xml.utils.FilesUtils.convertToWindowsPath;
import static org.eclipse.lsp4xml.utils.FilesUtils.getFilePathSlash;
import static org.eclipse.lsp4xml.utils.FilesUtils.getNormalizedPath;
import static org.eclipse.lsp4xml.utils.OSUtils.isWindows;
import static org.eclipse.lsp4xml.utils.StringUtils.isEmpty;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class XMLGeneralClientSettings {

private XMLCodeLensSettings codeLens;

private XMLTelemetrySettings telemetry;

private XMLExperimentalSettings experimental;

public XMLExperimentalSettings getExperimental() {
Expand Down Expand Up @@ -90,6 +92,24 @@ public void setCodeLens(XMLCodeLensSettings codeLens) {
this.codeLens = codeLens;
}

/**
* Returns the telemetry settings.
*
* @return the telemetry settings.
*/
public XMLTelemetrySettings getTelemetry() {
return telemetry;
}

/**
* Set the telemetry settings
*
* @param telemetry the telementry setting
*/
public void setTelemetry(XMLTelemetrySettings telemetry) {
this.telemetry = telemetry;
}

public void setFormat(XMLFormattingOptions format) {
this.format = format;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
* Red Hat Inc. - initial API and implementation
*******************************************************************************/

package org.eclipse.lsp4xml.utils;
package org.eclipse.lsp4xml.settings;

/**
* OSUtils
* Telemetry settings
*/
public class OSUtils {

public static final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
public static String SLASH = isWindows ? "\\" : "/";
public class XMLTelemetrySettings {


}
private boolean enabled;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

}
Loading

0 comments on commit 33f2df3

Please sign in to comment.