forked from PowerShell/vscode-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeActions.ts
51 lines (42 loc) · 1.84 KB
/
CodeActions.ts
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
46
47
48
49
50
51
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import vscode = require("vscode");
import Window = vscode.window;
import { ILogger } from "../logging";
export class CodeActionsFeature implements vscode.Disposable {
private applyEditsCommand: vscode.Disposable;
private showDocumentationCommand: vscode.Disposable;
constructor(private log: ILogger) {
this.applyEditsCommand = vscode.commands.registerCommand("PowerShell.ApplyCodeActionEdits", (edit: any) => {
Window.activeTextEditor.edit((editBuilder) => {
editBuilder.replace(
new vscode.Range(
edit.StartLineNumber - 1,
edit.StartColumnNumber - 1,
edit.EndLineNumber - 1,
edit.EndColumnNumber - 1),
edit.Text);
});
});
this.showDocumentationCommand =
vscode.commands.registerCommand("PowerShell.ShowCodeActionDocumentation", (ruleName: any) => {
this.showRuleDocumentation(ruleName);
});
}
public dispose() {
this.applyEditsCommand.dispose();
this.showDocumentationCommand.dispose();
}
public showRuleDocumentation(ruleId: string) {
const pssaDocBaseURL = "https://github.com/PowerShell/PSScriptAnalyzer/blob/master/RuleDocumentation";
if (!ruleId) {
this.log.writeWarning("Cannot show documentation for code action, no ruleName was supplied.");
return;
}
if (ruleId.startsWith("PS")) {
ruleId = ruleId.substr(2);
}
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(pssaDocBaseURL + `/${ruleId}.md`));
}
}