From ff4181de0a5e9ad167570aa6b1f6c60e4ecefe23 Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 6 Nov 2024 16:47:48 +0100 Subject: [PATCH] feat: add example Autocomplete --- Clients/VisualStudioCode/src/extension.ts | 5 +++-- .../main/java/com/dhbw/JavaTXLanguageServer.java | 8 +------- .../java/com/dhbw/JavaTXTextDocumentService.java | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Clients/VisualStudioCode/src/extension.ts b/Clients/VisualStudioCode/src/extension.ts index ceb865e..a7d32f4 100644 --- a/Clients/VisualStudioCode/src/extension.ts +++ b/Clients/VisualStudioCode/src/extension.ts @@ -14,14 +14,15 @@ import { // Your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { + const serverOptions: ServerOptions = { run: { command: 'java', - args: ['-jar', "C:/Users/ruben/IdeaProjects/LanguageServerTestServer/target/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe + args: ['-jar', "C:\\Users\\ruben\\JavaTXLanguageServer\\JavaTXLanguageServer\\LanguageServer\\target\\JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe }, debug: { command: 'java', - args: ['-jar', "C:/Users/ruben/IdeaProjects/LanguageServerTestServer/target/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe für Debug + args: ['-jar', "C:d \Users\\ruben\\JavaTXLanguageServer\\JavaTXLanguageServer\\LanguageServer\\target\\JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe für Debug } }; diff --git a/LanguageServer/src/main/java/com/dhbw/JavaTXLanguageServer.java b/LanguageServer/src/main/java/com/dhbw/JavaTXLanguageServer.java index 05717ef..0e90579 100644 --- a/LanguageServer/src/main/java/com/dhbw/JavaTXLanguageServer.java +++ b/LanguageServer/src/main/java/com/dhbw/JavaTXLanguageServer.java @@ -26,15 +26,9 @@ public class JavaTXLanguageServer implements LanguageServer { ServerCapabilities capabilities = new ServerCapabilities(); capabilities.setTextDocumentSync(TextDocumentSyncKind.Full); - - capabilities.setHoverProvider(true); - - capabilities.setTextDocumentSync(TextDocumentSyncKind.Full); - - - capabilities.setCompletionProvider(new CompletionOptions(true, List.of("."))); + capabilities.setCompletionProvider(new CompletionOptions(true, List.of())); capabilities.setWorkspaceSymbolProvider(true); diff --git a/LanguageServer/src/main/java/com/dhbw/JavaTXTextDocumentService.java b/LanguageServer/src/main/java/com/dhbw/JavaTXTextDocumentService.java index ec895cb..7625b49 100644 --- a/LanguageServer/src/main/java/com/dhbw/JavaTXTextDocumentService.java +++ b/LanguageServer/src/main/java/com/dhbw/JavaTXTextDocumentService.java @@ -9,9 +9,10 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.services.LanguageClient; import org.eclipse.lsp4j.services.TextDocumentService; -import java.util.Collections; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.*; import java.util.concurrent.CompletableFuture; -import java.util.List; import java.util.concurrent.atomic.AtomicReference; import org.antlr.v4.runtime.CharStreams; @@ -29,7 +30,16 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex @Override public CompletableFuture, CompletionList>> completion(CompletionParams params) { - return CompletableFuture.completedFuture(Either.forLeft(Collections.emptyList())); + List completions = new ArrayList<>(); + + CompletionItem item = new CompletionItem("HelloWorld"); + item.setKind(CompletionItemKind.Text); + item.setInsertText("Hello, JavaTX World!"); + completions.add(item); + + client.showMessage(new MessageParams(MessageType.Info, "Returning completion suggestions: " + completions)); + + return CompletableFuture.completedFuture(Either.forLeft(completions)); } @Override