refactored and reorganized eclipse ls extensions and added new ones for bosh and concourse

This commit is contained in:
Martin Lippert
2017-08-18 12:24:04 +02:00
parent 56e8b5e008
commit 19c0bfe8d7
70 changed files with 3232 additions and 52 deletions

View File

@@ -0,0 +1,7 @@
<?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

@@ -0,0 +1,28 @@
<?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

@@ -0,0 +1,7 @@
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

@@ -0,0 +1,21 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spring Boot Java Language Server
Bundle-SymbolicName: org.springframework.tooling.boot.java.ls;singleton:=true
Bundle-Version: 4.0.0.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.lsp4e;bundle-version="0.1.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.lsp4j,
org.eclipse.ui.workbench,
org.eclipse.jface,
org.eclipse.xtext.xbase.lib
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

View File

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

View File

@@ -0,0 +1,38 @@
<?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"
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>
</plugin>

View File

@@ -0,0 +1,56 @@
<?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>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>boot-java-language-server</artifactId>
<version>0.0.9-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

@@ -0,0 +1,21 @@
/*******************************************************************************
* 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.0.9";
}

View File

@@ -0,0 +1,65 @@
/*******************************************************************************
* 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.io.InputStream;
import java.io.OutputStream;
import org.eclipse.lsp4e.server.StreamConnectionProvider;
/**
* 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;
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 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 void stop() {
this.provider.stop();
}
}

View File

@@ -0,0 +1,126 @@
/*******************************************************************************
* 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.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.eclipse.jdt.internal.launching.StandardVMType;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.eclipse.lsp4j.jsonrpc.messages.NotificationMessage;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.Bundle;
import com.google.gson.JsonObject;
/**
* @author Martin Lippert
*/
@SuppressWarnings("restriction")
public class SpringBootJavaLanguageServer extends ProcessStreamConnectionProvider {
public SpringBootJavaLanguageServer() {
List<String> commands = new ArrayList<>();
commands.add(getJDKLocation());
commands.add("-Xdebug");
commands.add("-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n");
commands.add("-jar");
commands.add(getLanguageServerJARLocation());
String workingDir = getWorkingDirLocation();
setCommands(commands);
setWorkingDirectory(workingDir);
}
public void handleMessage(Message message, LanguageServer languageServer, String rootPath) {
if (message instanceof NotificationMessage) {
NotificationMessage notificationMessage = (NotificationMessage) message;
if ("sts/progress".equals(notificationMessage.getMethod())) {
JsonObject params = (JsonObject) notificationMessage.getParams();
String status = params.has("statusMsg") ? params.get("statusMsg").getAsString() : "";
showStatusMessage(status);
}
}
}
private void showStatusMessage(final String status) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
IStatusLineManager statusLineManager = getStatusLineManager();
if (statusLineManager != null) {
statusLineManager.setMessage(status);
}
}
});
}
private IStatusLineManager getStatusLineManager() {
try {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorSite().getActionBars().getStatusLineManager();
}
catch (NullPointerException e) {
return null;
}
}
protected String getJDKLocation() {
IVMInstall jdk = JavaRuntime.getDefaultVMInstall();
File javaExecutable = StandardVMType.findJavaExecutable(jdk.getInstallLocation());
return javaExecutable.getAbsolutePath();
}
protected String getLanguageServerJARLocation() {
String languageServer = "boot-java-language-server-" + Constants.LANGUAGE_SERVER_VERSION + "-SNAPSHOT.jar";
Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID);
File dataFile = bundle.getDataFile(languageServer);
// if (!dataFile.exists()) {
try {
copyLanguageServerJAR(languageServer);
}
catch (Exception e) {
e.printStackTrace();
}
// }
return dataFile.getAbsolutePath();
}
protected String getWorkingDirLocation() {
// TODO: identify a reasonable working directory for the language server process
return System.getProperty("user.dir");
}
protected void copyLanguageServerJAR(String languageServerJarName) throws Exception {
Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID);
InputStream stream = FileLocator.openStream( bundle, new Path("servers/" + languageServerJarName), false );
File dataFile = bundle.getDataFile(languageServerJarName);
Files.copy(stream, dataFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}

View File

@@ -0,0 +1,64 @@
/*******************************************************************************
* 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.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 void stop() {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,64 @@
/*******************************************************************************
* 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 java.util.Arrays;
import java.util.List;
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 LSContentAssistProcessor lsContentAssistProcessor;
public SpringBootJavaCompletionProposalComputer() {
lsContentAssistProcessor = new LSContentAssistProcessor();
}
@Override
public void sessionStarted() {
}
@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
IProgressMonitor monitor) {
System.out.println("Spring Boot Java Completion Proposal - compute completion proposals");
ICompletionProposal[] proposals = lsContentAssistProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset());
return Arrays.asList(proposals);
}
@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

@@ -0,0 +1,45 @@
/*******************************************************************************
* 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.IRegion;
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 {
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) {
}
}