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/10/26 14:54:24 UTC

[GitHub] [netbeans] sdedic opened a new pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

sdedic opened a new pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493


   I've implemented a `AbstractDialogDisplayer` that, if registered will remote `notify()` and `notifyLater` through `UIContext` into the remote LSP client. I've tested locally on Gradle projects; but it has still some limitations, like Project Problems tend to display a customizer ... so I've commented out the final registration of the service.
   
   I'd like to pull in the infrastructure for collaboration.
   


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


[GitHub] [netbeans] lkishalmi commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
lkishalmi commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512093485



##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/LspDialogDisplayer.java
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import org.netbeans.modules.java.lsp.server.ui.AbstractDialogDisplayer;
+import org.openide.DialogDisplayer;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author sdedic
+ */
+//@ServiceProvider(service = DialogDisplayer.class, position = 1000)

Review comment:
       I'm bit confused. The PR is against delivery, but no 12.2 milestone set, I'm not among the reviewers. Am I assuming right upon this comment, that you would like to float this here in case of need? So it is tentative for 12.2? If yes, please decide it till beta3 (29th Oct, late PDT) this week. If that one is messed this one have to go to master. I've put the milestone 12.2 anyway.




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


[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512102542



##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/LspDialogDisplayer.java
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import org.netbeans.modules.java.lsp.server.ui.AbstractDialogDisplayer;
+import org.openide.DialogDisplayer;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author sdedic
+ */
+//@ServiceProvider(service = DialogDisplayer.class, position = 1000)

Review comment:
       Is `beta3` supposed to become VC1? Oct 29, so close! 
   
   I asked Sváťa to propose his infrastructure changes in this PR for 12.2 as they are harmless (until we enable `@ServiceProvider`), but we may desperately need them. I am afraid we may need to download `nbjavac` if support for JDK8 is needed. Downloading shall of course only happen after asking a question - preferably through this Sváťa's infrastructure.
   
   That's my rationale. but Oct 29, is so close!




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


[GitHub] [netbeans] sdedic commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512026565



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -216,7 +242,42 @@ Lookup getSessionLookup() {
             capabilities.setDocumentHighlightProvider(true);
             capabilities.setReferencesProvider(true);
             capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(Arrays.asList(JAVA_BUILD_WORKSPACE, GRAALVM_PAUSE_SCRIPT)));
-            return CompletableFuture.completedFuture(new InitializeResult(capabilities));
+            return new InitializeResult(capabilities);
+        }
+        
+        @Override
+        public CompletableFuture<InitializeResult> initialize(InitializeParams init) {

Review comment:
       Note this change: some events are fired synchronously from Open Project. If the code asks for something like DialogDisplayer.notify (which some code really does), the initialization request processing would block - and the notify() round-trip would be never completed, freezing LSP client-server communication completely.




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


[GitHub] [netbeans] sdedic commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512102005



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -86,39 +109,56 @@ public static void launchServer(InputStream in, OutputStream out) {
         }
     }
     
-    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out) {
+    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out,
+            Function<MessageConsumer, MessageConsumer> processor) {
         return new LSPLauncher.Builder<NbCodeLanguageClient>()
             .setLocalService(server)
             .setRemoteInterface(NbCodeLanguageClient.class)
             .setInput(in)
             .setOutput(out)
-            .wrapMessages(new ConsumeWithLookup(server.getSessionLookup())::attachLookup)
+            .wrapMessages(processor)
             .create();
     }
     
+    static final ThreadLocal<NbCodeLanguageClient>   DISPATCHERS = new ThreadLocal<>();
+    
     /**
      * Processes message while the default Lookup is set to 
      * {@link LanguageServerImpl#getSessionLookup()}.
      */
     private static class ConsumeWithLookup {
         private final Lookup sessionLookup;
-
+        private NbCodeLanguageClient client;
+        
         public ConsumeWithLookup(Lookup sessionLookup) {
             this.sessionLookup = sessionLookup;
         }
         
+        synchronized void attachClient(NbCodeLanguageClient client) {
+            this.client = client;
+        }
+        
         public MessageConsumer attachLookup(MessageConsumer delegate) {
             return new MessageConsumer() {
                 @Override
                 public void consume(Message msg) throws MessageIssueException, JsonRpcException {
-                    Lookups.executeWith(sessionLookup, () -> {
-                        delegate.consume(msg);
-                    });
+                    try {
+                        DISPATCHERS.set(client);
+                        Lookups.executeWith(sessionLookup, () -> {
+                            delegate.consume(msg);
+                        });
+                    } finally {
+                        DISPATCHERS.remove();
+                    }
                 }
             };
         }
     }
     
