drccrd commented on code in PR #4005:
URL: 
https://github.com/apache/incubator-kie-tools/pull/4005#discussion_r4062337148


##########
packages/drools-lsp/drools-lsp-server/src/main/java/org/drools/lsp/server/DroolsLspServer.java:
##########
@@ -441,9 +463,90 @@ public CompletableFuture<InitializeResult> 
initialize(InitializeParams params) {
             });
         }
 
+        
textService.setFormatterOptions(formatterOptionsOf(params.getInitializationOptions()));
+
         return CompletableFuture.supplyAsync(() -> initializeResult);
     }
 
+    /**
+     * Pulls {@code drools.lsp.formatter} through {@code 
workspace/configuration} and
+     * registers for an empty configuration change, the pattern LSP 3.17 
prescribes:
+     * "If the server still needs to react to configuration changes (since the 
server
+     * caches the result of {@code workspace/configuration} requests) the 
server should
+     * register for an empty configuration change using the following 
registration
+     * pattern" (LSP 3.17, workspace/configuration).
+     */
+    @Override
+    public void initialized(InitializedParams params) {
+        pullFormatterOptions();
+        LanguageClient target = client;
+        if (!clientSupportsConfigurationRegistration || target == null) {
+            return;
+        }
+        Registration registration = new 
Registration("drools.lsp.didChangeConfiguration",
+                "workspace/didChangeConfiguration");
+        try {
+            target.registerCapability(new 
RegistrationParams(List.of(registration)))
+                    .exceptionally(e -> {
+                        logger.log(Level.WARNING, "Client refused to register 
for configuration "
+                                + "changes — formatter settings will need a 
restart", e);
+                        return null;
+                    });
+        } catch (Exception e) {
+            logger.log(Level.WARNING, "Client does not implement 
client/registerCapability", e);
+        }
+    }
+
+    CompletableFuture<Void> pullFormatterOptions() {
+        LanguageClient target = client;
+        if (!clientProvidesConfiguration || target == null) {
+            return CompletableFuture.completedFuture(null);
+        }
+        ConfigurationItem item = new ConfigurationItem();
+        item.setSection("drools.lsp.formatter");
+        int generation = formatterPullGeneration.incrementAndGet();
+        try {
+            return target.configuration(new ConfigurationParams(List.of(item)))
+                    .thenAccept(answer -> {
+                        if (generation == formatterPullGeneration.get()) {
+                            applyPulledFormatterOptions(answer);

Review Comment:
   probably not high priority in real use. Fixed in 
[8de1f34](https://github.com/apache/incubator-kie-tools/pull/4005/commits/8de1f34b2580710dac074ea551c47dfdebab6115)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to