diff --git a/atom-extensions/atom-boot-java/lib/main.js b/atom-extensions/atom-boot-java/lib/main.js index 9bd49c351..cdee1500a 100644 --- a/atom-extensions/atom-boot-java/lib/main.js +++ b/atom-extensions/atom-boot-java/lib/main.js @@ -18,6 +18,15 @@ class BootJavaLanguageClient extends JavaProcessLanguageClient { // this.DEBUG = true; } + postInitialization(server) { + this.sendConfig(server); + this._disposable.add(atom.config.observe('boot-java', () => this.sendConfig(server))); + } + + sendConfig(server) { + server.connection.didChangeConfiguration({ settings: {'boot-java': atom.config.get('boot-java') }}); + } + getGrammarScopes() { return ['source.java'] } @@ -44,7 +53,7 @@ class BootJavaLanguageClient extends JavaProcessLanguageClient { launchVmArgs(version) { return super.getOrInstallLauncher().then(lsJar => { const toolsJar = this.findJavaFile('lib', 'tools.jar'); - if (!toolsJar) { + if (version < 9 && !toolsJar) { // Notify the user that tool.jar is not found const notification = atom.notifications.addWarning(`"Boot-Java" Package Functionality Limited`, { dismissable: true, diff --git a/atom-extensions/atom-boot-java/package.json b/atom-extensions/atom-boot-java/package.json index ff1e774af..974dabe83 100644 --- a/atom-extensions/atom-boot-java/package.json +++ b/atom-extensions/atom-boot-java/package.json @@ -14,6 +14,13 @@ "server/", "properties.json" ], + "configSchema": { + "boot-hints.on": { + "type": "boolean", + "default": true, + "description": "Enable/Disable Spring running Boot application live hints decorators in the source code" + } + }, "dependencies": { "atom-package-deps": "^4.6.0", "download": "^6.2.5", diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/META-INF/MANIFEST.MF b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/META-INF/MANIFEST.MF index fff073fd9..e3f75d1da 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/META-INF/MANIFEST.MF +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/META-INF/MANIFEST.MF @@ -16,9 +16,12 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0", org.eclipse.jface, org.eclipse.xtext.xbase.lib, org.springframework.tooling.ls.eclipse.commons, - org.eclipse.core.resources + org.eclipse.core.resources, + org.eclipse.ui Import-Package: com.google.gson;version="2.7.0", org.eclipse.jface.preference, org.eclipse.lsp4j.jsonrpc.messages;version="0.1.0.v20170117-0759", org.eclipse.lsp4j.services;version="0.1.0.v20170117-0759", org.osgi.framework +Bundle-Activator: org.springframework.tooling.boot.java.ls.BootJavaLanguageServerPlugin +Bundle-ActivationPolicy: lazy diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/plugin.xml b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/plugin.xml index ff3b0db66..c4e184d7c 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/plugin.xml +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/plugin.xml @@ -42,5 +42,20 @@ contentTypeId="org.eclipse.jdt.core.javaSource"> + + + + + + + + diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/BootJavaLanguageServerPlugin.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/BootJavaLanguageServerPlugin.java new file mode 100644 index 000000000..b068daf68 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/BootJavaLanguageServerPlugin.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.tooling.boot.java.ls; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * Boot-Java LS extension plugin + * + * @author Alex Boyko + * + */ +public class BootJavaLanguageServerPlugin extends AbstractUIPlugin { + + public static final String ID = "org.springframework.tooling.boot.java.ls"; + + // The shared instance + private static BootJavaLanguageServerPlugin plugin; + + public BootJavaLanguageServerPlugin() { + // Empty + } + + @Override + public void start(BundleContext context) throws Exception { + plugin = this; + super.start(context); + } + + @Override + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + public static BootJavaLanguageServerPlugin getDefault() { + return plugin; + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/BootJavaPreferencesPage.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/BootJavaPreferencesPage.java new file mode 100644 index 000000000..0cf63db32 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/BootJavaPreferencesPage.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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.tooling.boot.java.ls; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * Preference page for Boot-Java LS extension + * + * @author Alex Boyko + * + */ +public class BootJavaPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + public BootJavaPreferencesPage() { + } + + @Override + public void init(IWorkbench workbench) { + setDescription("Settings for Boot-Java language server extension"); + setPreferenceStore(BootJavaLanguageServerPlugin.getDefault().getPreferenceStore()); + } + + @Override + protected void createFieldEditors() { + BooleanFieldEditor editor = new BooleanFieldEditor(Constants.PREF_BOOT_HINTS, "Live Boot Hint Decorators", getFieldEditorParent()); + addField(editor); + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/Constants.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/Constants.java index 12b9cec73..8f398dfe2 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/Constants.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/Constants.java @@ -17,5 +17,7 @@ public class Constants { public static final String PLUGIN_ID = "org.springframework.tooling.boot.java.ls"; public static final String LANGUAGE_SERVER_VERSION = "0.0.10-SNAPSHOT.jar"; + + public static final String PREF_BOOT_HINTS = "boot-java.boot-hints.on"; } diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/DelegatingStreamConnectionProvider.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/DelegatingStreamConnectionProvider.java index 7cfa38cf1..2fa86aa3c 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/DelegatingStreamConnectionProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/DelegatingStreamConnectionProvider.java @@ -16,11 +16,18 @@ import java.io.OutputStream; import java.net.URI; import java.nio.file.FileSystems; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.lsp4e.server.StreamConnectionProvider; +import org.eclipse.lsp4j.DidChangeConfigurationParams; +import org.eclipse.lsp4j.InitializeResult; +import org.eclipse.lsp4j.jsonrpc.messages.Message; +import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage; +import org.eclipse.lsp4j.services.LanguageServer; /** * if the system property "boot-java-ls-port" exists, delegate to the socket-based @@ -37,6 +44,14 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi private StreamConnectionProvider provider; private ResourceListener fResourceListener; + private LanguageServer languageServer; + + private final IPropertyChangeListener configListener = new IPropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent event) { + sendConfiguration(); + } + }; public DelegatingStreamConnectionProvider() { String port = System.getProperty("boot-java-ls-port"); @@ -51,7 +66,6 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi @Override public Object getInitializationOptions(URI rootUri) { - installResourceChangeListener(rootUri); return provider.getInitializationOptions(rootUri); } @@ -77,30 +91,38 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi ResourcesPlugin.getWorkspace().removeResourceChangeListener(fResourceListener); fResourceListener = null; } + BootJavaLanguageServerPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(configListener); } - private void installResourceChangeListener(URI rootPath) { - if (rootPath == null || fResourceListener != null) { - return; - } - - IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(rootPath); - if (containers.length == 0) { - return; - } - - for (IContainer c : containers) { - if (!(c instanceof IProject)) { - continue; + @Override + public void handleMessage(Message message, LanguageServer languageServer, URI rootURI) { + if (message instanceof ResponseMessage) { + ResponseMessage responseMessage = (ResponseMessage)message; + if (responseMessage.getResult() instanceof InitializeResult) { + this.languageServer = languageServer; + + sendConfiguration(); + + // Add config listener + BootJavaLanguageServerPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(configListener); + + // Add resource listener + ResourcesPlugin.getWorkspace().addResourceChangeListener(fResourceListener = new ResourceListener(languageServer, Arrays.asList( + FileSystems.getDefault().getPathMatcher("glob:**/pom.xml"), + FileSystems.getDefault().getPathMatcher("glob:**/build.gradle") + ))); } - IProject project = (IProject) c; - fResourceListener = new ResourceListener("org.eclipse.languageserver.languages.springbootjava", project, Arrays.asList( - FileSystems.getDefault().getPathMatcher("glob:**/pom.xml"), - FileSystems.getDefault().getPathMatcher("glob:**/build.gradle") - )); - project.getWorkspace().addResourceChangeListener(fResourceListener); - - break; } } + + private void sendConfiguration() { + Map settings = new HashMap<>(); + Map bootJavaObj = new HashMap<>(); + Map bootHint = new HashMap<>(); + bootHint.put("on", BootJavaLanguageServerPlugin.getDefault().getPreferenceStore().getBoolean(Constants.PREF_BOOT_HINTS)); + bootJavaObj.put("boot-hints", bootHint); + settings.put("boot-java", bootJavaObj); + this.languageServer.getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings)); + } + } diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/PrefsInitializer.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/PrefsInitializer.java new file mode 100644 index 000000000..50115f785 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/PrefsInitializer.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.tooling.boot.java.ls; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; + +/** + * Preferences initializer for Boot-Java LS extension + * + * @author Alex Boyko + * + */ +public class PrefsInitializer extends AbstractPreferenceInitializer { + + public PrefsInitializer() { + } + + @Override + public void initializeDefaultPreferences() { + BootJavaLanguageServerPlugin.getDefault().getPreferenceStore().setDefault(Constants.PREF_BOOT_HINTS, true); + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/ResourceListener.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/ResourceListener.java index f6d621c92..e90afc5e1 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/ResourceListener.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/ResourceListener.java @@ -10,25 +10,20 @@ *******************************************************************************/ package org.springframework.tooling.boot.java.ls; -import java.io.IOException; import java.net.URI; import java.nio.file.PathMatcher; import java.util.ArrayList; import java.util.List; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.runtime.CoreException; -import org.eclipse.lsp4e.LanguageServersRegistry; -import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition; -import org.eclipse.lsp4e.LanguageServiceAccessor; -import org.eclipse.lsp4e.ProjectSpecificLanguageServerWrapper; import org.eclipse.lsp4j.DidChangeWatchedFilesParams; import org.eclipse.lsp4j.FileChangeType; import org.eclipse.lsp4j.FileEvent; +import org.eclipse.lsp4j.services.LanguageServer; /** * Resource listener for LSP4E taken from CPP-LS @@ -37,35 +32,29 @@ import org.eclipse.lsp4j.FileEvent; * @author Alex Boyko * */ -@SuppressWarnings("restriction") public class ResourceListener implements IResourceChangeListener { - private final String lsId; - private final IProject fProject; + private final LanguageServer server; private List pathMatchers; - ResourceListener(String lsId, IProject project, List pathMatchers) { - this.lsId = lsId; - fProject = project; + ResourceListener(LanguageServer server, List pathMatchers) { + this.server = server; this.pathMatchers = pathMatchers; } @Override public void resourceChanged(IResourceChangeEvent event) { - LanguageServerDefinition definition = LanguageServersRegistry.getInstance().getDefinition(lsId); - ProjectSpecificLanguageServerWrapper wrapper = getLanguageSeverWrapper(definition); - if (event.getType() != IResourceChangeEvent.POST_CHANGE || !isRelevantDelta(event.getDelta()) - || wrapper == null) { + if (event.getType() != IResourceChangeEvent.POST_CHANGE || !isRelevantDelta(event.getDelta())) { return; } - sendFileEvents(wrapper, createFileEventsFromResourceEvent(event)); + sendFileEvents(createFileEventsFromResourceEvent(event)); } - private static void sendFileEvents(ProjectSpecificLanguageServerWrapper wrapper, List fileEvents) { + private void sendFileEvents(List fileEvents) { if (!fileEvents.isEmpty()) { DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(fileEvents); - wrapper.getServer().getWorkspaceService().didChangeWatchedFiles(params); + server.getWorkspaceService().didChangeWatchedFiles(params); } } @@ -91,15 +80,6 @@ public class ResourceListener implements IResourceChangeListener { return pathMatchers.stream().filter(m -> m.matches(resource.getLocation().toFile().toPath())).findFirst().isPresent(); } - private ProjectSpecificLanguageServerWrapper getLanguageSeverWrapper(LanguageServerDefinition definition) { - try { - return LanguageServiceAccessor.getLSWrapperForConnection(fProject, definition); - } catch (IOException e) { - // Do nothing - return null; - } - } - private static boolean isRelevantDelta(IResourceDelta delta) { int kind = delta.getKind(); int flags = delta.getFlags(); diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaConfig.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaConfig.java new file mode 100644 index 000000000..158bbdf7b --- /dev/null +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaConfig.java @@ -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; + } + + +} diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java index 786365024..4d8e5f725 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServer.java @@ -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 _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; + } } diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaHoverProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaHoverProvider.java index c11a57bbc..3d19288d1 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaHoverProvider.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/handlers/BootJavaHoverProvider.java @@ -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 hoverProviders; private RunningAppProvider runningAppProvider; - public BootJavaHoverProvider(SimpleLanguageServer server, JavaProjectFinder projectFinder, Map specificProviders, RunningAppProvider runningAppProvider) { + public BootJavaHoverProvider(BootJavaLanguageServer server, JavaProjectFinder projectFinder, Map specificProviders, RunningAppProvider runningAppProvider) { this.server = server; this.projectFinder = projectFinder; this.hoverProviders = specificProviders; diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java index c3226ae41..daa0d2eab 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java @@ -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(); + } + } + } diff --git a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java index 6ee475cfc..201d2b0d0 100644 --- a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java +++ b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java @@ -50,6 +50,7 @@ import org.eclipse.lsp4j.CompletionItemCapabilities; import org.eclipse.lsp4j.CompletionList; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.DiagnosticSeverity; +import org.eclipse.lsp4j.DidChangeConfigurationParams; import org.eclipse.lsp4j.DidChangeTextDocumentParams; import org.eclipse.lsp4j.DidChangeWatchedFilesParams; import org.eclipse.lsp4j.DidOpenTextDocumentParams; @@ -88,6 +89,7 @@ import org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient; import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits; import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixEdit.CursorMovement; import org.springframework.ide.vscode.commons.languageserver.util.LanguageServerTestListener; +import org.springframework.ide.vscode.commons.languageserver.util.Settings; import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer; import org.springframework.ide.vscode.commons.util.Assert; import org.springframework.ide.vscode.commons.util.ExceptionUtil; @@ -649,6 +651,10 @@ public class LanguageServerHarness { return newEditor(languageId, content, docUri); } + public void changeConfiguration(Settings settings) { + server.getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings)); + } + public S getServer() { return server; } diff --git a/vscode-extensions/vscode-boot-java/lib/Main.ts b/vscode-extensions/vscode-boot-java/lib/Main.ts index e82a0cf11..78f0d4c5d 100644 --- a/vscode-extensions/vscode-boot-java/lib/Main.ts +++ b/vscode-extensions/vscode-boot-java/lib/Main.ts @@ -20,7 +20,7 @@ export function activate(context: VSCode.ExtensionContext) { let options: commons.ActivatorOptions = { DEBUG: false, CONNECT_TO_LS: false, - extensionId: 'vscode-boot-java', + extensionId: 'boot-java', launcher: (context: VSCode.ExtensionContext) => 'org.springframework.boot.loader.JarLauncher', classpath: (context: VSCode.ExtensionContext) => { const classpath = [ @@ -37,7 +37,7 @@ export function activate(context: VSCode.ExtensionContext) { clientOptions: { documentSelector: ['java'], synchronize: { - configurationSection: 'vscode-boot-java' + configurationSection: 'boot-java' } } }; diff --git a/vscode-extensions/vscode-boot-java/package.json b/vscode-extensions/vscode-boot-java/package.json index 919ec396d..4bb7d2cee 100644 --- a/vscode-extensions/vscode-boot-java/package.json +++ b/vscode-extensions/vscode-boot-java/package.json @@ -25,6 +25,19 @@ "activationEvents": [ "onLanguage:java" ], + "contributes": { + "configuration": { + "type": "object", + "title": "Boot-Java Configuration", + "properties": { + "boot-java.boot-hints.on": { + "type": "boolean", + "default": true, + "description": "Enable/Disable Spring running Boot application live hints decorators in the source code" + } + } + } + }, "main": "./out/lib/Main", "scripts": { "prepublish": "tsc -p .",