-
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
Adopt CodeAction & CodeActionKind protocol. #800
Conversation
I believe you need to check if the client supports code action literals before sending back code actions. Else, keep the current behaviour |
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.
Check client capability before enabling that feature
@yaohaizh any updates? |
a063884
to
f6bccef
Compare
@fbricon Updated the PR. However, the UI is not updated because of this issue: eclipse-lsp4j/lsp4j#266 |
@yaohaizh can you try opening a PR for lsp4j? |
@fbricon Will update the lsp4j protocol. |
The PR fixes #796 |
The PR works correctly. I have done the following:
@fbricon We should move the "Organize Imports" action to "Source Action...". My changes: diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeActionHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeActionHandler.java
index 3263bf8a..8ac8431a 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeActionHandler.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeActionHandler.java
@@ -108,9 +108,13 @@ public class CodeActionHandler {
ICompilationUnit unit = proposal.getCompilationUnit();
Command command = new Command(name, COMMAND_ID_APPLY_EDIT, Arrays.asList(convertChangeToWorkspaceEdit(unit, proposal.getChange())));
- if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(proposal.getKind())) {
+ String kind = proposal.getKind();
+ if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(kind)) {
CodeAction codeAction = new CodeAction(name);
- codeAction.setKind(proposal.getKind());
+ if ("quickfix".equals(kind)) {
+ kind = "refactor.quickfix";
+ }
+ codeAction.setKind(kind);
codeAction.setCommand(command);
codeAction.setDiagnostics(context.getDiagnostics());
return Either.forRight(codeAction);
diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java
index c04ff869..828a46c8 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java
@@ -59,6 +59,8 @@ import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionKind;
+import org.eclipse.lsp4j.CodeActionOptions;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.CodeLensOptions;
@@ -185,7 +187,7 @@ public class JDTLanguageServer implements LanguageServer, TextDocumentService, W
registerCapability(Preferences.DOCUMENT_SYMBOL_ID, Preferences.DOCUMENT_SYMBOL);
}
if (preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
- registerCapability(Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION);
+ registerCapability(Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION, getCodeActionOptions());
}
if (preferenceManager.getClientPreferences().isDefinitionDynamicRegistered()) {
registerCapability(Preferences.DEFINITION_ID, Preferences.DEFINITION);
@@ -255,6 +257,21 @@ public class JDTLanguageServer implements LanguageServer, TextDocumentService, W
toggleCapability(preferenceManager.getPreferences().isExecuteCommandEnabled(), Preferences.EXECUTE_COMMAND_ID, Preferences.WORKSPACE_EXECUTE_COMMAND,
new ExecuteCommandOptions(new ArrayList<>(WorkspaceExecuteCommandHandler.getCommands())));
}
+ if (preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
+ toggleCapability(preferenceManager.getClientPreferences().isCodeActionDynamicRegistered(), Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION, getCodeActionOptions());
+ }
+ }
+
+ private CodeActionOptions getCodeActionOptions() {
+ String[] kinds = { CodeActionKind.QuickFix, CodeActionKind.Refactor, CodeActionKind.RefactorExtract, CodeActionKind.RefactorInline, CodeActionKind.RefactorRewrite, CodeActionKind.Source, CodeActionKind.SourceOrganizeImports };
+ List<String> codeActionKinds = new ArrayList<>();
+ for (String kind : kinds) {
+ if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(kind)) {
+ codeActionKinds.add(kind);
+ }
+ }
+ CodeActionOptions options = new CodeActionOptions(codeActionKinds);
+ return options;
}
/* (non-Javadoc)
diff --git a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
index 49c3f9ac..ee054344 100644
--- a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
+++ b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target
@@ -33,13 +33,13 @@
<repository location="http://download.eclipse.org/eclipse/updates/4.10-I-builds/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
- <unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.5.0.v20180903-1212"/>
- <repository location="http://download.eclipse.org/lsp4j/updates/releases/0.5.0/"/>
+ <unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.6.0.v20181008-1501"/>
+ <repository location="http://services.typefox.io/open-source/jenkins/job/lsp4j/job/master/lastStableBuild/artifact/build/p2-repository/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
- <unit id="org.eclipse.xtend.sdk.feature.group" version="2.14.0.v20180523-0937"/>
- <unit id="org.eclipse.xtext.sdk.feature.group" version="2.14.0.v20180523-0937"/>
- <repository location="http://download.eclipse.org/releases/photon/"/>
+ <unit id="org.eclipse.xtend.sdk.feature.group" version="2.15.0.v20180916-1232"/>
+ <unit id="org.eclipse.xtext.sdk.feature.group" version="2.15.0.v20180916-1232"/>
+ <repository location="http://download.eclipse.org/releases/2018-09/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.jboss.tools.maven.apt.feature.feature.group" version="1.5.0.201805160042"/> |
f6bccef
to
a7ed3ea
Compare
@fbricon I have updated the PR. |
a7ed3ea
to
df4a4bf
Compare
if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(kind)) { | ||
CodeAction codeAction = new CodeAction(name); | ||
if (CodeActionKind.QuickFix.equals(kind)) { | ||
kind = REFACTOR_QUICKFIX; |
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. Quick fixes are no longer quick fixes that way, so no actions available from the problems view in vscode
<unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.5.0.v20180903-1212"/> | ||
<repository location="http://download.eclipse.org/lsp4j/updates/releases/0.5.0/"/> | ||
<unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.6.0.v20181008-1501"/> | ||
<repository location="http://services.typefox.io/open-source/jenkins/job/lsp4j/job/master/lastStableBuild/artifact/build/p2-repository/"/> |
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.
http://services.typefox.io/open-source/jenkins/job/lsp4j/job/master/31/artifact/build/p2-repository/ will be a little more stable (not by much), until 0.6.0 gets a milestone
df4a4bf
to
308e7de
Compare
308e7de
to
7157807
Compare
@fbricon What is scheduled timeline for this PR? |
I gotta release jdt.ls for code one, but this PR won't be a part of it, as I haven't been able to thoroughly test it, so I'll merge after tomorrow's release, and we'll be able to properly vet it for the next week or so. |
lsp4j p2 repo is no longer available. @kittaakos @svenefftinge, when is your next milestone released planned for? I'd like to use a stable(r) version than the last successful build. |
|
What does that mean? We have
No plans yet. You could use the snapshot build |
I scheduled the next LSP4J release for November 30th. |
7157807
to
c70cdef
Compare
Signed-off-by: Snjezana Peco <[email protected]>
c70cdef
to
fadb166
Compare
@fbricon Think so. We need remove the customized organize UI in the client also. |
No description provided.