-
Notifications
You must be signed in to change notification settings - Fork 524
Expand file tree
/
Copy pathcodeActionProvider.ts
More file actions
45 lines (42 loc) · 1.81 KB
/
codeActionProvider.ts
File metadata and controls
45 lines (42 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { CodeActionProvider, CodeActionProviderMetadata, CodeActionKind } from "vscode";
import { Commands } from "./commands";
/**
* Mapping the refactoring kind to its section id in the document
*/
export const javaRefactorKinds: Map<CodeActionKind, string> = new Map([
[CodeActionKind.Refactor, 'java-refactoring'],
[CodeActionKind.RefactorExtract, 'extract-to-constant'],
[CodeActionKind.RefactorExtract.append('function'), 'extract-to-method'],
[CodeActionKind.RefactorExtract.append('constant'), 'extract-to-constant'],
[CodeActionKind.RefactorExtract.append('variable'), 'extract-to-local-variable'],
[CodeActionKind.RefactorExtract.append('field'), 'extract-to-field'],
[CodeActionKind.RefactorInline, 'inline-constant'],
[CodeActionKind.Refactor.append('move'), 'move'],
[CodeActionKind.Refactor.append('assign'), 'assign-to-variable'],
[CodeActionKind.Refactor.append('introduce').append('parameter'), 'introduce-parameter']
]);
export class RefactorDocumentProvider implements CodeActionProvider {
provideCodeActions() {
return [{
// The aim of this is to expose the source actions in the light bulb.
title: "Source Actions...",
command: "editor.action.sourceAction",
kind: CodeActionKind.Empty,
}];
}
public static readonly metadata: CodeActionProviderMetadata = {
providedCodeActionKinds: [
CodeActionKind.Refactor
],
documentation: Array.from(javaRefactorKinds.keys()).map(kind => {
return {
kind,
command: {
command: Commands.LEARN_MORE_ABOUT_REFACTORING,
title: 'Learn more about Java refactorings...',
arguments: [kind]
}
};
}),
};
}