-
Notifications
You must be signed in to change notification settings - Fork 373
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
Support advanced organizeImports to resolve ambiguous imports #966
Support advanced organizeImports to resolve ambiguous imports #966
Conversation
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
test this please |
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.
we also probably want to have a default selection exposed in the API, for each list of choices (even though we might not want to return a default selection at this point. Think java.util.List vs java.awt.List
....jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/text/correction/SourceAssistProcessor.java
Outdated
Show resolved
Hide resolved
....tests/src/org/eclipse/jdt/ls/core/internal/handlers/AdvancedOrganizeImportsHandlerTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
I'd like to see the server response to look something like: OrganizeImportsSelection:
I believe it'll be easier to understand the API and implement the client side |
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Updated the client callback api schema:
|
Optional<Either<Command, CodeAction>> organizeImports = convertToWorkspaceEditAction(params.getContext(), context.getCompilationUnit(), CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description, | ||
CodeActionKind.SourceOrganizeImports, organizeImportsEdit); | ||
addSourceActionCommand($, params.getContext(), organizeImports); | ||
if (preferenceManager.getClientPreferences().isAdvancedOrganizeImportsSupported()) { |
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.
The if conditional could be put insider getOrganizeImportsAction to make logic simple.
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 if
is to fall back to the old organizeImport logic if the JDT LS client doesn't implement chooseImports command yet. Don't belong to getOrganizeImportsAction function.
...clipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/OrganizeImportsHandler.java
Outdated
Show resolved
Hide resolved
...clipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/OrganizeImportsHandler.java
Outdated
Show resolved
Hide resolved
...clipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/OrganizeImportsHandler.java
Outdated
Show resolved
Hide resolved
...clipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/OrganizeImportsHandler.java
Outdated
Show resolved
Hide resolved
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.
CIL
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
Now I'm having 2nd thoughts on the default selection. The problem with it is it adds more work onto clients to implement proper sorting, when it could be done at the server level, consistently for everyone. WDYT? We could imagine the server will eventually guarantee a sort order based on a relevancy score. |
@yaohaizh CIL? |
When submit a review feedback, it requires comments, so CIL for comment in lines |
See
vscode QuickPick only supports preselecting for multiple selections. And for single selection QuickPick, it will preselect the top one by default. So i did sorting to put the default selection to the top. I like the idea of guarantee a sort order based on a relevancy score. If the server returns the sorted candidates list, then no need of |
Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
About calculating the relevancy of the candidate, one idea is to record the user picking history, and put the candidate in the history to the top. Also, if some class under the same package is existing in the history, give the candidate high priority. In this PR, i removed the default selection logic, and add TODO tag about sorting. Will let a new PR to explore the sorting for the import candidates. |
Nice work @testforstephen! |
Signed-off-by: Jinbo Wang jinbwan@microsoft.com
See PR redhat-developer/vscode-java#850 for vscode client implementation.