Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faulty/Undesired CodeCompletion behaviour #2620 #3350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

angelickite
Copy link

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

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
@@ -3562,7 +3567,41 @@ private void completionOnQualifiedNameReference(ASTNode astNode, ASTNode enclosi
private void internalCompletionOnQualifiedReference(ASTNode ref, ASTNode enclosingNode, Binding qualifiedBinding, Scope scope,
boolean insideTypeAnnotation, boolean isInsideAnnotationAttribute, InvocationSite site, char[][] tokens, long[] sourcePositions)
{
long completionPosition = sourcePositions[sourcePositions.length - 1];
// we take the cursor location into consideration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why start a codeblock here?

long bestPosition;
{
bestPosition = -1L;
for (int i = 0; i < sourcePositions.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faulty/Undesired CodeCompletion behaviour
2 participants