Skip to content

Commit 80c26b1

Browse files
authored
Merge pull request #344 from PowerShell/kapilmb/code-actions
Add quickfix functionality
2 parents 3944fa2 + 96c1d62 commit 80c26b1

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/features/CodeActions.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import vscode = require('vscode');
2+
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
3+
import Window = vscode.window;
4+
import { IFeature } from '../feature';
5+
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+
}
37+
}

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
'use strict';
66

77
import vscode = require('vscode');
8-
98
import { Logger, LogLevel } from './logging';
109
import { IFeature } from './feature';
1110
import { SessionManager } from './session';
@@ -16,6 +15,7 @@ import { ExpandAliasFeature } from './features/ExpandAlias';
1615
import { ShowHelpFeature } from './features/ShowOnlineHelp';
1716
import { FindModuleFeature } from './features/PowerShellFindModule';
1817
import { ExtensionCommandsFeature } from './features/ExtensionCommands';
18+
import { CodeActionsFeature } from './features/CodeActions';
1919

2020
// NOTE: We will need to find a better way to deal with the required
2121
// PS Editor Services version...
@@ -75,7 +75,8 @@ export function activate(context: vscode.ExtensionContext): void {
7575
new ExpandAliasFeature(),
7676
new ShowHelpFeature(),
7777
new FindModuleFeature(),
78-
new ExtensionCommandsFeature()
78+
new ExtensionCommandsFeature(),
79+
new CodeActionsFeature()
7980
];
8081

8182
sessionManager =

0 commit comments

Comments
 (0)