+    private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName(), 10);
+    private static final Map<NbCodeClientWrapper, Future> initializations = new WeakHashMap<>();

Review comment:
       leftover, will remove. I originally planned to cancel the pending Future if the server receives `exit()`




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


[GitHub] [netbeans] lkishalmi merged pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
lkishalmi merged pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493


   


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


[GitHub] [netbeans] lkishalmi commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
lkishalmi commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512185940



##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/LspDialogDisplayer.java
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import org.netbeans.modules.java.lsp.server.ui.AbstractDialogDisplayer;
+import org.openide.DialogDisplayer;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author sdedic
+ */
+//@ServiceProvider(service = DialogDisplayer.class, position = 1000)

Review comment:
       The VC is or I'd better call it RC is due to 7th of November. Previously we had 2 week period between beta1 and beta2, I've switched it  to one week as usually the forts week in the release mode is when the most commits are happening "oh, this is a minor, but needs to be there". Also the weekly delivery -> master merge is hopefully small enough change to deal with.




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


[GitHub] [netbeans] sdedic commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512101860



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -86,39 +109,56 @@ public static void launchServer(InputStream in, OutputStream out) {
         }
     }
     
-    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out) {
+    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out,
+            Function<MessageConsumer, MessageConsumer> processor) {
         return new LSPLauncher.Builder<NbCodeLanguageClient>()
             .setLocalService(server)
             .setRemoteInterface(NbCodeLanguageClient.class)
             .setInput(in)
             .setOutput(out)
-            .wrapMessages(new ConsumeWithLookup(server.getSessionLookup())::attachLookup)
+            .wrapMessages(processor)
             .create();
     }
     
+    static final ThreadLocal<NbCodeLanguageClient>   DISPATCHERS = new ThreadLocal<>();
+    
     /**
      * Processes message while the default Lookup is set to 
      * {@link LanguageServerImpl#getSessionLookup()}.
      */
     private static class ConsumeWithLookup {
         private final Lookup sessionLookup;
-
+        private NbCodeLanguageClient client;
+        
         public ConsumeWithLookup(Lookup sessionLookup) {
             this.sessionLookup = sessionLookup;
         }
         
+        synchronized void attachClient(NbCodeLanguageClient client) {
+            this.client = client;
+        }
+        
         public MessageConsumer attachLookup(MessageConsumer delegate) {
             return new MessageConsumer() {
                 @Override
                 public void consume(Message msg) throws MessageIssueException, JsonRpcException {
-                    Lookups.executeWith(sessionLookup, () -> {
-                        delegate.consume(msg);
-                    });
+                    try {
+                        DISPATCHERS.set(client);
+                        Lookups.executeWith(sessionLookup, () -> {
+                            delegate.consume(msg);
+                        });
+                    } finally {
+                        DISPATCHERS.remove();
+                    }
                 }
             };
         }
     }
     
+    private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName(), 10);

Review comment:
       Hmm ... OK; I thought about multiple instances that may have been initializing (multiple LSP clients), but you're right as far as there's just project open operation being waited on. Will change.

##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -86,39 +109,56 @@ public static void launchServer(InputStream in, OutputStream out) {
         }
     }
     
-    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out) {
+    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out,
+            Function<MessageConsumer, MessageConsumer> processor) {
         return new LSPLauncher.Builder<NbCodeLanguageClient>()
             .setLocalService(server)
             .setRemoteInterface(NbCodeLanguageClient.class)
             .setInput(in)
             .setOutput(out)
-            .wrapMessages(new ConsumeWithLookup(server.getSessionLookup())::attachLookup)
+            .wrapMessages(processor)
             .create();
     }
     
