adopt unified boot language server for eclipse language server plugins and features

This commit is contained in:
Martin Lippert
2018-02-18 18:06:52 +01:00
parent dcb08077f5
commit 260a5f9241
44 changed files with 133 additions and 445 deletions

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.springframework.tooling.boot.java.ls</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -1,7 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View File

@@ -1,26 +0,0 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spring Boot Java Language Server
Bundle-Vendor: Pivotal, Inc.
Bundle-SymbolicName: org.springframework.tooling.boot.java.ls;singleton:=true
Bundle-Version: 0.1.4.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0",
org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.ui.genericeditor;bundle-version="1.0.0",
org.eclipse.jface.text;bundle-version="3.11.100",
org.eclipse.jdt.ui;bundle-version="3.13.0",
org.eclipse.lsp4e;bundle-version="0.5.0",
org.eclipse.lsp4j;bundle-version="0.4.0",
org.eclipse.lsp4j.jsonrpc;bundle-version="0.4.0",
org.eclipse.ui.workbench,
org.eclipse.jface,
org.eclipse.xtext.xbase.lib,
org.springframework.tooling.ls.eclipse.commons;bundle-version="0.2.0",
org.eclipse.core.resources,
org.eclipse.ui
Import-Package: com.google.gson;version="2.7.0",
org.eclipse.jface.preference,
org.osgi.framework
Bundle-Activator: org.springframework.tooling.boot.java.ls.BootJavaLanguageServerPlugin
Bundle-ActivationPolicy: lazy

View File

@@ -1,6 +0,0 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
servers/

View File

@@ -1,61 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.lsp4e.languageServer">
<server
class="org.springframework.tooling.boot.java.ls.DelegatingStreamConnectionProvider"
id="org.eclipse.languageserver.languages.springbootjava"
clientImpl="org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl"
label="Spring Boot Java Language Server">
</server>
<contentTypeMapping
contentType="org.eclipse.jdt.core.javaSource"
id="org.eclipse.languageserver.languages.springbootjava">
</contentTypeMapping>
</extension>
<extension
id="springbootjava-completion-computer"
point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
<javaCompletionProposalComputer
activate="true"
categoryId="org.eclipse.jdt.ui.defaultProposalCategory"
class="org.springframework.tooling.boot.java.ls.jdt.SpringBootJavaCompletionProposalComputer"
needsSortingAfterFiltering="false">
</javaCompletionProposalComputer>
</extension>
<extension
id="springbootjava-hover-provider"
point="org.eclipse.jdt.ui.javaEditorTextHovers">
<hover
activate="true"
class="org.springframework.tooling.boot.java.ls.jdt.SpringBootJavaHoverProvider"
id="org.springframework.boot.ide.java.servers.hoverprovider">
</hover>
</extension>
<extension
point="org.eclipse.core.filebuffers.documentSetup">
<participant
class="org.eclipse.lsp4e.ConnectDocumentToLanguageServerSetupParticipant"
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>

View File

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot.ide</groupId>
<artifactId>org.springframework.boot.ide.servers</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>org.springframework.tooling.boot.java.ls</artifactId>
<version>0.1.4-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>boot-java-language-server</artifactId>
<version>0.1.4-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>boot-java-language-server</artifactId>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/../servers</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,98 +0,0 @@
/*******************************************************************************
* 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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.keys.IBindingService;
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";
private static final Object LSP4E_COMMAND_SYMBOL_IN_WORKSPACE = "org.eclipse.lsp4e.symbolinworkspace";
// The shared instance
private static BootJavaLanguageServerPlugin plugin;
public BootJavaLanguageServerPlugin() {
// Empty
}
@Override
public void start(BundleContext context) throws Exception {
plugin = this;
super.start(context);
deactivateDuplicateKeybindings();
}
@Override
public void stop(BundleContext context) throws Exception {
super.stop(context);
plugin = null;
}
public static BootJavaLanguageServerPlugin getDefault() {
return plugin;
}
private void deactivateDuplicateKeybindings() {
IBindingService service = PlatformUI.getWorkbench().getService(IBindingService.class);
if (service != null) {
List<Binding> newBindings = new ArrayList<>();
Binding[] bindings = service.getBindings();
for (Binding binding : bindings) {
String commandId = null;
if (binding != null && binding.getParameterizedCommand() != null && binding.getParameterizedCommand().getCommand() != null) {
commandId = binding.getParameterizedCommand().getCommand().getId();
if (commandId == null) {
newBindings.add(binding);
}
else if (!commandId.equals(LSP4E_COMMAND_SYMBOL_IN_WORKSPACE)) {
newBindings.add(binding);
}
}
else {
newBindings.add(binding);
}
}
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
try {
service.savePreferences(service.getActiveScheme(),
newBindings.toArray(new Binding[newBindings.size()]));
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
}

View File

@@ -1,41 +0,0 @@
/*******************************************************************************
* 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);
}
}

View File

@@ -1,23 +0,0 @@
/*******************************************************************************
* 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;
/**
* @author Martin Lippert
*/
public class Constants {
public static final String PLUGIN_ID = "org.springframework.tooling.boot.java.ls";
public static final String LANGUAGE_SERVER_VERSION = "0.1.4-SNAPSHOT.jar";
public static final String PREF_BOOT_HINTS = "boot-java.boot-hints.on";
}

