diff --git a/lib/extension.ts b/lib/extension.ts index 2399f95d..c73c44d2 100644 --- a/lib/extension.ts +++ b/lib/extension.ts @@ -26,14 +26,6 @@ export async function activate(context: ExtensionContext) { // Synchronize the setting section 'java' to the server // NOTE: this currently doesn't do anything configurationSection: 'java', - // Notify the server about file changes to 'javaconfig.json' files contain in the workspace - fileEvents: [ - workspace.createFileSystemWatcher('**/javaconfig.json'), - workspace.createFileSystemWatcher('**/pom.xml'), - workspace.createFileSystemWatcher('**/WORKSPACE'), - workspace.createFileSystemWatcher('**/BUILD'), - workspace.createFileSystemWatcher('**/*.java') - ] }, outputChannelName: 'Java', revealOutputChannelOn: 4 // never diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java index aa96ebd0..a27bac47 100644 --- a/src/main/java/org/javacs/JavaLanguageServer.java +++ b/src/main/java/org/javacs/JavaLanguageServer.java @@ -142,6 +142,7 @@ private Set docPath() { } return paths; } + private Set addExports() { if (!settings.has("addExports")) return Set.of(); var array = settings.getAsJsonArray("addExports"); @@ -189,7 +190,7 @@ public InitializeResult initialize(InitializeParams params) { } private static final String[] watchFiles = { - "**/*.java", "**/pom.xml", "**/BUILD", + "**/*.java", "**/pom.xml", "**/BUILD", "**/javaconfig.json", "**/WORKSPACE" }; @Override diff --git a/src/main/java/org/javacs/lsp/LSP.java b/src/main/java/org/javacs/lsp/LSP.java index 27cf6c55..2654b622 100644 --- a/src/main/java/org/javacs/lsp/LSP.java +++ b/src/main/java/org/javacs/lsp/LSP.java @@ -6,6 +6,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Optional; +import java.util.Random; import java.util.UUID; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.TimeUnit; @@ -150,11 +151,20 @@ public void showMessage(ShowMessageParams params) { @Override public void registerCapability(String method, JsonElement options) { var params = new RegistrationParams(); - params.id = UUID.randomUUID().toString(); - params.method = method; - params.registerOptions = options; - - notifyClient(send, "client/registerCapability", params); + var registration = new RegistrationParams.Registration(); + registration.id = UUID.randomUUID().toString(); + registration.method = method; + registration.registerOptions = options; + params.registrations.add(registration); + var jsonText = toJson(params); + var requestMethod = "client/registerCapability"; + // The request should contain the id param. Otherwise, it will be considered a notification. + var id = new Random().nextInt(); + var messageText = + String.format( + "{\"jsonrpc\":\"2.0\",\"id\":\"%d\",\"method\":\"%s\",\"params\":%s}", + id, requestMethod, jsonText); + writeClient(send, messageText); } @Override @@ -172,7 +182,7 @@ public static void connect( // Read messages and process cancellations on a separate thread class MessageReader implements Runnable { void peek(Message message) { - if (message.method.equals("$/cancelRequest")) { + if ("$/cancelRequest".equals(message.method)) { var params = gson.fromJson(message.params, CancelParams.class); var removed = pending.removeIf(r -> r.id != null && r.id.equals(params.id)); if (removed) LOG.info(String.format("Cancelled request %d, which had not yet started", params.id)); diff --git a/src/main/java/org/javacs/lsp/RegistrationParams.java b/src/main/java/org/javacs/lsp/RegistrationParams.java index 9030aa04..e6a12a54 100644 --- a/src/main/java/org/javacs/lsp/RegistrationParams.java +++ b/src/main/java/org/javacs/lsp/RegistrationParams.java @@ -1,8 +1,14 @@ package org.javacs.lsp; import com.google.gson.JsonElement; +import java.util.ArrayList; +import java.util.List; public class RegistrationParams { - public String id, method; - public JsonElement registerOptions; + List registrations = new ArrayList<>(); + + public static class Registration { + public String id, method; + public JsonElement registerOptions; + } }