-
Notifications
You must be signed in to change notification settings - Fork 408
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
Exclude certain packages from autocomplete/autoimport #1176
Conversation
@@ -801,6 +813,14 @@ public Preferences setImportOrder(List<String> importOrder) { | |||
return this; | |||
} | |||
|
|||
public Preferences setFilteredTypes(List<String> filteredTypes) { | |||
this.filteredTypes = (filteredTypes == null || filteredTypes.size() == 0) ? JAVA_COMPLETION_FILTERED_TYPES_DEFAULT : filteredTypes; |
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.
If user decides to remove filters (sets empty list), we should not force our default filters
private StringMatcher[] fStringMatchers; | ||
|
||
/** | ||
* |
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.
Empty javadoc
@@ -368,6 +374,8 @@ | |||
JAVA_IMPORT_ORDER_DEFAULT.add("javax"); | |||
JAVA_IMPORT_ORDER_DEFAULT.add("com"); | |||
JAVA_IMPORT_ORDER_DEFAULT.add("org"); | |||
JAVA_COMPLETION_FILTERED_TYPES_DEFAULT = new ArrayList<>(); | |||
JAVA_IMPORT_ORDER_DEFAULT.add("java.awt.*"); |
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.
Should be JAVA_COMPLETION_FILTERED_TYPES_DEFAULT.add
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.
Also add com.sun.*
boolean exists = false; | ||
for (CompletionItem item : list.getItems()) { | ||
if ("List - java.util".equals(item.getLabel())) { | ||
exists = true; |
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.
Just call fail() here
|
||
WorkspaceEdit rootEdit = new WorkspaceEdit(); | ||
command.organizeImportsInCompilationUnit(cu, rootEdit); | ||
assertTrue(rootEdit.getChanges().size() == 0); |
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.
assertEquals
assertTrue(rootEdit.getChanges().size() == 0); | ||
PreferenceManager.getPrefs(null).setFilteredTypes(Collections.emptyList()); | ||
command.organizeImportsInCompilationUnit(cu, rootEdit); | ||
assertFalse(rootEdit.getChanges().size() == 0); |
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.
IsEmpty
Signed-off-by: Snjezana Peco <[email protected]>
@fbricon I have updated the PR. |
@@ -349,6 +397,9 @@ public void testOrganizeImportsInProject() throws CoreException, BadLocationExce | |||
|
|||
private String getOrganizeImportResult(ICompilationUnit cu, WorkspaceEdit we) throws BadLocationException, CoreException { | |||
List<TextEdit> change = we.getChanges().get(JDTUtils.toURI(cu)); | |||
if (change == null) { |
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.
What is the use case here?
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.
'change' is null if there aren't any actions.
PreferenceManager.getPrefs(null).setFilteredTypes(Collections.emptyList()); | ||
command.organizeImportsInCompilationUnit(cu, rootEdit); | ||
assertFalse(rootEdit.getChanges().isEmpty()); | ||
assertEquals(buf.toString(), getOrganizeImportResult(cu, rootEdit)); |
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.
if you set an empty list for filtered types, how come the organize imports action managed to select java.util.List over java.awt.List?
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.
TypeFilter is never called in this test. I don't understand how it even passes
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.
if you set an empty list for filtered types, how come the organize imports action managed to select java.util.List over java.awt.List?
java.awt.List doesn't exist when running tests.
TypeFilter is never called in this test. I don't understand how it even passes
See org.eclipse.jdt.core.manipulation.TypeNameMatchCollector.getStringMatchers()
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.
Ok I suspect the fake rt jars we use don't have the java.awt classes.
Thanks for the info about TypeNameMatchCollector
Fixes redhat-developer/vscode-java#710
Requires redhat-developer/vscode-java#1059
Signed-off-by: Snjezana Peco [email protected]