Repository navigation
Conversation
|
@ahmedneilhussain , what do you think of this? |
|
I see there is a unit test failure... looks like this was meant to work for empty lists in the case of a hover. Anyway, for the case of quick fixes this doesn't work. I can suggest |
|
@BoykoAlex, what about following the TODO on the line that you have modified
and adding a parameter Consumers could just pass Would you like to do that or shall I? |
| CompletableFuture.allOf( | ||
| executeOnServers(fn) | ||
| .map(cf -> cf.thenApply(t -> { | ||
| if (!isEmpty(t)) { // TODO: Does this need to be a supplied function to handle all cases? |
There was a problem hiding this comment.
isEmpty is now not used, so we could remove it from the class
If we can avoid extra parameters, it would be great. Everything is possible with new parameters, new methods and so on, but in the end they make the API more and more complicated. We should aim at getting a minimal API that makes the best choice. Something like AtomicBoolean metEmptyList = new AtomicBoolean();
CompletableFuture.allOf(
executeOnServers(fn)
.map(cf -> cf.thenApply(t -> {
if (t instanceof List<?> && t.isEmpty()) {
metEmptyList.set(true);
}
if (!isEmpty(t)) {
result.complete(Optional.of(t)); // return immediately non-empty result
}
return t;
})).toArray(CompletableFuture[]::new)
).whenComplete((v, t) -> completeEmptyOrWithException(result, t));
return result.thenApplyAsync(result -> (result == null && metEmptyList) ? List.of() : result); |
|
@mickaelistria , is your proposal not the same as the one done by @BoykoAlex? Both cases return the empty list or am I missing something. If that is the goal, I think the proposal done by alex is preferable. In general it is a bit strange in my opinion that the class has specific code for a List, but not for a Map, a Set, and it is I think not really something that can be achieved in general, because we cannot have filter functions for a type which can be anything. So I think to not have expectations that the method cannot really fulfill, we should just check for != null as in the proposed PR or give a filter function. One could also offer a filter function and create a method that defaults to just != null, thus having a simple API for most cases but allowing custom filtering. |
Hi @rubenporras the reason for the test for empty list is because of the way computeFirst() works (or is intended to work). This method is for when we have multiple language servers but it's only sensible to use one response (e.g. an edit). However we want the first LS that produces a result not the first LS to respond, otherwise a LS that doesn't have anything 'interesting' to contribute will win out just because it responds first, and the user will see nothing when they actually could have had a useful result from a different LS. The bug looks to be with the fallback code: if none of the LS respond with anything 'interesting' then the future should still terminate. I think this should be happening correctly (there is a test case I think the problem is not in I think the bug is that this block should have a branch for optional.ifEmpty() that replaces the 'computing' placeholder with nothing. @BoykoAlex what do you think? @rubenporras the reason we have a (slightly hacky) Does that make sense, everyone? |
|
I'd also add that in this case is there any reason not to use |
|
@ahmedneilhussain , so you propose a fix like #535? |
In the current state
In @BoykoAlex 's propsal
In my proposal: Both pros above, none of the cons. |
Yes @rubenporras , exactly that. @mickaelistria something like your proposal would undoubtedly work, but would it really be useful? Is it at all likely that calling code would need to know the distinction between a null result and an empty list? Either one or more servers returned some content, in which case the calling code can process it, or they didn't, in which case the caller either has nothing to do or (as in this case) just has to update a 'pending' placeholder with 'nothing'. |
Maybe not. |
|
@mickaelistria #535 fixes it. Thanks!-) |
|
Replaced by #535 |
Quick fixes for a problem marker shown fine if there are quick fixes available. However, if there are no quick fixes available an empty list of code actions is received on the lsp4e side. However, this result is ignored (this the chunk of code is changed by this PR) and therefore Computing... is shown indefnitely under quick fixes for problem that don't have a quick fix.