-
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
Add source CodeAction support for organize imports. #856
Conversation
4bb07a3
to
532fd6d
Compare
@@ -60,10 +60,10 @@ private static int moveBack(int offset, int start, String ignoreCharacters, ICom | |||
return start; | |||
} | |||
|
|||
public CUCorrectionProposal[] getCorrections(IInvocationContext context, IProblemLocationCore[] locations) | |||
public ArrayList<CUCorrectionProposal> getCorrections(IInvocationContext context, IProblemLocationCore[] locations) |
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.
public List
throws CoreException { | ||
if (locations == null || locations.length == 0) { | ||
return new CUCorrectionProposal[0]; | ||
return new ArrayList<>(); |
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.
return Collections.emptyList();
$.add(getCodeActionFromProposal(proposal, params.getContext())); | ||
} | ||
ArrayList<CUCorrectionProposal> corrections = this.quickFixProcessor.getCorrections(context, locations); | ||
corrections.sort(new CUCorrectionProposalComparator()); |
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.
no need to sort it now, it'll be sorted again L101
|
||
try { | ||
ArrayList<CUCorrectionProposal> corrections = this.quickAssistProcessor.getAssists(context, locations); | ||
corrections.sort(new CUCorrectionProposalComparator()); |
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.
no need to sort it now, it'll be sorted again L101
} | ||
|
||
ArrayList<CUCorrectionProposal> corrections = this.sourceAssistProcessor.getAssists(context, locations); | ||
corrections.sort(new CUCorrectionProposalComparator()); |
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.
sort candidates instead
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.
Would keep the group by kind before sort.
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.
then just make the comparator use the kind 1st
@@ -141,7 +141,7 @@ | |||
public QuickAssistProcessor() { | |||
} | |||
|
|||
public CUCorrectionProposal[] getAssists(IInvocationContext context, IProblemLocationCore[] locations) throws CoreException { | |||
public ArrayList<CUCorrectionProposal> getAssists(IInvocationContext context, IProblemLocationCore[] locations) throws CoreException { |
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.
public List
} | ||
return new CUCorrectionProposal[0]; | ||
return new ArrayList<>(); |
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.
Collections.emptyList
|
||
public class SourceAssistProcessor { | ||
|
||
public SourceAssistProcessor() { |
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.
unnecessary constructor
@@ -0,0 +1,61 @@ | |||
|
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.
remove extra blank line
@@ -179,6 +190,22 @@ protected void setIgnoredCommands(List<String> ignoredCommands) { | |||
parms.setContext(context); | |||
|
|||
List<Either<Command, CodeAction>> codeActions = new CodeActionHandler(this.preferenceManager).getCodeActionCommands(parms, new NullProgressMonitor()); | |||
|
|||
if (this.ignoredKinds != null) { | |||
List<Either<Command, CodeAction>> filteredList = new ArrayList<>(); |
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.
filteredList = codeActions.stream().filter(Either::isRight).filter(codeAction -> {
for (String str : this.ignoredKinds) {
if (codeAction.getRight().getKind().matches(str)) {
return false;
}
}
return true;
}).collect(Collectors.toList())
@@ -161,6 +168,10 @@ protected void setIgnoredCommands(List<String> ignoredCommands) { | |||
this.ignoredCommands = ignoredCommands; | |||
} | |||
|
|||
protected void setIgnoredKind(List<String> ignoredKind) { |
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.
String...ignoredKind makes it easier to use
fJProject1.setOptions(options); | ||
fSourceFolder = fJProject1.getPackageFragmentRoot(fJProject1.getProject().getFolder("src")); | ||
|
||
this.setIgnoredKind(Arrays.asList("quickfix.*", "refactor.*")); |
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.
this.setIgnoredKind("quickfix.", "refactor."); when you have setIgnoredKind(String...ignoredKind)
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.
A few minor things to change, but overall, this works as expected. I'm looking forward to merging it
Signed-off-by: Yaohai Zheng <[email protected]>
532fd6d
to
2f7ad52
Compare
@fbricon Updated PR. Just keep the group by kind behavior. |
test this please |
@yaohaizh please fix the build (390 failures because of new, unexpected, code action) |
cbf60d8
to
a2cae96
Compare
@fbricon Updated the PR |
test this please |
@fbricon The original organize imports delegate commands is not deleted yet since it is used by other client and provide organize in folders/workspaces functionalities.
Fixes #845