Faulty/Undesired CodeCompletion behaviour #2620#3350
Conversation
| boolean insideTypeAnnotation, boolean isInsideAnnotationAttribute, InvocationSite site, char[][] tokens, long[] sourcePositions) | ||
| { | ||
| long completionPosition = sourcePositions[sourcePositions.length - 1]; | ||
| // we take the cursor location into consideration. |
There was a problem hiding this comment.
I am not qualified to make a in-depth review, but i can help with some formals. it would help here if you start the code example with "Example:" otherwise it looks like out commented code
| // in the above example, bestPosition will match against the cursor after 'ch', i.e. sourcePositions[1]. | ||
| // (sourcePositions[0] points to 'node', sourcePositions[4] to 'parent') | ||
| long bestPosition; | ||
| { |
| long bestPosition; | ||
| { | ||
| bestPosition = -1L; | ||
| for (int i = 0; i < sourcePositions.length; i++) { |
There was a problem hiding this comment.
You can use a for-each loop here? would be easier to read.
| int end = (int) (p); | ||
| { // in specific cases like "node.|.child" the start might be larger than the end (see GH-2620) | ||
| if (start > end) { | ||
| int tmp = start; |
There was a problem hiding this comment.
if this code should swap start and end, you could add it as comment.
| } | ||
| } | ||
| if (bestPosition == -1L) { | ||
| // fallback to the previous behaviour, just in case. |
There was a problem hiding this comment.
In future it will not be clear what "previous" refers to. Please instead describe what the previous behavior was.
| this(selector, start, end, setup -> {/* use defaults */}); | ||
| } | ||
|
|
||
| public CompletionOnMessageSendName(char[] selector, int start, int end, Consumer<CompletionOnMessageSendName> setup) { |
There was a problem hiding this comment.
instead of using a Consumer for setup it would be easier to understand and maintain if you directly pass the initial values to the constructor. probably "cursorIsToTheLeftOfTheLParen" misses a "t" at the end and could be final.
There was a problem hiding this comment.
In order to unblock the change I'm applying some of these suggestions, but here's one correction: LParen is correct compiler lingo to refer to '(' (short for left parenthesis), nothing to do with parents :)
Completions for CompletionOnMessageSendName as well as for QualifiedNameReference did not take the cursor position into consideration, leading to various downstream issues like failing to complete at all, not properly overwriting a source range or overwriting too eagerly. fixes eclipse-jdt#2620
Changes during review:
+ revert overhead that was used just to set one addition boolean field
+ code simplification also in CompletionEngine
Tests:
+ make expected relevance explicit in terms of individual constants
+ two more tests to observe incremental differences
1a: when cursor is immediately after '('
1b: immediately before '(' when the selected method has parameters
fixes eclipse-jdt#2620
0dc2dc8 to
aa0c66d
Compare
|
Trying to unblock this issue I ...
One more observations, and one remaining task: (1) We should call out that the change in (2) I'm seeing a regression when trying the following in the IDE: Cursor location is indicated by
@angelickite can you find out, if this is a bug in JDT/UI, or can/should be fixed here? |
|
@stephan-herrmann Are we on the same page that this regression is foremost a side effect of the new approach? What I mean by that:
So the regression then manifests itself in the case where we have an empty argument list and can potentially safely modify the argument list too as a bonus feature as there is "nothing to break"? If this is the situation you refer to as the regression, looking back I did see this case appear but never gave it any attention or thought. Reason being that the completion behaviour around arguments always felt janky anyways as well as it not negatively impacting my workflow. If this feature is truly highly important, I will take a look where it originates and whether there is a sensible solution. Lastly, I personally would prefer this sidegrade every time over having the old behaviour back. |
I generally agree.
I didn't investigate the exact conditions under which arguments are proposed, perhaps my scenario is the only one, perhaps the feature applies much more broadly. I didn't test.
I agree that the behaviour around arguments has room for improvement. But that even more motivates me to be careful that we don't break behaviour that exists at present and may be very important to some users. A somewhat messy situation is no excuse for piling up more inconsistencies - and as I said the current state in this PR is inconsistent between insertion / overwrite modes. For me personally, support for arguments in calls to methods with long parameter lists is actually very relevant.
I'd appreciate. It would already help if we only find out if the problem is in jdt.core or jdt.ui.
I wouldn't wont to judge one user's needs against those of another :) |
|
The regression is here: https://github.com/angelickite/eclipse.jdt.core/blob/aa0c66d368586cdc30c18511f260519c80c59ff7/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java#L3263-L3270 So it stems directly from the new behaviour where "cursor to left of lparen" is given special consideration. Something like this just might do the trick (limited testing): (note the added |
|
@angelickite are you interested in taking this to completion? |
the L-Paren checks were redundant as `CompletionOnMessageSendName` already guarantees the cursor to be in a "good position".
|
@stephan-herrmann Should be good to go. The various holes in codecompletion go quite deep... so I've tried to find a balance between "keeping sanity", "recovering lost value", "maintaining the status quo" and "taking a step towards a better future". |
|
@stephan-herrmann Another ping. |
What it does
Add cursor awareness to various auto-completion situations.
Completions for CompletionOnMessageSendName as well as for QualifiedNameReference did not take the cursor position into consideration, leading to various downstream issues like failing to complete at all, not properly overwriting a source range or overwriting too eagerly.
fixes #2620
How to test
I've included some tests. A thorough description can be found in #2620.
Author checklist