Skip to content

Commit

Permalink
fix: codeActionKinds not sent when CodeActionClientCapability is not …
Browse files Browse the repository at this point in the history
…dynamic.
  • Loading branch information
ethan-vanderheijden committed May 3, 2024
1 parent 64dca83 commit 1f29e7f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionContext;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionOptions;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Diagnostic;
Expand All @@ -80,6 +81,19 @@ public class CodeActionHandler {
= new ResponseStore<>(ForkJoinPool.commonPool().getParallelism());
public static final String COMMAND_ID_APPLY_EDIT = "java.apply.workspaceEdit";

public static CodeActionOptions createOptions(PreferenceManager preferenceManager) {
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);
options.setResolveProvider(Boolean.valueOf(preferenceManager.getClientPreferences().isResolveCodeActionSupported()));
return options;
}

private QuickFixProcessor quickFixProcessor;
private RefactorProcessor refactorProcessor;
private QuickAssistProcessor quickAssistProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.jdt.ls.internal.gradle.checksums.WrapperValidator;
import org.eclipse.lsp4j.CodeActionOptions;
import org.eclipse.lsp4j.CodeLensOptions;
import org.eclipse.lsp4j.DocumentFilter;
import org.eclipse.lsp4j.DocumentOnTypeFormattingOptions;
Expand Down Expand Up @@ -145,13 +144,7 @@ public void registerCapabilities(InitializeResult initializeResult) {
capabilities.setRenameProvider(RenameHandler.createOptions());
}
if (!preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
if (preferenceManager.getClientPreferences().isResolveCodeActionSupported()) {
CodeActionOptions codeActionOptions = new CodeActionOptions();
codeActionOptions.setResolveProvider(Boolean.TRUE);
capabilities.setCodeActionProvider(codeActionOptions);
} else {
capabilities.setCodeActionProvider(Boolean.TRUE);
}
capabilities.setCodeActionProvider(CodeActionHandler.createOptions(preferenceManager));
}
if (!preferenceManager.getClientPreferences().isExecuteCommandDynamicRegistrationSupported()) {
Set<String> commands = commandHandler.getAllCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
import org.eclipse.lsp4j.CallHierarchyOutgoingCallsParams;
import org.eclipse.lsp4j.CallHierarchyPrepareParams;
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;
Expand Down Expand Up @@ -418,7 +416,7 @@ private void syncCapabilitiesToSettings() {
new ExecuteCommandOptions(new ArrayList<>(commandHandler.getNonStaticCommands())));
}
if (preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
toggleCapability(preferenceManager.getClientPreferences().isCodeActionDynamicRegistered(), Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION, getCodeActionOptions());
toggleCapability(preferenceManager.getClientPreferences().isCodeActionDynamicRegistered(), Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION, CodeActionHandler.createOptions(preferenceManager));
}
if (preferenceManager.getClientPreferences().isFoldgingRangeDynamicRegistered()) {
toggleCapability(preferenceManager.getPreferences().isFoldingRangeEnabled(), Preferences.FOLDINGRANGE_ID, Preferences.FOLDINGRANGE, null);
Expand Down Expand Up @@ -454,19 +452,6 @@ private void synchronizeBundles() {
}
}

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);
options.setResolveProvider(Boolean.valueOf(preferenceManager.getClientPreferences().isResolveCodeActionSupported()));
return options;
}

/* (non-Javadoc)
* @see org.eclipse.lsp4j.services.LanguageServer#shutdown()
*/
Expand Down

0 comments on commit 1f29e7f

Please sign in to comment.