-
Notifications
You must be signed in to change notification settings - Fork 136
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3244,9 +3244,14 @@ private void completionOnMessageSendName(ASTNode astNode, Binding qualifiedBindi | |
if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) { | ||
CompletionOnMessageSendName messageSend = (CompletionOnMessageSendName) astNode; | ||
|
||
setTokenRange(messageSend.sourceStart, messageSend.sourceEnd); | ||
if (messageSend.statementEnd > messageSend.sourceStart) | ||
setSourceRange(messageSend.sourceStart, messageSend.statementEnd); | ||
// we take the cursor location into consideration | ||
if (messageSend.cursorIsToTheLeftOfTheLParen) { | ||
setSourceAndTokenRange(messageSend.sourceStart, messageSend.sourceEnd); | ||
} else { | ||
setTokenRange(messageSend.sourceStart, messageSend.sourceEnd); | ||
if (messageSend.statementEnd > messageSend.sourceStart) | ||
setSourceRange(messageSend.sourceStart, messageSend.statementEnd); | ||
} | ||
|
||
this.completionToken = messageSend.selector; | ||
|
||
|
@@ -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. | ||
// | ||
// void x(TreeNode node) { | ||
// TreeNode other = node.ch|.child.child.parent; | ||
// // ... | ||
// } | ||
// | ||
// 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; | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why start a codeblock here? |
||
bestPosition = -1L; | ||
for (int i = 0; i < sourcePositions.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
long p = sourcePositions[i]; | ||
int start = (int) (p >>> 32); | ||
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. Choose a reason for hiding this commentThe 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. |
||
start = end; | ||
end = tmp; | ||
} | ||
} | ||
boolean cursorWithinBounds = (start <= this.actualCompletionPosition && this.actualCompletionPosition <= end); | ||
if (cursorWithinBounds) { | ||
bestPosition = p; | ||
} | ||
} | ||
} | ||
if (bestPosition == -1L) { | ||
// fallback to the previous behaviour, just in case. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
bestPosition = sourcePositions[sourcePositions.length - 1]; | ||
} | ||
long completionPosition = bestPosition; | ||
|
||
if (qualifiedBinding.problemId() == ProblemReasons.NotFound) { | ||
setSourceAndTokenRange((int) (completionPosition >>> 32), (int) completionPosition); | ||
// complete field members with missing fields type | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2006, 2013 IBM Corporation and others. | ||
* Copyright (c) 2006, 2024 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -13,6 +13,7 @@ | |
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.codeassist.complete; | ||
|
||
import java.util.function.Consumer; | ||
import org.eclipse.jdt.internal.compiler.ast.MessageSend; | ||
import org.eclipse.jdt.internal.compiler.impl.Constant; | ||
import org.eclipse.jdt.internal.compiler.lookup.BlockScope; | ||
|
@@ -27,14 +28,19 @@ | |
public class CompletionOnMessageSendName extends MessageSend implements CompletionNode { | ||
|
||
public boolean nextIsCast; | ||
public boolean cursorIsToTheLeftOfTheLParen; | ||
|
||
public CompletionOnMessageSendName(char[] selector, int start, int end, boolean nextIsCast) { | ||
public CompletionOnMessageSendName(char[] selector, int start, int end) { | ||
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. Choose a reason for hiding this commentThe 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. |
||
super(); | ||
this.selector = selector; | ||
this.sourceStart = start; | ||
this.sourceEnd = end; | ||
this.nameSourcePosition = end; | ||
this.nextIsCast = nextIsCast; | ||
setup.accept(this); | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
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