PT #151674858 Live boot hint decorations on/off
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -42,5 +42,20 @@
|
||||
contentTypeId="org.eclipse.jdt.core.javaSource">
|
||||
</participant>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.preferencePages">
|
||||
<page
|
||||
category="org.springsource.ide.eclipse.commons.preferencePage"
|
||||
class="org.springframework.tooling.boot.java.ls.BootJavaPreferencesPage"
|
||||
id="org.springframework.tooling.boot.java.ls.page1"
|
||||
name="Boot Java Language Server Extension">
|
||||
</page>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.preferences">
|
||||
<initializer
|
||||
class="org.springframework.tooling.boot.java.ls.PrefsInitializer">
|
||||
</initializer>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String, Object> settings = new HashMap<>();
|
||||
Map<String, Object> bootJavaObj = new HashMap<>();
|
||||
Map<String, Object> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<PathMatcher> pathMatchers;
|
||||
|
||||
ResourceListener(String lsId, IProject project, List<PathMatcher> pathMatchers) {
|
||||
this.lsId = lsId;
|
||||
fProject = project;
|
||||
ResourceListener(LanguageServer server, List<PathMatcher> 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<FileEvent> fileEvents) {
|
||||
private void sendFileEvents(List<FileEvent> 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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<S extends SimpleLanguageServer> {
|
||||
return newEditor(languageId, content, docUri);
|
||||
}
|
||||
|
||||
public void changeConfiguration(Settings settings) {
|
||||
server.getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings));
|
||||
}
|
||||
|
||||
public S getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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 .",
|
||||
|
||||
Reference in New Issue
Block a user