Skip to content

Commit

Permalink
Fixed a bug where the autocomplete could show a ghost variable inferr…
Browse files Browse the repository at this point in the history
…ed from the stem of the item being code completed.
  • Loading branch information
neilccbrown committed Jan 18, 2024
1 parent 43578fd commit ac14752
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bluej/src/main/java/bluej/parser/ParseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private static List<AssistContent> getCompletionsForTarget(GenTypeClass exprType
if (surroundingMethod != null && suggests.isPlain())
{
// Find and add the local variables:
findLocalVariables(findInnerMostNode(ourPos - surroundingMethod.getAbsoluteEditorPosition(), surroundingMethod), surroundingMethod, ourPos).forEach(var -> {
findLocalVariables(findInnerMostNode(ourPos - surroundingMethod.getAbsoluteEditorPosition(), surroundingMethod), surroundingMethod, ourPos - (suggests.getSuggestionToken() == null ? 0 : suggests.getSuggestionToken().getLength())).forEach(var -> {
AssistContent completion = LocalCompletion.getCompletion(var.getFieldTypeAsPlainString(), var.getName(), false);
if (completion != null)
{
Expand Down
19 changes: 19 additions & 0 deletions bluej/src/test/java/bluej/parser/CompletionTest3.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,23 @@ public Foo(double x, int y, int z)
new AC("int z")
));
}

@Test
public void testNoIncorrectVars()
{
// Saw a behaviour where with a partial expression, we were considering this a variable declaration in progress
// and showing a variable that did not really exist (in this case, "myObj" with type "x"):
assertNamesAtA(List.of("int var1", "int var2", "String var3"), List.of( "myObj"), """
class Foo
{
<T> void foo(List<T> param1, T param2, int param3)
{
int var1, var2;
String var3;
x/*A*/
myObj.toString();
}
}
""");
}
}

0 comments on commit ac14752

Please sign in to comment.