+    static final ThreadLocal<NbCodeLanguageClient>   DISPATCHERS = new ThreadLocal<>();
+    
     /**
      * Processes message while the default Lookup is set to 
      * {@link LanguageServerImpl#getSessionLookup()}.
      */
     private static class ConsumeWithLookup {
         private final Lookup sessionLookup;
-
+        private NbCodeLanguageClient client;
+        
         public ConsumeWithLookup(Lookup sessionLookup) {
             this.sessionLookup = sessionLookup;
         }
         
+        synchronized void attachClient(NbCodeLanguageClient client) {
+            this.client = client;
+        }
+        
         public MessageConsumer attachLookup(MessageConsumer delegate) {
             return new MessageConsumer() {
                 @Override
                 public void consume(Message msg) throws MessageIssueException, JsonRpcException {
-                    Lookups.executeWith(sessionLookup, () -> {
-                        delegate.consume(msg);
-                    });
+                    try {
+                        DISPATCHERS.set(client);
+                        Lookups.executeWith(sessionLookup, () -> {
+                            delegate.consume(msg);
+                        });
+                    } finally {
+                        DISPATCHERS.remove();
+                    }
                 }
             };
         }
     }
     
+    private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName(), 10);
+    private static final Map<NbCodeClientWrapper, Future> initializations = new WeakHashMap<>();

Review comment:
       leftover, will remove.




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


[GitHub] [netbeans] sdedic commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512102005



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -86,39 +109,56 @@ public static void launchServer(InputStream in, OutputStream out) {
         }
     }
     
-    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out) {
+    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out,
+            Function<MessageConsumer, MessageConsumer> processor) {
         return new LSPLauncher.Builder<NbCodeLanguageClient>()
             .setLocalService(server)
             .setRemoteInterface(NbCodeLanguageClient.class)
             .setInput(in)
             .setOutput(out)
-            .wrapMessages(new ConsumeWithLookup(server.getSessionLookup())::attachLookup)
+            .wrapMessages(processor)
             .create();
     }
     
+    static final ThreadLocal<NbCodeLanguageClient>   DISPATCHERS = new ThreadLocal<>();
+    
     /**
      * Processes message while the default Lookup is set to 
      * {@link LanguageServerImpl#getSessionLookup()}.
      */
     private static class ConsumeWithLookup {
         private final Lookup sessionLookup;
-
+        private NbCodeLanguageClient client;
+        
         public ConsumeWithLookup(Lookup sessionLookup) {
             this.sessionLookup = sessionLookup;
         }
         
+        synchronized void attachClient(NbCodeLanguageClient client) {
+            this.client = client;
+        }
+        
         public MessageConsumer attachLookup(MessageConsumer delegate) {
             return new MessageConsumer() {
                 @Override
                 public void consume(Message msg) throws MessageIssueException, JsonRpcException {
-                    Lookups.executeWith(sessionLookup, () -> {
-                        delegate.consume(msg);
-                    });
+                    try {
+                        DISPATCHERS.set(client);
+                        Lookups.executeWith(sessionLookup, () -> {
+                            delegate.consume(msg);
+                        });
+                    } finally {
+                        DISPATCHERS.remove();
+                    }
                 }
             };
         }
     }
     
+    private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName(), 10);
+    private static final Map<NbCodeClientWrapper, Future> initializations = new WeakHashMap<>();

Review comment:
       leftover, will remove. I originally plan to cancel the pending Future if the client receives `exit()`




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


[GitHub] [netbeans] sdedic commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512102596



##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/LspDialogDisplayer.java
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import org.netbeans.modules.java.lsp.server.ui.AbstractDialogDisplayer;
+import org.openide.DialogDisplayer;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author sdedic
+ */
+//@ServiceProvider(service = DialogDisplayer.class, position = 1000)

Review comment:
       @lkishalmi I would added you after the PR passed through Jarda ;) it's easier to review cleaned-up code.




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


[GitHub] [netbeans] sdedic commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512102005



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -86,39 +109,56 @@ public static void launchServer(InputStream in, OutputStream out) {
         }
     }
     
-    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out) {
+    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out,
+            Function<MessageConsumer, MessageConsumer> processor) {
         return new LSPLauncher.Builder<NbCodeLanguageClient>()
             .setLocalService(server)
             .setRemoteInterface(NbCodeLanguageClient.class)
             .setInput(in)
             .setOutput(out)
-            .wrapMessages(new ConsumeWithLookup(server.getSessionLookup())::attachLookup)
+            .wrapMessages(processor)
             .create();
     }
     
