Skip to content

Commit 949e624

Browse files
aminyaalexheretic
andcommitted
feat: support custom filterCodeActions
Co-Authored-By: Alex Butler <[email protected]>
1 parent ca02334 commit 949e624

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/adapters/code-action-adapter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ export default class CodeActionAdapter {
4141
linterAdapter: LinterPushV2Adapter | IdeDiagnosticAdapter | undefined,
4242
editor: TextEditor,
4343
range: Range,
44-
linterMessages: linter.Message[] | atomIde.Diagnostic[]
44+
linterMessages: linter.Message[] | atomIde.Diagnostic[],
45+
filterActions: (actions: (Command | CodeAction)[] | null) => (Command | CodeAction)[] | null = (actions) => actions
4546
): Promise<atomIde.CodeAction[]> {
4647
if (linterAdapter == null) {
4748
return []
4849
}
4950
assert(serverCapabilities.codeActionProvider, "Must have the textDocument/codeAction capability")
5051

5152
const params = createCodeActionParams(linterAdapter, editor, range, linterMessages)
52-
const actions = await connection.codeAction(params)
53+
const actions = filterActions(await connection.codeAction(params))
5354
if (actions === null) {
5455
return []
5556
}

lib/auto-languageclient.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,10 +944,16 @@ export default class AutoLanguageClient {
944944
this.getServerAdapter(server, "linterPushV2"),
945945
editor,
946946
range,
947-
diagnostics
947+
diagnostics,
948+
this.filterCodeActions.bind(this)
948949
)
949950
}
950951

952+
/** Optionally filter code action before they're displayed */
953+
protected filterCodeActions(actions: (ls.Command | ls.CodeAction)[] | null): (ls.Command | ls.CodeAction)[] | null {
954+
return actions
955+
}
956+
951957
public provideRefactor(): atomIde.RefactorProvider {
952958
return {
953959
grammarScopes: this.getGrammarScopes(),

0 commit comments

Comments
 (0)