Skip to content

Commit 96c1d62

Browse files
author
Kapil Borle
committed
Refactor CodeActions to fit the new model
1 parent 378a4cb commit 96c1d62

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

src/features/CodeActions.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
import vscode = require('vscode');
22
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
33
import Window = vscode.window;
4+
import { IFeature } from '../feature';
45

5-
export function registerCodeActionCommands(client: LanguageClient): void {
6-
vscode.commands.registerCommand('PowerShell.ApplyCodeActionEdits', (edit: any) => {
7-
console.log("Applying edits");
8-
console.log(edit);
9-
var editor = Window.activeTextEditor;
10-
var filePath = editor.document.fileName;
11-
var workspaceEdit = new vscode.WorkspaceEdit();
12-
workspaceEdit.set(
13-
vscode.Uri.file(filePath),
14-
[
15-
new vscode.TextEdit(
16-
new vscode.Range(
17-
edit.StartLineNumber - 1,
18-
edit.StartColumnNumber - 1,
19-
edit.EndLineNumber - 1,
20-
edit.EndColumnNumber - 1),
21-
edit.Text)
22-
]);
23-
vscode.workspace.applyEdit(workspaceEdit);
24-
});
6+
export class CodeActionsFeature implements IFeature {
7+
private command: vscode.Disposable;
8+
private languageClient: LanguageClient;
9+
10+
constructor() {
11+
this.command = vscode.commands.registerCommand('PowerShell.ApplyCodeActionEdits', (edit: any) => {
12+
var editor = Window.activeTextEditor;
13+
var filePath = editor.document.fileName;
14+
var workspaceEdit = new vscode.WorkspaceEdit();
15+
workspaceEdit.set(
16+
vscode.Uri.file(filePath),
17+
[
18+
new vscode.TextEdit(
19+
new vscode.Range(
20+
edit.StartLineNumber - 1,
21+
edit.StartColumnNumber - 1,
22+
edit.EndLineNumber - 1,
23+
edit.EndColumnNumber - 1),
24+
edit.Text)
25+
]);
26+
vscode.workspace.applyEdit(workspaceEdit);
27+
});
28+
}
29+
30+
public setLanguageClient(languageclient: LanguageClient) {
31+
this.languageClient = languageclient;
32+
}
33+
34+
public dispose() {
35+
this.command.dispose();
36+
}
2537
}

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ExpandAliasFeature } from './features/ExpandAlias';
1515
import { ShowHelpFeature } from './features/ShowOnlineHelp';
1616
import { FindModuleFeature } from './features/PowerShellFindModule';
1717
import { ExtensionCommandsFeature } from './features/ExtensionCommands';
18+
import { CodeActionsFeature } from './features/CodeActions';
1819

1920
// NOTE: We will need to find a better way to deal with the required
2021
// PS Editor Services version...
@@ -74,7 +75,8 @@ export function activate(context: vscode.ExtensionContext): void {
7475
new ExpandAliasFeature(),
7576
new ShowHelpFeature(),
7677
new FindModuleFeature(),
77-
new ExtensionCommandsFeature()
78+
new ExtensionCommandsFeature(),
79+
new CodeActionsFeature()
7880
];
7981

8082
sessionManager =

0 commit comments

Comments
 (0)