Skip to content
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

Merged
merged 2 commits into from
Nov 14, 2018
Merged

Conversation

yaohaizh
Copy link
Contributor

No description provided.

@fbricon
Copy link
Contributor

fbricon commented Sep 21, 2018

I believe you need to check if the client supports code action literals before sending back code actions. Else, keep the current behaviour

Copy link
Contributor

@fbricon fbricon left a 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

@fbricon
Copy link
Contributor

fbricon commented Oct 1, 2018

@yaohaizh any updates?

@yaohaizh yaohaizh force-pushed the yaohai_codeaction branch 2 times, most recently from a063884 to f6bccef Compare October 8, 2018 02:40
@yaohaizh
Copy link
Contributor Author

yaohaizh commented Oct 8, 2018

@fbricon Updated the PR. However, the UI is not updated because of this issue: eclipse-lsp4j/lsp4j#266

@fbricon
Copy link
Contributor

fbricon commented Oct 8, 2018

@yaohaizh can you try opening a PR for lsp4j?

@yaohaizh
Copy link
Contributor Author

yaohaizh commented Oct 8, 2018

@fbricon Will update the lsp4j protocol.

@yaohaizh
Copy link
Contributor Author

yaohaizh commented Oct 8, 2018

eclipse-lsp4j/lsp4j#268

@snjeza
Copy link
Contributor

snjeza commented Oct 9, 2018

The PR fixes #796

@snjeza
Copy link
Contributor

snjeza commented Oct 10, 2018

However, the UI is not updated because of this issue: eclipse-lsp4j/lsp4j#266

The PR works correctly. I have done the following:

  • updated lsp4j
  • registered the code action options which add "Refactor..." and "Source Action..." to the editor's context menu
  • renamed the "quickfix" actions to "refactor.quickfix" - the "quickfix" code actions aren't included into the Refactor context menu. Only those code actions that start with 'refactor' are included.

@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"/>	

@yaohaizh
Copy link
Contributor Author

@fbricon Could we directly apply @snjeza change to this PR and merge if everything okay?

@fbricon
Copy link
Contributor

fbricon commented Oct 15, 2018

@snjeza you can resubmit the PR with your changes on top of it. Either amend @yaohaizh's commit with your changes or, if you care about authorship, add your own commit

@snjeza snjeza force-pushed the yaohai_codeaction branch from f6bccef to a7ed3ea Compare October 15, 2018 23:52
@snjeza
Copy link
Contributor

snjeza commented Oct 16, 2018

@fbricon I have updated the PR.

@snjeza snjeza force-pushed the yaohai_codeaction branch from a7ed3ea to df4a4bf Compare October 16, 2018 00:49
if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(kind)) {
CodeAction codeAction = new CodeAction(name);
if (CodeActionKind.QuickFix.equals(kind)) {
kind = REFACTOR_QUICKFIX;
Copy link
Contributor

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/"/>
Copy link
Contributor

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

@snjeza snjeza force-pushed the yaohai_codeaction branch from df4a4bf to 308e7de Compare October 17, 2018 18:33
@snjeza
Copy link
Contributor

snjeza commented Oct 17, 2018

@fbricon @yaohaizh I have updated the PR.

@snjeza snjeza force-pushed the yaohai_codeaction branch from 308e7de to 7157807 Compare October 19, 2018 20:29
@yaohaizh
Copy link
Contributor Author

@fbricon What is scheduled timeline for this PR?

@fbricon
Copy link
Contributor

fbricon commented Oct 23, 2018

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.

@fbricon fbricon added this to the End October 2018 milestone Oct 23, 2018
@fbricon
Copy link
Contributor

fbricon commented Oct 23, 2018

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.

@kittaakos
Copy link

lsp4j p2 repo is no longer available.
when is your next milestone released planned for?

@spoenemann

@spoenemann
Copy link

lsp4j p2 repo is no longer available.

What does that mean? We have
http://download.eclipse.org/lsp4j/updates/releases/0.5.0/

when is your next milestone released planned for?

No plans yet. You could use the snapshot build
https://ci.eclipse.org/lsp4j/job/lsp4j-snapshots/lastStableBuild/artifact/build-result/p2.repository/

@spoenemann
Copy link

I scheduled the next LSP4J release for November 30th.

https://projects.eclipse.org/projects/technology.lsp4j

@fbricon fbricon merged commit 044b66f into master Nov 14, 2018
@fbricon
Copy link
Contributor

fbricon commented Nov 14, 2018

There's a couple of issues that need to be dealt with, but I'll open separate tickets for those (no getter/setter refactoring when private field is used privately / organize imports should appear in source actions).
So far, it seems to work pretty well. Nice work @yaohaizh and @snjeza!

@yaohaizh
Copy link
Contributor Author

@fbricon Think so. We need remove the customized organize UI in the client also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants