diff --git a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/SpringBootJavaLanguageServer.java b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/SpringBootJavaLanguageServer.java index 3856499b7..4e2bbd1eb 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/SpringBootJavaLanguageServer.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.java.ls/src/org/springframework/tooling/boot/java/ls/SpringBootJavaLanguageServer.java @@ -11,7 +11,6 @@ package org.springframework.tooling.boot.java.ls; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; @@ -21,18 +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.lsp4e.server.ProcessStreamConnectionProvider; import org.osgi.framework.Bundle; -import org.springframework.tooling.ls.eclipse.commons.LanguageServerProcessReaper; +import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector; /** * @author Martin Lippert */ -@SuppressWarnings("restriction") -public class SpringBootJavaLanguageServer extends ProcessStreamConnectionProvider { - - private static LanguageServerProcessReaper processReaper = new LanguageServerProcessReaper(); +public class SpringBootJavaLanguageServer extends STS4LanguageServerProcessStreamConnector { public SpringBootJavaLanguageServer() { List commands = new ArrayList<>(); @@ -43,7 +37,7 @@ public class SpringBootJavaLanguageServer extends ProcessStreamConnectionProvide commands.add("-Dlsp.lazy.completions.disable=true"); commands.add("-Dlsp.completions.indentation.enable=true"); - commands.add("-Xmx100m"); + commands.add("-Xmx200m"); commands.add("-cp"); commands.add(getToolsJAR() + ":" + getLanguageServerJARLocation()); commands.add("org.springframework.boot.loader.JarLauncher"); @@ -54,29 +48,6 @@ public class SpringBootJavaLanguageServer extends ProcessStreamConnectionProvide setWorkingDirectory(workingDir); } - @Override - public void start() throws IOException { - super.start(); - processReaper.addProcess(LanguageServerProcessReaper.getProcess(this)); - } - - @Override - public void stop() { - super.stop(); - processReaper.removeProcess(LanguageServerProcessReaper.getProcess(this)); - } - - protected String getJDKLocation() { - File jre = new File(System.getProperty("java.home")); - File javaExecutable = StandardVMType.findJavaExecutable(jre); - return javaExecutable.getAbsolutePath(); - } - - protected String getToolsJAR() { - File jre = new File(System.getProperty("java.home")); - return new File(jre.getParent(), "lib" + Path.SEPARATOR + "tools.jar").getAbsolutePath(); - } - protected String getLanguageServerJARLocation() { String fromSysprop = System.getProperty("boot-java-ls-jar", null); if (fromSysprop!=null) { @@ -102,11 +73,6 @@ public class SpringBootJavaLanguageServer extends ProcessStreamConnectionProvide 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, String languageServerLocalCopy) throws Exception { Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID); InputStream stream = FileLocator.openStream( bundle, new Path("servers/" + languageServerJarName), false ); diff --git a/eclipse-language-servers/org.springframework.tooling.bosh.ls/META-INF/MANIFEST.MF b/eclipse-language-servers/org.springframework.tooling.bosh.ls/META-INF/MANIFEST.MF index 6a945e88b..7443c1a53 100644 --- a/eclipse-language-servers/org.springframework.tooling.bosh.ls/META-INF/MANIFEST.MF +++ b/eclipse-language-servers/org.springframework.tooling.bosh.ls/META-INF/MANIFEST.MF @@ -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", diff --git a/eclipse-language-servers/org.springframework.tooling.bosh.ls/plugin.xml b/eclipse-language-servers/org.springframework.tooling.bosh.ls/plugin.xml index 7f8ae7c10..66c711985 100644 --- a/eclipse-language-servers/org.springframework.tooling.bosh.ls/plugin.xml +++ b/eclipse-language-servers/org.springframework.tooling.bosh.ls/plugin.xml @@ -85,6 +85,7 @@ commands = new ArrayList<>(); @@ -58,44 +47,6 @@ public class BoshLanguageServer 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 = "bosh-language-server-" + Constants.LANGUAGE_SERVER_VERSION + "-SNAPSHOT.jar"; @@ -113,11 +64,6 @@ public class BoshLanguageServer 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 ); diff --git a/eclipse-language-servers/org.springframework.tooling.cloudfoundry.manifest.ls/plugin.xml b/eclipse-language-servers/org.springframework.tooling.cloudfoundry.manifest.ls/plugin.xml index f13feb6b2..538d4e5be 100644 --- a/eclipse-language-servers/org.springframework.tooling.cloudfoundry.manifest.ls/plugin.xml +++ b/eclipse-language-servers/org.springframework.tooling.cloudfoundry.manifest.ls/plugin.xml @@ -7,6 +7,7 @@ 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 ); diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/META-INF/MANIFEST.MF b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/META-INF/MANIFEST.MF index 498fe1ac0..9cfeb7391 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/META-INF/MANIFEST.MF +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/META-INF/MANIFEST.MF @@ -4,7 +4,8 @@ Bundle-Name: Eclipse Language Server Commons Bundle-SymbolicName: org.springframework.tooling.ls.eclipse.commons;singleton:=true Bundle-Version: 4.0.0.qualifier Bundle-Vendor: Pivotal, Inc. -Require-Bundle: org.eclipse.ui, +Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0", + org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.lsp4e;bundle-version="0.3.0", org.eclipse.lsp4j.jsonrpc, diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/ProgressParams.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/ProgressParams.java new file mode 100644 index 000000000..11322fcc4 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/ProgressParams.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2016-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.ls.eclipse.commons; + +public class ProgressParams { + + /** + * An id representing the enitity for which progress messages are to be shown. + */ + private String id; + + /** + * Updates the current statusMsg associated with a given the id. If null, then the message + * is cleared. + */ + private String statusMsg; + + + public ProgressParams() { + } + + public ProgressParams(String id, String statusMsg) { + super(); + this.id = id; + this.statusMsg = statusMsg; + } + + @Override + public String toString() { + return "ProgressParams [id=" + id + ", statusMsg=" + statusMsg + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((statusMsg == null) ? 0 : statusMsg.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ProgressParams other = (ProgressParams) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (statusMsg == null) { + if (other.statusMsg != null) + return false; + } else if (!statusMsg.equals(other.statusMsg)) + return false; + return true; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getStatusMsg() { + return statusMsg; + } + + public void setStatusMsg(String statusMsg) { + this.statusMsg = statusMsg; + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClient.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClient.java index 513711148..9e72b46fc 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClient.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClient.java @@ -23,9 +23,9 @@ public interface STS4LanguageClient extends LanguageClient { @JsonNotification("sts/highlight") void highlight(HighlightParams highlights); -// TODO: @JsonNotification("sts/progress") -// void progress(ProgressParams progressEvent); -// + @JsonNotification("sts/progress") + void progress(ProgressParams progressEvent); + // TODO: @JsonRequest("sts/moveCursor") // CompletableFuture moveCursor(CursorMovement cursorMovement); diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java index 6057c6ab4..adf5a1ebe 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java @@ -20,6 +20,7 @@ import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; @@ -147,4 +148,31 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La } } + @Override + public void progress(ProgressParams progressEvent) { + String status = progressEvent.getStatusMsg() != null ? progressEvent.getStatusMsg() : ""; + 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; + } + } + } diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageServerProcessStreamConnector.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageServerProcessStreamConnector.java new file mode 100644 index 000000000..e5e89c430 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageServerProcessStreamConnector.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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.ls.eclipse.commons; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.internal.launching.StandardVMType; +import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider; + +@SuppressWarnings("restriction") +public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConnectionProvider { + + private static LanguageServerProcessReaper processReaper = new LanguageServerProcessReaper(); + + @Override + public void start() throws IOException { + super.start(); + processReaper.addProcess(LanguageServerProcessReaper.getProcess(this)); + } + + @Override + public void stop() { + super.stop(); + processReaper.removeProcess(LanguageServerProcessReaper.getProcess(this)); + } + + protected String getJDKLocation() { + try { + File javaHome= new File(System.getProperty("java.home")).getCanonicalFile(); //$NON-NLS-1$ + if (javaHome.exists()) { + File javaExecutable = StandardVMType.findJavaExecutable(javaHome); + if (javaExecutable != null && javaExecutable.exists()) { + return javaExecutable.getAbsolutePath(); + } + } + } catch (IOException e) { + return null; + } + + return null; + } + + protected String getToolsJAR() { + File jre = new File(System.getProperty("java.home")); + return new File(jre.getParent(), "lib" + Path.SEPARATOR + "tools.jar").getAbsolutePath(); + } + + protected String getWorkingDirLocation() { + return System.getProperty("user.dir"); + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.properties.ls/META-INF/MANIFEST.MF b/eclipse-language-servers/org.springframework.tooling.properties.ls/META-INF/MANIFEST.MF index 5cee1cc31..ea9911ca8 100644 --- a/eclipse-language-servers/org.springframework.tooling.properties.ls/META-INF/MANIFEST.MF +++ b/eclipse-language-servers/org.springframework.tooling.properties.ls/META-INF/MANIFEST.MF @@ -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", diff --git a/eclipse-language-servers/org.springframework.tooling.properties.ls/plugin.xml b/eclipse-language-servers/org.springframework.tooling.properties.ls/plugin.xml index 2715a02be..8d7011e19 100644 --- a/eclipse-language-servers/org.springframework.tooling.properties.ls/plugin.xml +++ b/eclipse-language-servers/org.springframework.tooling.properties.ls/plugin.xml @@ -81,6 +81,7 @@ commands = new ArrayList<>(); @@ -59,45 +47,6 @@ public class SpringBootPropertiesLanguageServer extends ProcessStreamConnectionP setWorkingDirectory(workingDir); } - @Override - public void handleMessage(Message message, LanguageServer languageServer, URI 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-properties-language-server-" + Constants.LANGUAGE_SERVER_VERSION + "-SNAPSHOT.jar"; @@ -115,11 +64,6 @@ public class SpringBootPropertiesLanguageServer extends ProcessStreamConnectionP 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 );