PT #151674858 Live boot hint decorations on/off
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user