-
Notifications
You must be signed in to change notification settings - Fork 400
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
Modified to use WorkspaceEdit on OrganizeImports. #1059
Modified to use WorkspaceEdit on OrganizeImports. #1059
Conversation
Can one of the admins verify this patch? |
Test this please |
@mikoto2000 can you please sign the Eclipse ECA and sign-off your commit? |
Okay. I will sign ECA and add Signed-Off-By. |
4c2004b
to
03e80cc
Compare
I added Signed-Off-By. |
This might break the organize imports if the organize coming with commands such as resolve ambiguity . @testforstephen Please help review this one for organize changes. @mikoto2000 Please find document for code action carefully: https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction These two edits & commands are not mutually exclusive. |
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.
Need review from @testforstephen
CodeAction codeAction = new CodeAction(CorrectionMessages.ReorgCorrectionsSubProcessor_organizeimports_description); | ||
codeAction.setKind(CodeActionKind.SourceOrganizeImports); | ||
codeAction.setCommand(command); | ||
if (preferenceManager.getClientPreferences().isWorkspaceApplyEditSupported()) { |
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.
getOrganizeImportsAction
is used for advanced organize imports (Prompt a UI for resolve ambiguous imports). The command it returns is java.action.organizeImports
, not java.apply.workspaceEdit
. If you don't implement the command in the client side, please keep initializationOptions/extendedClientCapabilities/advancedOrganizeImportsSupport
to false
.
What you need look at is the function convertToWorkspaceEditAction
.
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 you need look at is the function convertToWorkspaceEditAction.
Thank you.
I was misunderstanding advanced code action function...
I want to work organize imports, without client-side command implementation.
so I will no fix getOrganizeImportsAction
.
I check convertToWorkspaceEditAction
and try fix it.
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.
I fix List of support WorkspaceEdit commands:
List of no support WorkspaceEdit commands:
Condition of using WorkspaceEdit:
|
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.
It's better to only add some different test cases, no need for duplicate code
} | ||
|
||
@Test | ||
public void testCodeAction_exception() throws JavaModelException { |
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 test case is same as CodeActionHandlerTest. No need of it.
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.
} | ||
|
||
@Test | ||
public void test_noUnnecessaryCodeActions() throws Exception{ |
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.
Same as CodeActionHandlerTest. No need of it.
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 server.codeAction(params).join(); | ||
} | ||
|
||
public static Command getCommand(Either<Command, CodeAction> codeAction) { |
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.
duplicate with CodeActionHandlerTest.
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 $; | ||
} | ||
|
||
public static boolean containsKind(List<Either<Command, CodeAction>> codeActions, String kind) { |
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.
Duplicated code. Use CodeActionHandlerTest#containsKind directly.
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.
Fixed in da69be9.
I deleted test_noUnnecessaryCodeActions
, so no longer needed to call containsKind
.
c7205e2
to
da69be9
Compare
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.
LGTM
When this PR is merged, it may have some side effects for vscode-java client. Currently vscode-client used a customized But when switching to this PR behavior, the vscode will auto apply the workspace edit, but without formatting operation. |
Okay. I reproduced this behavior. so I want to make format unnecessary after applyWorkspaceEdit. I propose a solution. Modify of Add configurations.
CodeGenerator respect JavaCore settings so format unnecessary after applyWorkspaceEdit. processing of vscode-java: Use those value when initialize and change configuration.
What do you think about it? |
Sorry but I need to better understand the new behavior before merging it, so I'll punt to target milestone to end of august |
Any updates on this? |
Sorry for the delay, I'm stretched on different projects and need to go through my backlog. But I haven't forgotten. I'll review as soon as I can. |
Ok, I can look at it now, but after rebasing against master, the code no longer compile. |
@testforstephen once #1194 and #1157 are fixed, the formatting issue should be fixed right? |
yes, these two issues should be able to fix it. |
Thank you. |
Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
…spaceEdit. Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
Signed-off-by: mikoto2000 <mikoto2000@gmail.com>
da69be9
to
aef4691
Compare
I rebased from latest master(d30acc4). |
codeAction.setDiagnostics(context.getDiagnostics()); | ||
if (useWorkspaceEdit) { | ||
codeAction.setEdit(edit); |
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 can easily throw a NullPointerException
. If the proposal
is either CUCorrectionCommandProposal
or RefactoricCorrectionCommandProposal
, there is no WorkspaceEdit
created.
This is what happened in #1256 (comment) and was taken care of in #1278. Good luck.
This PR is part of #376.
Modified to use WorkspaceEdit on OrganizeImports if client supported
workspace/applyEdit
.Needed those client capabilities and initialization parameters for use WorkspaceEdit.
quickfix
workspace/applyEdit
istrue
textDocument/codeAction/codeActionLiteralSupport/codeActionKind/valueSet
containsquickfix
source.organizeImports
workspace/applyEdit
istrue
initializationOptions/extendedClientCapabilities/advancedOrganizeImportsSupport
istrue