View File

@@ -1,133 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 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 java.io.IOException;
import java.io.InputStream;
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.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
* stream connection provider, otherwise use the standard process-based stream
* connection provider.
*
* This allows you to run the language server in server mode (listens on a port for
* a connection) and connect the IDE integration to that already running language
* server instead of starting a new process for it.
*
* @author Martin Lippert
*/
public class DelegatingStreamConnectionProvider implements StreamConnectionProvider {
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");
if (port != null) {
this.provider = new SpringBootJavaLanguageServerViaSocket(Integer.parseInt(port));
}
else {
this.provider = new SpringBootJavaLanguageServer();
}
}
@Override
public Object getInitializationOptions(URI rootUri) {
return provider.getInitializationOptions(rootUri);
}
@Override
public void start() throws IOException {
this.provider.start();
}
@Override
public InputStream getInputStream() {
return this.provider.getInputStream();
}
@Override
public OutputStream getOutputStream() {
return this.provider.getOutputStream();
}
@Override
public InputStream getErrorStream() {
return provider.getErrorStream();
}
@Override
public void stop() {
this.provider.stop();
if (fResourceListener != null) {
ResourcesPlugin.getWorkspace().removeResourceChangeListener(fResourceListener);
fResourceListener = null;
}
BootJavaLanguageServerPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(configListener);
}
@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:**/*.gradle"),
FileSystems.getDefault().getPathMatcher("glob:**/*.java")
)));
}
}
}
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));
}
}

View File

