You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/11/03 15:19:50 UTC

[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #2517: [NETBEANS-4981] Install nbjavac when needed

JaroslavTulach commented on a change in pull request #2517:
URL: https://github.com/apache/netbeans/pull/2517#discussion_r516736839



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -213,35 +211,49 @@ private void asyncOpenSelectedProjects(CompletableFuture f, List<FileObject> pro
             }
         }
         
-        private void showIndexingCompleted() {
+        private JavaSource showIndexingCompleted(Project[] opened) {
             try {
-                JavaSource.create(ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY))
-                          .runWhenScanFinished(cc -> {
-                  if (client.getNbCodeCapabilities().hasStatusBarMessageSupport()) {
-                        client.showStatusBarMessage(new ShowStatusMessageParams(MessageType.Info, INDEXING_COMPLETED, 0));
-                  } else {
-                        client.showMessage(new ShowStatusMessageParams(MessageType.Info, INDEXING_COMPLETED, 0));
-                  }
-                  //todo: refresh diagnostics all open editor?
-                }, true);
+                final ClasspathInfo info = ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY);
+                final JavaSource source = JavaSource.create(info);
+                if (source == null) {
+                    SERVER_INIT_RP.post(() -> {

Review comment:
       We have to use `RequestProcessor.post` as the support for status bar messages only gets initialized when this method returns.

##########
File path: java/java.lsp.server/vscode/src/extension.ts
##########
@@ -274,54 +282,82 @@ function activateWithJDK(specifiedJDK: string | null, context: ExtensionContext,
                 'nbcodeCapabilities' : {
                     'statusBarMessageSupport' : true
                 }
+            },
+            errorHandler: {
+                error : function(_error: Error, _message: Message, count: number): ErrorAction {
+                    return ErrorAction.Continue;
+                },
+                closed : function(): CloseAction {
+                    activateWithJDK(specifiedJDK, context, log, false);
+                    return CloseAction.DoNotRestart;
+                }
             }
         }
 
-        if (!client) {
-            // Create the language client and start the client.
-            client = new LanguageClient(
-                    'java',
-                    'NetBeans Java',
-                    connection,
-                    clientOptions
-            );
-
-            // Start the client. This will also launch the server
-            client.start();
-            client.onReady().then(() => {
-                commands.executeCommand('setContext', 'nbJavaLSReady', true);
-                client.onNotification(StatusMessageRequest.type, showStatusBarMessage);
-            });
+        if (client) {
+            client.stop();
         }
+        client = new LanguageClient(
+                'java',
+                'NetBeans Java',
+                connection,
+                clientOptions
+        );
+        client.start();
+        client.onReady().then(() => {
+            commands.executeCommand('setContext', 'nbJavaLSReady', true);
+            client.onNotification(StatusMessageRequest.type, showStatusBarMessage);

Review comment:
       This is the place that hooks up to the status messages. It needs to initialize first and only then it can handle the request for installation of `nbjavac`.

##########
File path: java/java.lsp.server/vscode/src/extension.ts
##########
@@ -274,54 +282,82 @@ function activateWithJDK(specifiedJDK: string | null, context: ExtensionContext,
                 'nbcodeCapabilities' : {
                     'statusBarMessageSupport' : true
                 }
+            },
+            errorHandler: {
+                error : function(_error: Error, _message: Message, count: number): ErrorAction {
+                    return ErrorAction.Continue;
+                },
+                closed : function(): CloseAction {
+                    activateWithJDK(specifiedJDK, context, log, false);

Review comment:
       This should contribute a lot to the robustness of the NetBeans backend integration. Previously it was not guaranteed the launch process really goes thru the `activateWithJDK` booting sequence. By default (if there is no `errorHandler`) the NetBeans client is restarted automatically by trying to connect to dead NetBeans instance.
   
   With this change a restart should replay the whole booting sequence in `activateWithJDK`.

##########
File path: java/java.lsp.server/vscode/src/extension.ts
##########
@@ -243,6 +250,7 @@ function activateWithJDK(specifiedJDK: string | null, context: ExtensionContext,
                         srv.disconnect();
                         return;
                     }
+                    debugPort = -1;

Review comment:
       I was hunting this one for quite a long time. We have to set the `debugPort` to `-1`, so the subsequent parsing of the output changes it.

##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -213,35 +211,49 @@ private void asyncOpenSelectedProjects(CompletableFuture f, List<FileObject> pro
             }
         }
         
-        private void showIndexingCompleted() {
+        private JavaSource showIndexingCompleted(Project[] opened) {
             try {
-                JavaSource.create(ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY))
-                          .runWhenScanFinished(cc -> {
-                  if (client.getNbCodeCapabilities().hasStatusBarMessageSupport()) {
-                        client.showStatusBarMessage(new ShowStatusMessageParams(MessageType.Info, INDEXING_COMPLETED, 0));
-                  } else {
-                        client.showMessage(new ShowStatusMessageParams(MessageType.Info, INDEXING_COMPLETED, 0));
-                  }
-                  //todo: refresh diagnostics all open editor?
-                }, true);
+                final ClasspathInfo info = ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY);
+                final JavaSource source = JavaSource.create(info);
+                if (source == null) {
+                    SERVER_INIT_RP.post(() -> {
+                        final String msg = NO_JAVA_SUPPORT + System.getProperty("java.version");
+                        showStatusBarMessage(MessageType.Error, msg, 5000);
+                    });
+                } else {
+                    source.runWhenScanFinished(cc -> {
+                        showStatusBarMessage(MessageType.Info, INDEXING_COMPLETED, 0);
+                    }, true);
+                }
+                return source;
             } catch (IOException ex) {
                 throw new IllegalStateException(ex);
             }
         }
+
+        private void showStatusBarMessage(final MessageType type, final String msg, int timeout) {
+            if (client.getNbCodeCapabilities().hasStatusBarMessageSupport()) {
+                client.showStatusBarMessage(new ShowStatusMessageParams(type, msg, timeout));
+            } else {
+                client.showMessage(new ShowStatusMessageParams(type, msg, timeout));
+            }
+        }
         
-        private InitializeResult constructInitResponse() {
+        private InitializeResult constructInitResponse(JavaSource src) {
             ServerCapabilities capabilities = new ServerCapabilities();
-            capabilities.setTextDocumentSync(TextDocumentSyncKind.Incremental);
-            CompletionOptions completionOptions = new CompletionOptions();
-            completionOptions.setResolveProvider(true);
-            completionOptions.setTriggerCharacters(Collections.singletonList("."));
-            capabilities.setCompletionProvider(completionOptions);
-            capabilities.setCodeActionProvider(true);
-            capabilities.setDocumentSymbolProvider(true);
-            capabilities.setDefinitionProvider(true);
-            capabilities.setDocumentHighlightProvider(true);
-            capabilities.setReferencesProvider(true);
-            capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(Arrays.asList(JAVA_BUILD_WORKSPACE, GRAALVM_PAUSE_SCRIPT)));
+            if (src != null) {

Review comment:
       If there is no `JavaSource` (e.g. no Java infrastructure installed), then our server is started, but it has no code editing capabilities - e.g. no additional queries needed `JavaSource` shall arrive.

##########
File path: platform/autoupdate.cli/src/org/netbeans/modules/autoupdate/cli/ModuleOptions.java
##########
@@ -482,14 +482,22 @@ public CLIInternalHandle(String displayName, Env env) {
         public CLIProgressUIWorker(Env env) {
             this.env = env;
         }
+
         @Override
         public void processProgressEvent(ProgressEvent event) {
-            env.getOutputStream().println(event.getMessage());
+            printEvent(event);
         }
+
         @Override
         public void processSelectedProgressEvent(ProgressEvent event) {
-            env.getOutputStream().println(event.getMessage());
+            printEvent(event);
+        }
+
+        private void printEvent(ProgressEvent event) {
+            final String msg = event.getMessage();
+            if (msg != null && msg.length() > 0) {

Review comment:
       Without this check the output was full of `null`s:
   ![obrazek](https://user-images.githubusercontent.com/26887752/98004171-e4538480-1def-11eb-9e01-58c93111d42a.png)
   




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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