refactored common language server eclipse integration code into superclass and enabled progress message support for all eclipse ls integrations

This commit is contained in:
Martin Lippert
2017-11-22 20:57:56 +01:00
parent a50c09097a
commit 0e05a1a280
17 changed files with 205 additions and 250 deletions

View File

@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0",
org.eclipse.tm4e.ui;bundle-version="0.1.0",
org.eclipse.lsp4j,
org.eclipse.ui.workbench,
org.eclipse.jface
org.eclipse.jface,
org.springframework.tooling.ls.eclipse.commons;bundle-version="4.0.0"
Import-Package: com.google.gson;version="2.7.0",
org.eclipse.jface.preference,
org.eclipse.lsp4j.jsonrpc.messages;version="0.1.0.v20170117-0759",

View File

@@ -85,6 +85,7 @@
<server
class="org.springframework.tooling.concourse.ls.ConcourseLanguageServer"
id="org.eclipse.languageserver.languages.concourse"
clientImpl="org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl"
label="Concourse Language Server">
</server>
<contentTypeMapping

View File

@@ -20,24 +20,13 @@ 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;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector;
/**
* @author Martin Lippert
*/
@SuppressWarnings("restriction")
public class ConcourseLanguageServer extends ProcessStreamConnectionProvider {
public class ConcourseLanguageServer extends STS4LanguageServerProcessStreamConnector {
public ConcourseLanguageServer() {
List<String> commands = new ArrayList<>();
@@ -58,44 +47,6 @@ public class ConcourseLanguageServer extends ProcessStreamConnectionProvider {
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 = "concourse-language-server-" + Constants.LANGUAGE_SERVER_VERSION + "-SNAPSHOT.jar";
@@ -113,11 +64,6 @@ public class ConcourseLanguageServer extends ProcessStreamConnectionProvider {
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 );