Skip to content

Commit

Permalink
Only filter types from completion
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Oct 16, 2019
1 parent 50aa600 commit 0fc3034
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,19 @@ protected boolean isFiltered(CompletionProposal proposal) {
if (isIgnored(proposal.getKind())) {
return true;
}
char[] declaringType = getDeclaringType(proposal);
return declaringType != null && TypeFilter.isFiltered(declaringType);
// Only filter types and constructors from completion.
// Methods from already imported types and packages can still be proposed.
// See https://github.com/eclipse/eclipse.jdt.ls/issues/1212
switch (proposal.getKind()) {
case CompletionProposal.CONSTRUCTOR_INVOCATION:
case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
case CompletionProposal.JAVADOC_TYPE_REF:
case CompletionProposal.TYPE_REF: {
char[] declaringType = getDeclaringType(proposal);
return declaringType != null && TypeFilter.isFiltered(declaringType);
}
}
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,33 @@ public void testCompletion_FilterTypes() throws JavaModelException {
}
}

@Test
public void testCompletion_FilterTypesKeepMethods() throws JavaModelException {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java",
//@formatter:off
"package org.sample;\n"
+ "public class Test {\n\n"
+ " void test() {\n\n"
+ " java.util.List l; \n"
+ " l.clea \n"
+ " }\n"
+ "}\n");
//@formatter:on
int[] loc = findCompletionLocation(unit, "l.clea");
try {
List<String> filteredTypes = new ArrayList<>();
filteredTypes.add("java.util.*");
PreferenceManager.getPrefs(null).setFilteredTypes(filteredTypes);

CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertEquals("Missing completion", 1, list.getItems().size());
assertEquals("clear() : void", list.getItems().get(0).getLabel());
} finally {
PreferenceManager.getPrefs(null).setFilteredTypes(Collections.emptyList());
}
}

@Test
public void testCompletion_ConstantDefaultValue() throws JavaModelException {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java",
Expand Down

0 comments on commit 0fc3034

Please sign in to comment.