-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathExtractVariable.ts
More file actions
30 lines (24 loc) · 763 Bytes
/
ExtractVariable.ts
File metadata and controls
30 lines (24 loc) · 763 Bytes
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
import {
Action,
ActionPreferences,
ActionReturnValue,
Graph,
TypedSelection,
} from "../typings/Types";
import { ensureSingleTarget } from "../util/targetUtils";
import { commands } from "vscode";
export default class ExtractVariable implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];
constructor(private graph: Graph) {
this.run = this.run.bind(this);
}
async run([targets]: [TypedSelection[]]): Promise<ActionReturnValue> {
ensureSingleTarget(targets);
await this.graph.actions.setSelection.run([targets]);
await commands.executeCommand("editor.action.codeAction", {
kind: "refactor.extract.constant",
preferred: true,
});
return {};
}
}