WIP 2
This commit is contained in:
@@ -10,11 +10,10 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver;
|
||||
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonDelegate;
|
||||
import org.eclipse.lsp4j.services.LanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.sprotty.SprottyService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.SprottyProtocol;
|
||||
|
||||
/**
|
||||
* STS4 language server
|
||||
@@ -22,7 +21,7 @@ import org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspac
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public interface Sts4LanguageServer extends LanguageServer {
|
||||
public interface Sts4LanguageServer extends LanguageServer, SprottyProtocol {
|
||||
|
||||
@Override
|
||||
SimpleTextDocumentService getTextDocumentService();
|
||||
@@ -42,8 +41,4 @@ public interface Sts4LanguageServer extends LanguageServer {
|
||||
*/
|
||||
DiagnosticService getDiagnosticService();
|
||||
|
||||
@JsonDelegate
|
||||
SprottyService getSprottyService();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
|
||||
import org.eclipse.lsp4j.ApplyWorkspaceEditResponse;
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.CodeLensOptions;
|
||||
import org.eclipse.lsp4j.CompletionOptions;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.eclipse.lsp4j.ExecuteCommandOptions;
|
||||
@@ -513,6 +512,8 @@ public final class SimpleLanguageServer implements Sts4LanguageServer, LanguageC
|
||||
|
||||
private DiagnosticSeverityProvider severityProvider = DiagnosticSeverityProvider.DEFAULT;
|
||||
|
||||
private SprottyMessageHandler sprottyMessageHandler;
|
||||
|
||||
/**
|
||||
* Convenience method. Subclasses can call this to use a {@link IReconcileEngine} ported
|
||||
* from old STS codebase to validate a given {@link TextDocument} and publish Diagnostics.
|
||||
@@ -718,4 +719,16 @@ public final class SimpleLanguageServer implements Sts4LanguageServer, LanguageC
|
||||
return hasCompletionSnippetSupport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sprottyMessage(JsonObject message) {
|
||||
if (this.sprottyMessageHandler != null) {
|
||||
async.execute(() -> this.sprottyMessageHandler.handleMessage(message));
|
||||
}
|
||||
}
|
||||
|
||||
public void onSprottyMessage(SprottyMessageHandler h) {
|
||||
Assert.isNull("Multiple handlers not supported!", this.sprottyMessageHandler);
|
||||
this.sprottyMessageHandler = h;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.springframework.ide.vscode.commons.languageserver.util;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SprottyMessageHandler {
|
||||
void handleMessage(JsonObject message);
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import org.springframework.ide.vscode.commons.protocol.java.JavaCodeCompletePara
|
||||
import org.springframework.ide.vscode.commons.protocol.java.JavaDataParams;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.JavaSearchParams;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.JavaTypeHierarchyParams;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.SprottyProtocol;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.TypeData;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
|
||||
|
||||
@@ -32,7 +33,7 @@ import org.springframework.ide.vscode.commons.protocol.java.TypeDescriptorData;
|
||||
*
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public interface STS4LanguageClient extends LanguageClient {
|
||||
public interface STS4LanguageClient extends LanguageClient, SprottyProtocol {
|
||||
|
||||
@JsonNotification("sts/highlight")
|
||||
void highlight(HighlightParams highlights);
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.protocol;
|
||||
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public interface SprottyClient {
|
||||
|
||||
@JsonNotification("sts/progress")
|
||||
void sprottyMessage(JsonObject message);
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.springframework.ide.vscode.commons.languageserver.sprotty;
|
||||
package org.springframework.ide.vscode.commons.protocol.java;
|
||||
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public interface SprottyService {
|
||||
public interface SprottyProtocol {
|
||||
|
||||
@JsonNotification("sts/sprotty")
|
||||
void sprottyMessage(JsonObject message);
|
||||
@@ -8,6 +8,11 @@
|
||||
</parent>
|
||||
<artifactId>commons-sprotty</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ide.vscode</groupId>
|
||||
<artifactId>commons-language-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
@@ -22,6 +23,9 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Controller
|
||||
public class DiagramWebsocketServer implements WebSocketConfigurer, InitializingBean {
|
||||
@@ -35,6 +39,9 @@ public class DiagramWebsocketServer implements WebSocketConfigurer, Initializing
|
||||
@Autowired
|
||||
private IDiagramServer diagramServer;
|
||||
|
||||
@Autowired
|
||||
private SimpleLanguageServer server;
|
||||
|
||||
private void initializeGson() {
|
||||
if (gson == null) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
@@ -46,6 +53,15 @@ public class DiagramWebsocketServer implements WebSocketConfigurer, Initializing
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
initializeGson();
|
||||
server.onSprottyMessage((jsonMessage) -> {
|
||||
ActionMessage actionMessage = gson.fromJson(jsonMessage, ActionMessage.class);
|
||||
diagramServer.accept(actionMessage);
|
||||
});
|
||||
server.doOnInitialized(() -> {
|
||||
diagramServer.setRemoteEndpoint(message -> {
|
||||
sendMessage((JsonObject)gson.toJsonTree(message));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,9 +89,6 @@ public class DiagramWebsocketServer implements WebSocketConfigurer, Initializing
|
||||
}
|
||||
log.info("Websocket connection OPENED in: "+this);
|
||||
log.info("Number of active sessions = {}", ws_sessions.size());
|
||||
diagramServer.setRemoteEndpoint(message -> {
|
||||
sendMessage(gson.toJson(message, ActionMessage.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,13 +129,14 @@ public class DiagramWebsocketServer implements WebSocketConfigurer, Initializing
|
||||
};
|
||||
}
|
||||
|
||||
private void sendMessage(String msg) {
|
||||
private void sendMessage(JsonObject msg) {
|
||||
server.getClient().sprottyMessage(msg);
|
||||
synchronized (ws_sessions) {
|
||||
for (WebSocketSession ws : ws_sessions) {
|
||||
try {
|
||||
if (ws.isOpen()) {
|
||||
log.info("Sent: {}", msg);
|
||||
ws.sendMessage(new TextMessage(msg));
|
||||
ws.sendMessage(new TextMessage(msg.toString()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error forwarding message to ws session", e);
|
||||
|
||||
@@ -132,6 +132,7 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -394,6 +395,10 @@ public class LanguageServerHarness {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sprottyMessage(JsonObject message) {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user