matthiasblaesing commented on a change in pull request #2389:
URL: https://github.com/apache/netbeans/pull/2389#discussion_r495583928
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/text/TextDocumentServiceImpl.java
##########
@@ -591,16 +588,69 @@ public static String html2MD(String html) {
createPosition(thisFileLineMap[0], end))));
}
}
- return CompletableFuture.completedFuture(result);
+ return CompletableFuture.completedFuture(Either.forLeft(result));
}
@Override
- public CompletableFuture<List<? extends Location>>
references(ReferenceParams arg0) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CompletableFuture<List<? extends Location>>
references(ReferenceParams params) {
+ AtomicBoolean cancel = new AtomicBoolean();
+ Runnable[] cancelCallback = new Runnable[1];
+ CompletableFuture<List<? extends Location>> result = new
CompletableFuture<List<? extends Location>>() {
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ cancel.set(mayInterruptIfRunning);
+ if (cancelCallback[0] != null) {
+ cancelCallback[0].run();
+ }
+ return super.cancel(mayInterruptIfRunning);
+ }
+ };
+ WORKER.post(() -> {
+ JavaSource js = getSource(params.getTextDocument().getUri());
+ try {
+ WhereUsedQuery[] query = new WhereUsedQuery[1];
+ js.runUserActionTask(cc -> {
+ cc.toPhase(JavaSource.Phase.RESOLVED);
+ if (cancel.get()) return ;
+ Document doc =
cc.getSnapshot().getSource().getDocument(true);
+ TreePath path =
cc.getTreeUtilities().pathFor(getOffset(doc, params.getPosition()));
+ query[0] = new
WhereUsedQuery(Lookups.singleton(TreePathHandle.create(path, cc)));
+ }, true);
+ if (cancel.get()) return ;
+ cancelCallback[0] = () -> query[0].cancelRequest();
+ RefactoringSession refactoring =
RefactoringSession.create("FindUsages");
+ query[0].fastCheckParameters();
Review comment:
I'm not familiar with the refactoring API, but my reading of the Javadoc
is, that:
- preCheck
- prepare
- checkParameters
- fastCheckParameters
do not raise exceptions, but return "Problem" instances. The way they are
invoked here, the return value is ignored. Not sure whether this is
intenential, but it looks wrong.
My reading of
http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-refactoring-api/org/netbeans/modules/refactoring/api/AbstractRefactoring.html#fastCheckParameters--
is, that the call to `checkParameters` should do a superset of checks to
`fastCheckParameters`. So if `checkParameters` is invoked, I would expect the
call to `fastCheckParameters` to be superfluous.
----------------------------------------------------------------
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