eppleton commented on code in PR #9851:
URL: https://github.com/apache/netbeans/pull/9851#discussion_r4803079406


##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientCapabilities.java:
##########
@@ -180,30 +182,38 @@ public void setAltConfigurationPrefix(String 
altConfigurationPrefix) {
     }
 
     private NbCodeClientCapabilities withCapabilities(ClientCapabilities caps) 
{
-        if (caps == null) {
-            caps = new ClientCapabilities();
+        if (caps != null) {
+            this.clientCaps = caps;
+        } else {
+            this.clientCaps = new ClientCapabilities();
         }
-        this.clientCaps = caps;
         return this;
     }
 
-    public static NbCodeClientCapabilities get(InitializeParams initParams) {
-        if (initParams == null) {
-            return null;
-        }
-        Object ext = initParams.getInitializationOptions();
-        if (!(ext instanceof JsonElement)) {
-            return null;
-        }
-        InitializationExtendedCapabilities root = new GsonBuilder().
-                /*
-                    hypothetically needed for formatting options with Either 
type
-                registerTypeAdapterFactory(new EitherTypeAdapter.Factory()).
-                */
+    /**
+     * The NetBeans-specific client capabilities of an initialize request. A
+     * client that sends no {@code initializationOptions}, or options without a
+     * {@code nbcodeCapabilities} element (any plain LSP client), gets the
+     * defaults.
+     *
+     * @param initParams the initialize request's parameters or {@code null}
+     * @return the capabilities, never {@code null}
+     */
+    @NonNull
+    public static NbCodeClientCapabilities get(@NullAllowed InitializeParams 
initParams) {
+        Object ext = initParams != null ? 
initParams.getInitializationOptions() : null;
+        InitializationExtendedCapabilities root = ext instanceof JsonElement 
jsonElement
+            ? new GsonBuilder().
                 create().
-                fromJson((JsonElement)ext, 
InitializationExtendedCapabilities.class);
-        return root == null ? null : 
root.getNbcodeCapabilities().withCapabilities(initParams.getCapabilities());
-
+                fromJson(jsonElement, InitializationExtendedCapabilities.class)
+            : null;
+        NbCodeClientCapabilities caps = root == null ? null : 
root.getNbcodeCapabilities();
+        if (caps == null) {
+            caps = new NbCodeClientCapabilities();

Review Comment:
   Yes, that's exactly what I meant. 4e567ba61a only covers `initParams == 
null`, which shouldn't happen because `params` is required for `initialize`. 
Without `initializationOptions`, the old code switched Groovy indexing off and 
the new code switches it on. The same is true for options without 
`nbcodeCapabilities`; before this PR that case crashed with the NPE.
   
   A small thing in the same commit: the Javadoc says `{@coe initParams}` 
instead of `{@code initParams}` (line 202).
   



-- 
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]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to