@@ -1,58 +0,0 @@
/*******************************************************************************
* Copyright (c) 2018 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 java.io.File;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingJDKException;
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingToolsJarException;
public class MissingJdkWarning {
private static boolean missingToolsJarWarningIssued = false;
public static void show(MissingJDKException e) {
//Don't warn more than once per Eclipse session.
if (!missingToolsJarWarningIssued) {
Display.getDefault().asyncExec(() -> {
missingToolsJarWarningIssued = true;
if (e instanceof MissingToolsJarException) {
show((MissingToolsJarException)e);
} else {
MessageDialog.openWarning(null, "Missing JDK",
"The JRE you are running Eclipse with appears to not be a JDK.\n\n"+
"Spring Boot Live hovers will not work with a plain JRE.\n\n" +
"The JRE you are running Eclipse with is:\n "+e.javaHome+"\n\n"
);
}
});
}
}
private static void show(MissingToolsJarException e) {
StringBuilder lookedIn = new StringBuilder();
for (File file : e.lookedIn) {
lookedIn.append(" ");
lookedIn.append(file);
lookedIn.append("\n");
}
MessageDialog.openWarning(null, "Missing 'tools.jar'",
"Could not find 'tools.jar' in the active JRE.\n\n"+
"Spring Boot Live hovers will not work without it.\n\n" +
"The JRE you are running Eclipse with is:\n "+e.javaHome+"\n\n" +
"Where we looked for 'tools.jar':\n" +
lookedIn
);
}
}

View File

@@ -1,31 +0,0 @@
/*******************************************************************************
* 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);
}
}

View File

@@ -1,115 +0,0 @@
/*******************************************************************************
* 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 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.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.lsp4e.LSPEclipseUtils;
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
* https://github.com/eclipse/cdt/blob/master/lsp4e-cpp/org.eclipse.lsp4e.cpp.language/src/org/eclipse/lsp4e/cpp/language/CPPResourceChangeListener.java
*
* @author Alex Boyko
*
*/
@SuppressWarnings("restriction")
public class ResourceListener implements IResourceChangeListener {
private final LanguageServer server;
private List<PathMatcher> pathMatchers;
ResourceListener(LanguageServer server, List<PathMatcher> pathMatchers) {
this.server = server;
this.pathMatchers = pathMatchers;
}
@Override
public void resourceChanged(IResourceChangeEvent event) {
if (event.getType() != IResourceChangeEvent.POST_CHANGE || !isRelevantDelta(event.getDelta())) {
return;
}
sendFileEvents(createFileEventsFromResourceEvent(event));
}
private void sendFileEvents(List<FileEvent> fileEvents) {
if (!fileEvents.isEmpty()) {
DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(fileEvents);
server.getWorkspaceService().didChangeWatchedFiles(params);
}
}
private List<FileEvent> createFileEventsFromResourceEvent(IResourceChangeEvent event) {
List<FileEvent> fileEvents = new ArrayList<>();
try {
event.getDelta().accept((delta) -> {
if (delta.getResource() instanceof IFile && isRelevantDelta(delta) && isApplicableFile((IFile) delta.getResource())) {
FileEvent fileEvent = createFileEventFromDelta(delta);
if (fileEvent != null) {
fileEvents.add(fileEvent);
}
}
return true;
}, false);
} catch (CoreException e) {
// Do nothing
}
return fileEvents;
}
private boolean isApplicableFile(IFile resource) {
return pathMatchers.stream().filter(m -> m.matches(resource.getLocation().toFile().toPath())).findFirst().isPresent();
}
private static boolean isRelevantDelta(IResourceDelta delta) {
int kind = delta.getKind();
int flags = delta.getFlags();
if (delta.getResource() instanceof IFile && kind == IResourceDelta.CHANGED) {
return (flags & IResourceDelta.CONTENT) != 0;
}
return kind == IResourceDelta.ADDED || kind == IResourceDelta.CHANGED || kind == IResourceDelta.REMOVED;
}
private static FileEvent createFileEventFromDelta(IResourceDelta delta) {
URI locationURI = LSPEclipseUtils.toUri(delta.getResource());
if (locationURI == null) {
return null;
}
FileChangeType changeType = null;
if (delta.getKind() == IResourceDelta.ADDED) {
changeType = FileChangeType.Created;
} else if (delta.getKind() == IResourceDelta.CHANGED) {
changeType = FileChangeType.Changed;
} else if (delta.getKind() == IResourceDelta.REMOVED) {
changeType = FileChangeType.Deleted;
} else {
throw new IllegalStateException("Unsupported resource delta kind: " + delta.getKind()); //$NON-NLS-1$
}
return new FileEvent(locationURI.toString(), changeType);
}
}

View File

@@ -1,112 +0,0 @@
/*******************************************************************************
* 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 static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.BOOT_JAVA_SERVER;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import org.springframework.tooling.ls.eclipse.commons.JRE;
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingJDKException;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector;
/**
* @author Martin Lippert
*/
public class SpringBootJavaLanguageServer extends STS4LanguageServerProcessStreamConnector {
public SpringBootJavaLanguageServer() {
super(BOOT_JAVA_SERVER);
List<String> commands = new ArrayList<>();
JRE jre = getJRE();
commands.add(jre.getJavaExecutable());
// commands.add("-Xdebug");
// commands.add("-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n");
commands.add("-Dlsp.lazy.completions.disable=true");
commands.add("-Dlsp.completions.indentation.enable=true");
commands.add("-Xmx1024m");
commands.add("-cp");
String classpath = getLanguageServerJARLocation();
if (jre.toolsJar!=null) {
classpath = jre.toolsJar + File.pathSeparator + classpath;
}
commands.add(classpath);
commands.add("org.springframework.boot.loader.JarLauncher");
String workingDir = getWorkingDirLocation();
setCommands(commands);
setWorkingDirectory(workingDir);
}
private JRE getJRE() {
try {
return JRE.findJRE(true);
} catch (MissingJDKException e) {
MissingJdkWarning.show(e);
return new JRE(e.javaHome, null); //Not everything will work without tools jar. But some of it will. So fallback on JRE without toolsjar.
}
}
protected String getLanguageServerJARLocation() {
String languageServer = "boot-java-language-server-" + Constants.LANGUAGE_SERVER_VERSION;
Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID);
String bundleVersion = bundle.getVersion().toString();
String languageServerLocalCopy = bundleVersion + "-" + languageServer;
File dataFile = bundle.getDataFile(languageServerLocalCopy);
Exception error = null;
if (!dataFile.exists() || bundleVersion.endsWith("qualifier")) { // qualifier check to get the language server always copied in dev mode
try {
copyLanguageServerJAR(languageServer, languageServerLocalCopy);
}
catch (Exception e) {
error = e;
}
}
if (!dataFile.exists()) {
File userHome = new File(System.getProperty("user.home"));
File locallyBuiltJar = new File(
userHome,
"git/sts4/headless-services/boot-java-language-server/target/boot-java-language-server-"+Constants.LANGUAGE_SERVER_VERSION
);
if (locallyBuiltJar.exists()) {
return locallyBuiltJar.getAbsolutePath();
}
if (error!=null) {
error.printStackTrace();
}
}
return dataFile.getAbsolutePath();
}
protected void copyLanguageServerJAR(String languageServerJarName, String languageServerLocalCopy) throws Exception {
Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID);
InputStream stream = FileLocator.openStream( bundle, new Path("servers/" + languageServerJarName), false );
File dataFile = bundle.getDataFile(languageServerLocalCopy);
Files.copy(stream, dataFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}

