PT #151674858 Live boot hint decorations on/off
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
/**
|
||||
* Boot-Java LS settings
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public class BootJavaConfig {
|
||||
|
||||
private Settings settings = new Settings(null);
|
||||
|
||||
public boolean isBootHintsEnabled() {
|
||||
Boolean enabled = (Boolean) settings.getProperty("boot-java", "boot-hints", "on");
|
||||
return enabled == null || enabled.booleanValue();
|
||||
}
|
||||
|
||||
public void handleConfigurationChange(Settings newConfig) {
|
||||
Log.info("Settings received: "+newConfig);
|
||||
this.settings = newConfig;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -74,15 +74,18 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
private final SpringPropertyIndexProvider propertyIndexProvider;
|
||||
private final SpringLiveHoverWatchdog liveHoverWatchdog;
|
||||
private final ProjectObserver projectObserver;
|
||||
private final BootJavaConfig config;
|
||||
|
||||
private final WordHighlighter testHightlighter = null; //new WordHighlighter("foo");
|
||||
|
||||
private JavaProjectFinder projectFinder;
|
||||
|
||||
public BootJavaLanguageServer(LSFactory<BootJavaLanguageServerParams> _params) {
|
||||
super("vscode-boot-java");
|
||||
super("boot-java");
|
||||
BootJavaLanguageServerParams serverParams = _params.create(this);
|
||||
|
||||
this.config = new BootJavaConfig();
|
||||
|
||||
propertyIndexProvider = serverParams.indexProvider;
|
||||
|
||||
System.setProperty(LANGUAGE_SERVER_PROCESS_PROPERTY, LANGUAGE_SERVER_PROCESS_PROPERTY);
|
||||
@@ -134,6 +137,15 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
documents.onCodeLens(codeLensHandler::createCodeLenses);
|
||||
documents.onCodeLensResolve(codeLensHandler::resolveCodeLens);
|
||||
|
||||
workspaceService.onDidChangeConfiguraton(settings -> {
|
||||
config.handleConfigurationChange(settings);
|
||||
if (config.isBootHintsEnabled()) {
|
||||
liveHoverWatchdog.enableHighlights();
|
||||
} else {
|
||||
liveHoverWatchdog.disableHighlights();
|
||||
}
|
||||
});
|
||||
|
||||
projectFinder = serverParams.projectFinder;
|
||||
projectObserver = serverParams.projectObserver;
|
||||
}
|
||||
@@ -295,4 +307,8 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
public SpringPropertyIndexProvider getSpringPropertyIndexProvider() {
|
||||
return propertyIndexProvider;
|
||||
}
|
||||
|
||||
public BootJavaConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.HoverHandler;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
@@ -52,11 +51,11 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
public class BootJavaHoverProvider implements HoverHandler {
|
||||
|
||||
private JavaProjectFinder projectFinder;
|
||||
private SimpleLanguageServer server;
|
||||
private BootJavaLanguageServer server;
|
||||
private Map<String, HoverProvider> hoverProviders;
|
||||
private RunningAppProvider runningAppProvider;
|
||||
|
||||
public BootJavaHoverProvider(SimpleLanguageServer server, JavaProjectFinder projectFinder, Map<String, HoverProvider> specificProviders, RunningAppProvider runningAppProvider) {
|
||||
public BootJavaHoverProvider(BootJavaLanguageServer server, JavaProjectFinder projectFinder, Map<String, HoverProvider> specificProviders, RunningAppProvider runningAppProvider) {
|
||||
this.server = server;
|
||||
this.projectFinder = projectFinder;
|
||||
this.hoverProviders = specificProviders;
|
||||
|
||||
@@ -38,7 +38,9 @@ public class SpringLiveHoverWatchdog {
|
||||
private final BootJavaHoverProvider hoverProvider;
|
||||
private RunningAppProvider runningAppProvider;
|
||||
|
||||
private final Timer timer;
|
||||
private boolean highlightsEnabled = true;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
|
||||
public SpringLiveHoverWatchdog(SimpleLanguageServer server, BootJavaHoverProvider hoverProvider, RunningAppProvider runningAppProvider) {
|
||||
@@ -46,23 +48,29 @@ public class SpringLiveHoverWatchdog {
|
||||
this.hoverProvider = hoverProvider;
|
||||
this.runningAppProvider = runningAppProvider;
|
||||
this.watchedDocs = new ConcurrentSkipListSet<>();
|
||||
|
||||
this.timer = new Timer();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
update();
|
||||
}
|
||||
};
|
||||
if (highlightsEnabled && timer == null) {
|
||||
this.timer = new Timer();
|
||||
|
||||
timer.scheduleAtFixedRate(task, 0, POLLING_INTERVAL_MILLISECONDS);
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
update();
|
||||
}
|
||||
};
|
||||
|
||||
timer.scheduleAtFixedRate(task, 0, POLLING_INTERVAL_MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
timer.cancel();
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
watchedDocs.forEach(uri -> cleanupLiveHints(uri));
|
||||
}
|
||||
}
|
||||
|
||||
public void watchDocument(String docURI) {
|
||||
@@ -79,18 +87,20 @@ public class SpringLiveHoverWatchdog {
|
||||
}
|
||||
|
||||
public void update(String docURI) {
|
||||
try {
|
||||
SpringBootApp[] runningBootApps = runningAppProvider.getAllRunningSpringApps().stream()
|
||||
.filter((app) -> !app.containsSystemProperty(BootJavaLanguageServer.LANGUAGE_SERVER_PROCESS_PROPERTY))
|
||||
.toArray(SpringBootApp[]::new);
|
||||
if (highlightsEnabled) {
|
||||
try {
|
||||
SpringBootApp[] runningBootApps = runningAppProvider.getAllRunningSpringApps().stream()
|
||||
.filter((app) -> !app.containsSystemProperty(BootJavaLanguageServer.LANGUAGE_SERVER_PROCESS_PROPERTY))
|
||||
.toArray(SpringBootApp[]::new);
|
||||
|
||||
TextDocument doc = this.server.getTextDocumentService().get(docURI);
|
||||
if (doc != null) {
|
||||
Range[] ranges = this.hoverProvider.getLiveHoverHints(doc, runningBootApps);
|
||||
publishLiveHints(docURI, ranges);
|
||||
TextDocument doc = this.server.getTextDocumentService().get(docURI);
|
||||
if (doc != null) {
|
||||
Range[] ranges = this.hoverProvider.getLiveHoverHints(doc, runningBootApps);
|
||||
publishLiveHints(docURI, ranges);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,11 +117,25 @@ public class SpringLiveHoverWatchdog {
|
||||
}
|
||||
|
||||
private void cleanupLiveHints(String docURI) {
|
||||
// TODO: send client a message to cleanup live hover diagnostics data
|
||||
publishLiveHints(docURI, new Range[0]);
|
||||
}
|
||||
|
||||
private void cleanupResources() {
|
||||
// TODO: close and cleanup open JMX connections and cached data
|
||||
}
|
||||
|
||||
public void enableHighlights() {
|
||||
if (!highlightsEnabled) {
|
||||
highlightsEnabled = true;
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
public void disableHighlights() {
|
||||
if (highlightsEnabled) {
|
||||
highlightsEnabled = false;
|
||||
shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user