+    static final ThreadLocal<NbCodeLanguageClient>   DISPATCHERS = new ThreadLocal<>();
+    
     /**
      * Processes message while the default Lookup is set to 
      * {@link LanguageServerImpl#getSessionLookup()}.
      */
     private static class ConsumeWithLookup {
         private final Lookup sessionLookup;
-
+        private NbCodeLanguageClient client;
+        
         public ConsumeWithLookup(Lookup sessionLookup) {
             this.sessionLookup = sessionLookup;
         }
         
+        synchronized void attachClient(NbCodeLanguageClient client) {
+            this.client = client;
+        }
+        
         public MessageConsumer attachLookup(MessageConsumer delegate) {
             return new MessageConsumer() {
                 @Override
                 public void consume(Message msg) throws MessageIssueException, JsonRpcException {
-                    Lookups.executeWith(sessionLookup, () -> {
-                        delegate.consume(msg);
-                    });
+                    try {
+                        DISPATCHERS.set(client);
+                        Lookups.executeWith(sessionLookup, () -> {
+                            delegate.consume(msg);
+                        });
+                    } finally {
+                        DISPATCHERS.remove();
+                    }
                 }
             };
         }
     }
     
+    private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName(), 10);
+    private static final Map<NbCodeClientWrapper, Future> initializations = new WeakHashMap<>();

Review comment:
       leftover, will remove. I originally planned to cancel the pending Future if the client receives `exit()`




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


[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #2493: Infrastructure to display simple confirmations/questions in LSP client.

Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #2493:
URL: https://github.com/apache/netbeans/pull/2493#discussion_r512051491



##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/LspDialogDisplayer.java
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.nbcode.integration;
+
+import org.netbeans.modules.java.lsp.server.ui.AbstractDialogDisplayer;
+import org.openide.DialogDisplayer;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author sdedic
+ */
+//@ServiceProvider(service = DialogDisplayer.class, position = 1000)

Review comment:
       Reasonable, given we after feature freeze. This functionality will certainly be needed in the future. For 12.2 we'd rather delay using it, unless necessary.

##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -86,39 +109,56 @@ public static void launchServer(InputStream in, OutputStream out) {
         }
     }
     
-    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out) {
+    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out,
+            Function<MessageConsumer, MessageConsumer> processor) {
         return new LSPLauncher.Builder<NbCodeLanguageClient>()
             .setLocalService(server)
             .setRemoteInterface(NbCodeLanguageClient.class)
             .setInput(in)
             .setOutput(out)
-            .wrapMessages(new ConsumeWithLookup(server.getSessionLookup())::attachLookup)
+            .wrapMessages(processor)
             .create();
     }
     
+    static final ThreadLocal<NbCodeLanguageClient>   DISPATCHERS = new ThreadLocal<>();
+    
     /**
      * Processes message while the default Lookup is set to 
      * {@link LanguageServerImpl#getSessionLookup()}.
      */
     private static class ConsumeWithLookup {
         private final Lookup sessionLookup;
-
+        private NbCodeLanguageClient client;
+        
         public ConsumeWithLookup(Lookup sessionLookup) {
             this.sessionLookup = sessionLookup;
         }
         
+        synchronized void attachClient(NbCodeLanguageClient client) {
+            this.client = client;
+        }
+        
         public MessageConsumer attachLookup(MessageConsumer delegate) {
             return new MessageConsumer() {
                 @Override
                 public void consume(Message msg) throws MessageIssueException, JsonRpcException {
-                    Lookups.executeWith(sessionLookup, () -> {
-                        delegate.consume(msg);
-                    });
+                    try {
+                        DISPATCHERS.set(client);
+                        Lookups.executeWith(sessionLookup, () -> {
+                            delegate.consume(msg);
+                        });
+                    } finally {
+                        DISPATCHERS.remove();
+                    }
                 }
             };
         }
     }
     
+    private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName(), 10);
+    private static final Map<NbCodeClientWrapper, Future> initializations = new WeakHashMap<>();

Review comment:
       Is the `initializations` field read anywhere? I can't find it (and that'd be good, as I don't think it is needed).