View File

@@ -1,69 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 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 java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import org.eclipse.lsp4e.server.StreamConnectionProvider;
public class SpringBootJavaLanguageServerViaSocket implements StreamConnectionProvider {
private OutputStream outputStream;
private InputStream inputStream;
private Socket socket;
private int port;
public SpringBootJavaLanguageServerViaSocket(int port) {
this.port = port;
}
@Override
public void start() throws IOException {
try {
socket = new Socket("localhost", port);
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
}
catch (IOException e) {
e.printStackTrace();
}
}
@Override
public InputStream getInputStream() {
return inputStream;
}
@Override
public OutputStream getOutputStream() {
return outputStream;
}
@Override
public InputStream getErrorStream() {
return null;
}
@Override
public void stop() {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -1,78 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 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.jdt;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor;
/**
* @author Martin Lippert
*/
@SuppressWarnings("restriction")
public class SpringBootJavaCompletionProposalComputer implements IJavaCompletionProposalComputer {
private static TimeUnit TIMEOUT_UNIT = TimeUnit.MILLISECONDS;
private static long TIMEOUT_LENGTH = 2000;
private LSContentAssistProcessor lsContentAssistProcessor;
public SpringBootJavaCompletionProposalComputer() {
lsContentAssistProcessor = new LSContentAssistProcessor();
}
@Override
public void sessionStarted() {
}
@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
IProgressMonitor monitor) {
CompletableFuture<ICompletionProposal[]> future = CompletableFuture.supplyAsync(() -> {
return lsContentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset());
});
try {
return Arrays.asList(future.get(TIMEOUT_LENGTH, TIMEOUT_UNIT));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
@Override
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context,
IProgressMonitor monitor) {
IContextInformation[] contextInformation = lsContentAssistProcessor.computeContextInformation(context.getViewer(), context.getInvocationOffset());
return Arrays.asList(contextInformation);
}
@Override
public String getErrorMessage() {
return lsContentAssistProcessor.getErrorMessage();
}
@Override
public void sessionEnded() {
}
}

View File

@@ -1,52 +0,0 @@
/*******************************************************************************
* 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.jdt;
import org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.lsp4e.operations.hover.LSBasedHover;
import org.eclipse.ui.IEditorPart;
/**
* @author Martin Lippert
*/
@SuppressWarnings("restriction")
public class SpringBootJavaHoverProvider implements IJavaEditorTextHover, ITextHoverExtension {
private LSBasedHover lsBasedHover;
public SpringBootJavaHoverProvider() {
lsBasedHover = new LSBasedHover();
}
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
return this.lsBasedHover.getHoverInfo(textViewer, hoverRegion);
}
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
return this.lsBasedHover.getHoverRegion(textViewer, offset);
}
@Override
public void setEditor(IEditorPart editor) {
}
@Override
public IInformationControlCreator getHoverControlCreator() {
return this.lsBasedHover.getHoverControlCreator();
}
}