refactored common language server eclipse integration code into superclass and enabled progress message support for all eclipse ls integrations
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Object> moveCursor(CursorMovement cursorMovement);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user