##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/NotifyDescriptorAdapter.java
##########
@@ -0,0 +1,322 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.ui;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleIcon;
+import javax.accessibility.AccessibleText;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import org.eclipse.lsp4j.MessageActionItem;
+import org.eclipse.lsp4j.MessageType;
+import org.eclipse.lsp4j.ShowMessageRequestParams;
+import org.openide.NotifyDescriptor;
+import org.openide.util.NbBundle;
+
+/**
+ * Adapts a {@link NotifyDescriptor} to a {@link ShowMessageRequestParams} call.
+ * @author sdedic
+ */
+class NotifyDescriptorAdapter {
+    private static final Logger LOG = Logger.getLogger(NotifyDescriptorAdapter.class.getName());
+    
+    private final UIContext client;
+    private final NotifyDescriptor  descriptor;
+    private final Map<MessageActionItem, Object> item2Option = new LinkedHashMap<>();
+    private final Map<String, Object> text2Option = new HashMap<>();
+    private final Map<Object, List<ActionListener>> optionListeners = new HashMap<>();
+    private final Map<Object, JButton> option2Button = new HashMap<>();
+    
+    private static final Set<String> warnedClasses = new HashSet<>();
+    
+    private ShowMessageRequestParams request;
+
+    private static final Object[] YES_NO_CANCEL = new Object[] {
+        NotifyDescriptor.YES_OPTION,
+        NotifyDescriptor.NO_OPTION,
+        NotifyDescriptor.CANCEL_OPTION
+    };
+    
+    private static final Object[] YES_NO = new Object[] {
+        NotifyDescriptor.YES_OPTION,
+        NotifyDescriptor.NO_OPTION,
+    };
+    
+    private static final Object[] OK_CANCEL = new Object[] {
+        NotifyDescriptor.OK_OPTION,
+        NotifyDescriptor.CANCEL_OPTION
+    };
+    
+    private static final Object[] JUST_OK = new Object[] {
+        NotifyDescriptor.OK_OPTION
+    };
+    
+    public NotifyDescriptorAdapter(NotifyDescriptor descriptor, UIContext client) {
+        this.descriptor = descriptor;
+        this.client = client;
+    }
+    
+    private MessageType translateMessageType() {
+        switch(descriptor.getMessageType()) {
+            case NotifyDescriptor.ERROR_MESSAGE:
+                return MessageType.Error;
+            case NotifyDescriptor.WARNING_MESSAGE:
+                return MessageType.Warning;
+            
+            case NotifyDescriptor.QUESTION_MESSAGE:
+            case NotifyDescriptor.PLAIN_MESSAGE:
+            case NotifyDescriptor.INFORMATION_MESSAGE:
+                return MessageType.Info;
+            default:
+                return MessageType.Log;
+        }
+    }
+    
+    /**
+     * Strip HTML from the message; VSCode standard showMessage does not support HTML.
+     * @param original
+     * @return 
+     */
+    private String translateText(String original) {

Review comment:
       I believe the translation of the text away from HTML shall only happen if it starts with `<html>`.

##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
##########
@@ -86,39 +109,56 @@ public static void launchServer(InputStream in, OutputStream out) {
         }
     }
     
-    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out) {
+    private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl server, InputStream in, OutputStream out,
+            Function<MessageConsumer, MessageConsumer> processor) {
         return new LSPLauncher.Builder<NbCodeLanguageClient>()
             .setLocalService(server)
             .setRemoteInterface(NbCodeLanguageClient.class)
             .setInput(in)
             .setOutput(out)
-            .wrapMessages(new ConsumeWithLookup(server.getSessionLookup())::attachLookup)
+            .wrapMessages(processor)
             .create();
     }
     
+    static final ThreadLocal<NbCodeLanguageClient>   DISPATCHERS = new ThreadLocal<>();
+    
     /**
      * Processes message while the default Lookup is set to 
      * {@link LanguageServerImpl#getSessionLookup()}.
      */
     private static class ConsumeWithLookup {
         private final Lookup sessionLookup;
-
+        private NbCodeLanguageClient client;
+        
         public ConsumeWithLookup(Lookup sessionLookup) {
             this.sessionLookup = sessionLookup;
         }
         
+        synchronized void attachClient(NbCodeLanguageClient client) {
+            this.client = client;
+        }
+        
         public MessageConsumer attachLookup(MessageConsumer delegate) {
             return new MessageConsumer() {
                 @Override
                 public void consume(Message msg) throws MessageIssueException, JsonRpcException {
-                    Lookups.executeWith(sessionLookup, () -> {
-                        delegate.consume(msg);
-                    });
+                    try {
+                        DISPATCHERS.set(client);
+                        Lookups.executeWith(sessionLookup, () -> {
+                            delegate.consume(msg);
+                        });
+                    } finally {
+                        DISPATCHERS.remove();
+                    }
                 }
             };
         }
     }
     
+    private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName(), 10);

Review comment:
       Throughput 10!? Isn't opening of project sequential anyway?




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