matthiasblaesing commented on code in PR #8655:
URL: https://github.com/apache/netbeans/pull/8655#discussion_r2270806315


##########
ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/refactoring/Refactoring.java:
##########
@@ -160,29 +148,28 @@ public Problem prepare(RefactoringElementsBag 
refactoringElements) {
                         refactoringElements.add(query, new 
LSPRefactoringElementImpl(annotatedLine, file, bounds));
                     }
                 }
-                runningRequest = null;
-                return null;
-            } catch (CancellationException ex) {
-                return new Problem(false, Bundle.TXT_Canceled());
-            } catch (InterruptedException | ExecutionException ex) {
-                Exceptions.printStackTrace(ex);
-                return new Problem(true, ex.getLocalizedMessage());
-            }
+            };
+
+            Utils.handleBindings(servers,
+                                 server -> true,
+                                 () -> params,
+                                 (server, params) -> 
server.getTextDocumentService().references(params),
+                                 handleResult);
+
+            return getProblem();
         }
 
     }
 
-    private static final class RenameRefactoringPlugin implements 
RefactoringPlugin {
+    private static final class RenameRefactoringPlugin extends RefactoringBase 
implements RefactoringPlugin {
 
         private final RenameRefactoring refactoring;
-        private final LSPBindings bindings;
+        private final List<LSPBindings> servers;
         private final RenameParams params;
-        private final AtomicBoolean cancel = new AtomicBoolean();
-        private volatile CompletableFuture<WorkspaceEdit> runningRequest;
 
-        public RenameRefactoringPlugin(RenameRefactoring refactoring, 
LSPBindings bindings, RenameParams params) {
+        public RenameRefactoringPlugin(RenameRefactoring refactoring, 
List<LSPBindings> servers, RenameParams params) {

Review Comment:
   Is it intentional, that sometimes the unwrapped list is used and sometimes 
the new record `LSPBindingsCollection` is?



##########
ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java:
##########
@@ -94,7 +97,7 @@ private void setDisplayName(LSPBindings bindings) {
         InitializeResult initResult = bindings.getInitResult();
         ServerCapabilities capa = initResult.getCapabilities();
         Either<Boolean, DocumentSymbolOptions> symbolProvider = capa != null ? 
capa.getDocumentSymbolProvider() : null;
-        String displayName = symbolProvider != null && 
symbolProvider.isRight() ? symbolProvider.getRight().getLabel() : null;
+        String displayName = symbolProvider != null && 
symbolProvider.isRight() ? symbolProvider.getRight().getLabel() : 
initResult.getServerInfo().getName();

Review Comment:
   This fails for the NetBeans bundled typescript support. The 
`initResult.getServerInfo()` yields `null` there.
   
   
   ```suggestion
           String displayName = null;
           if(symbolProvider != null && symbolProvider.isRight()) {
               displayName = symbolProvider.getRight().getLabel();
           } else if (initResult.getServerInfo() != null) {
               displayName = initResult.getServerInfo().getName();
           }
   ```



##########
ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/refactoring/Refactoring.java:
##########
@@ -201,141 +188,129 @@ public Problem fastCheckParameters() {
             return null;
         }
 
-        @Override
-        public void cancelRequest() {
-            cancel.set(true);
-            CompletableFuture localRunningRequest = runningRequest;
-            if(localRunningRequest != null) {
-                localRunningRequest.cancel(true);
-            }
-        }
-
         @Override
         public Problem prepare(RefactoringElementsBag refactoringElements) {
-            if (cancel.get()) {
-                return new Problem(false, Bundle.TXT_Canceled());
-            }
-            Problem p = null;
-            try {
-                runningRequest = 
bindings.getTextDocumentService().rename(params);
-                WorkspaceEdit edit = runningRequest.get();
-                List<Either<TextDocumentEdit, ResourceOperation>> 
documentChanges = edit.getDocumentChanges();
-                ModificationResult result = new ModificationResult();
-                Map<FileObject, List<Difference>> file2Diffs = new HashMap<>();
-                Map<String, String> newURI2Old = new HashMap<>();
-                Map<String, String> newFileURI2Content = new HashMap<>();
-
-                if (documentChanges != null) {
-                    for (Either<TextDocumentEdit, ResourceOperation> part : 
documentChanges) {
-                        if(cancel.get()) {
-                            break;
-                        }
-                        if (part.isLeft()) {
-                            String uri = 
part.getLeft().getTextDocument().getUri();
-                            uri = newURI2Old.getOrDefault(uri, uri);
-                            FileObject file = Utils.fromURI(uri);
-
-                            if (file != null) {
-                                for (TextEdit te : part.getLeft().getEdits()) {
-                                    Difference diff = 
textEdit2Difference(file, te);
-                                    file2Diffs.computeIfAbsent(file, f -> new 
ArrayList<>())
-                                              .add(diff);
-                                }
-                            } else if (newFileURI2Content.containsKey(uri)) {
-                                FileObject temp = 
FileUtil.createMemoryFileSystem().getRoot().createData("temp.txt");
-                                try (OutputStream out = 
temp.getOutputStream()) {
-                                    
out.write(newFileURI2Content.get(uri).getBytes()); //TODO: encoding - native, 
OK?
-                                }
-                                List<Difference> diffs = new ArrayList<>();
-                                for (TextEdit te : part.getLeft().getEdits()) {
-                                    diffs.add(textEdit2Difference(temp, te));
-                                }
-                                ModificationResult tempResult = new 
ModificationResult();
-                                tempResult.addDifferences(temp, diffs);
-                                newFileURI2Content.put(uri, 
tempResult.getResultingSource(temp));
-                            } else {
-                                //XXX: problem...
+//            if (cancel.get()) {
+//                return new Problem(false, Bundle.TXT_Canceled());
+//            }
+//            Problem p = null;
+//            try {
+//                runningRequest = 
bindings.getTextDocumentService().rename(params);

Review Comment:
   Remove?



##########
ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java:
##########
@@ -101,44 +96,34 @@ public void performClickAction(Document doc, int offset, 
HyperlinkType type) {
             //TODO: beep
             return ;
         }
-        LSPBindings server = LSPBindings.getBindings(file);
-        if (server == null) {
-            return ;
-        }
         String uri = Utils.toURI(file);
-        try {
-            DefinitionParams params;
-            params = new DefinitionParams(new TextDocumentIdentifier(uri),
-                                          Utils.createPosition(doc, offset));
-            //TODO: Location or Location[]
-            CompletableFuture<Either<List<? extends Location>, List<? extends 
LocationLink>>> def = server.getTextDocumentService().definition(params);
-            def.handleAsync((locations, exception) -> {
-                if (exception != null) {
-                    exception.printStackTrace();
-                }
-                if (locations == null) {
-                    return null;
-                }
-                String targetUri;
-                Range targetRange;
-                if (locations.isLeft() && locations.getLeft().size() == 1) { 
//TODO: what to do when there are multiple locations?
-                    targetUri = locations.getLeft().get(0).getUri();
-                    targetRange = locations.getLeft().get(0).getRange();
-                } else if (locations.isRight() && locations.getRight().size() 
== 1) { //TODO: what to do when there are multiple locations?
-                    targetUri = locations.getRight().get(0).getTargetUri();
-                    targetRange = locations.getRight().get(0).getTargetRange();
-                } else {
-                    return null;
-                }
-                Utils.open(targetUri, targetRange);
-                return null;
-            }).get();
-        } catch (BadLocationException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (InterruptedException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (ExecutionException ex) {
-            Exceptions.printStackTrace(ex);
+        List<Location> foundLocations = new ArrayList<>();
+        Utils.handleBindings(LSPBindings.getBindings(file),
+                             capa -> 
Utils.isEnabled(capa.getDefinitionProvider()),
+                             () -> new DefinitionParams(new 
TextDocumentIdentifier(uri),
+                                                        
Utils.createPosition(doc, offset)),
+
+                             (server, params) -> 
server.getTextDocumentService().definition(params),
+                             (server, locations) -> {
+                                 if (locations == null) {
+                                     return ;
+                                 } else if (locations.isLeft()) {
+                                     
foundLocations.addAll(locations.getLeft());
+                                 } else if (locations.isRight()) {
+                                     locations.getRight()
+                                              .stream()
+                                              .map(ll -> new 
Location(ll.getTargetUri(), ll.getTargetRange()))
+                                              .forEach(foundLocations::add);
+                                 }
+                             });
+        if (foundLocations.isEmpty()) {
+            //TODO: beep?
+        } else if (foundLocations.size() == 1) {
+            Location location = foundLocations.get(0);
+            Utils.open(location.getUri(), location.getRange());
+        } else {
+            //TODO: what to do when there are multiple locations?
+            //presumably show a popup

Review Comment:
   For now use the first result? People might get icky if nothing happens 
instead of one potential jump.



-- 
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: notifications-unsubscr...@netbeans.apache.org

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


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

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

Reply via email to