eppleton commented on code in PR #9851:
URL: https://github.com/apache/netbeans/pull/9851#discussion_r4782479652
##########
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:
This changes how Groovy is handled for plain LSP clients.
`Server.hackConfigureGroovySupport` computes `caps != null &&
caps.wantsGroovySupport()`. Before this PR, `caps` was `null` for such clients,
so Groovy indexing was switched off. Now they get the defaults, where
`wantsGroovySupport` is `TRUE`, so Groovy indexing is switched on. In a
distribution without Groovy support, the server also logs the "Unable to
configure Groovy indexing" WARNING, which it did not log before.
Is that intended? When comparing with other Java LSP servers, the extra
indexing work may matter. If it is intended, a sentence in the PR description
would help. (I found this by reading the code; I have not run it.)
##########
java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java:
##########
@@ -1445,6 +1446,78 @@ public void logMessage(MessageParams arg0) {
"\n");
}
+ /**
+ * A plain LSP client, not the NetBeans VS Code extension, sends
initialization
+ * options without the {@code nbcodeCapabilities} element. The server must
+ * initialize with the default NetBeans capabilities, report indexing
through
+ * the standard window/showMessage (no status bar message support) and
answer
+ * requests as usual.
+ */
+ public void testInitializeWithoutNbCodeCapabilities() throws Exception {
+ File src = new File(getWorkDir(), "Test.java");
+ src.getParentFile().mkdirs();
+ String code = """
+ /**
+ * Plain client Javadoc.
+ */
+ public class Test {
+ public static void main(String[] args) {
+ Test t = new Test();
+ }
+ }
+ """;
+ try (Writer w = new FileWriter(src)) {
+ w.write(code);
+ }
+ FileUtil.refreshFor(getWorkDir());
+ CountDownLatch indexingComplete = new CountDownLatch(1);
+ List<MessageParams> shownMessages = Collections.synchronizedList(new
ArrayList<>());
+ Launcher<LanguageServer> serverLauncher =
createClientLauncherWithLogging(new LspClient() {
+ @Override
+ public void showMessage(MessageParams params) {
+ shownMessages.add(params);
+ if (Server.INDEXING_COMPLETED.equals(params.getMessage())) {
+ indexingComplete.countDown();
+ }
+ }
+ }, client.getInputStream(), client.getOutputStream());
+ serverLauncher.startListening();
+ LanguageServer server = serverLauncher.getRemoteProxy();
+ InitializeParams initParams = new InitializeParams();
+ // options as another editor's client would send them: no
nbcodeCapabilities
+ initParams.setInitializationOptions(new JsonParser().parse(
Review Comment:
Nit: `new JsonParser().parse(...)` is deprecated. The new
`NbCodeClientCapabilitiesTest` already uses `JsonParser.parseString(...)`.
--
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