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