-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature discovery - Provide quick fix to 'Configure static import...' (…
- Loading branch information
1 parent
3ac1335
commit f598b79
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { CancellationToken, CodeAction, CodeActionContext, CodeActionKind, CodeActionProvider, Command, ExtensionContext, ProviderResult, Range, Selection, TextDocument, commands } from "vscode"; | ||
import { apiManager } from "./apiManager"; | ||
|
||
const configureStaticImportsCommand = "java.action.configureFavoriteStaticMembers"; | ||
const UNDEFINED_METHOD = "67108964"; | ||
export class ClientCodeActionProvider implements CodeActionProvider<CodeAction> { | ||
constructor(readonly context: ExtensionContext) { | ||
context.subscriptions.push(commands.registerCommand(configureStaticImportsCommand, async () => { | ||
commands.executeCommand("workbench.action.openSettings", "java.completion.favoriteStaticMembers"); | ||
apiManager.fireTraceEvent({ | ||
name: "java.ls.command", | ||
properties: { | ||
command: configureStaticImportsCommand, | ||
}, | ||
}); | ||
})); | ||
} | ||
|
||
provideCodeActions(document: TextDocument, range: Range | Selection, context: CodeActionContext, token: CancellationToken): ProviderResult<(CodeAction | Command)[]> { | ||
const codeActions = []; | ||
if (context.diagnostics?.some(diagnostic => diagnostic.code === UNDEFINED_METHOD) | ||
|| document.lineAt(range.start.line)?.text?.startsWith("import ")) { | ||
const action = new CodeAction("Configure static import...", CodeActionKind.QuickFix); | ||
action.command = { | ||
title: "Configure static import...", | ||
command: configureStaticImportsCommand, | ||
}; | ||
codeActions.push(action); | ||
} | ||
return codeActions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters