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 2021/01/05 17:47:24 UTC

[GitHub] [netbeans] dbalek commented on a change in pull request #2600: First attempt add LSP-based rename refactoring to the Java LSP Server and the LSP Client.

dbalek commented on a change in pull request #2600:
URL: https://github.com/apache/netbeans/pull/2600#discussion_r552090715



##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
##########
@@ -192,12 +205,14 @@
 
     private static final RequestProcessor BACKGROUND_TASKS = new RequestProcessor(TextDocumentServiceImpl.class.getName(), 1, false, false);
     private static final RequestProcessor WORKER = new RequestProcessor(TextDocumentServiceImpl.class.getName(), 1, false, false);
+    private static final Set<TextDocumentServiceImpl> ALL_INSTANCES = Collections.newSetFromMap(new WeakHashMap<>());

Review comment:
       What is `Set<TextDocumentServiceImpl> ALL_INSTANCES` good for? It is only used from `static void refreshAllEditors()` that seems to be unused.

##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
##########
@@ -1410,20 +1556,37 @@ public static int getOffset(Document doc, Position pos) {
             file[0] = wc.getFileObject();
             lm[0] = wc.getCompilationUnit().getLineMap();
         });
+        return fileModifications(changes, file[0], lm[0]);
+    }
+    
+    private static List<TextEdit> fileModifications(ModificationResult changes, FileObject file, LineMap lm) {
         //TODO: full, correct and safe edit production:
-        List<? extends ModificationResult.Difference> diffs = changes.getDifferences(file[0]);
+        List<? extends ModificationResult.Difference> diffs = changes.getDifferences(file);
         if (diffs == null) {
             return Collections.emptyList();
         }
         List<TextEdit> edits = new ArrayList<>();
+        IntFunction<Position> offset2Position = lm != null ? pos -> Utils.createPosition(lm, pos)
+                                                           : pos -> Utils.createPosition(file, pos);
+                                            
         for (ModificationResult.Difference diff : diffs) {
             String newText = diff.getNewText();
-            edits.add(new TextEdit(new Range(Utils.createPosition(lm[0], diff.getStartPosition().getOffset()),
-                                             Utils.createPosition(lm[0], diff.getEndPosition().getOffset())),
+            edits.add(new TextEdit(new Range(offset2Position.apply(diff.getStartPosition().getOffset()),
+                                             offset2Position.apply(diff.getEndPosition().getOffset())),
                                    newText != null ? newText : ""));
         }
         return edits;
     }
+    
+    static void refreshAllEditors() {

Review comment:
       Seems to be unused.




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