diff --git a/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/DTRAMLanguageServer.java b/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/DTRAMLanguageServer.java index dc95a48..111ad00 100644 --- a/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/DTRAMLanguageServer.java +++ b/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/DTRAMLanguageServer.java @@ -1,59 +1,44 @@ package org.nittalab.dtram.languageserver; -import org.eclipse.lsp4j.*; +import org.eclipse.lsp4j.InitializeParams; +import org.eclipse.lsp4j.InitializeResult; +import org.eclipse.lsp4j.ServerCapabilities; import org.eclipse.lsp4j.services.*; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.logging.Logger; public class DTRAMLanguageServer implements LanguageServer, LanguageClientAware { - private static final Logger logger = Logger.getLogger(DTRAMLanguageServer.class.getName()); - - private final DTRAMWorkspaceService workspaceService; + /** + * Text document service for DTRAM + */ private final DTRAMTextDocumentService textDocumentService; + /** + * The language client that the server connects to. + */ + private static LanguageClient client = null; + public DTRAMLanguageServer() { this.textDocumentService = new DTRAMTextDocumentService(); - this.workspaceService = new DTRAMWorkspaceService(); } @Override public void connect(LanguageClient client) { + setClient(client); } @Override public CompletableFuture initialize(InitializeParams params) { - ClientInfo clientInfo = params.getClientInfo(); - logger.info("Connected to: " + clientInfo.getName() + " " + clientInfo.getVersion()); - - ServerCapabilities capabilities = new ServerCapabilities(); - capabilities.setTextDocumentSync(TextDocumentSyncKind.Full); // ファイルの同期方法を指定(毎回ドキュメント全体を送信してもらう) - capabilities.setPositionEncoding(PositionEncodingKind.UTF16); // 文字列符号化方式を指定 - - /* Tells the client that code completion is available **/ - CompletionOptions completionOptions = new CompletionOptions(); - completionOptions.setTriggerCharacters(List.of(".", " ")); - capabilities.setCompletionProvider(completionOptions); - - /* Fetch all available token types from client and send them to tell the client that the server can analyze the token */ - List availableTokenTypes = params.getCapabilities().getTextDocument().getSemanticTokens().getTokenTypes(); - SemanticTokensWithRegistrationOptions semanticTokensOptions = new SemanticTokensWithRegistrationOptions(); - semanticTokensOptions.setFull(true); - semanticTokensOptions.setRange(false); - semanticTokensOptions.setLegend(new SemanticTokensLegend(availableTokenTypes, List.of())); - capabilities.setSemanticTokensProvider(semanticTokensOptions); - + ServerCapabilities capabilities = new DTRAMServerCapabilities(); InitializeResult result = new InitializeResult(capabilities); - - textDocumentService.updateSupportedTokenTypes(availableTokenTypes); - - return CompletableFuture.completedFuture(result); + textDocumentService.updateSupportedTokenTypes(List.of(DTRAMServerCapabilities.SEMANTIC_TOKEN_TYPES)); + return CompletableFuture.supplyAsync(() -> result); } @Override public CompletableFuture shutdown() { - return CompletableFuture.supplyAsync(Object::new); + return CompletableFuture.completedFuture(null); } @Override @@ -63,11 +48,22 @@ @Override public WorkspaceService getWorkspaceService() { - return workspaceService; + return null; } @Override public TextDocumentService getTextDocumentService() { return textDocumentService; } + + private static void setClient(LanguageClient client) { + DTRAMLanguageServer.client = client; + } + + public static void requestSemanticTokensRefresh() { + if (client == null) { + return; + } + client.refreshSemanticTokens(); + } }