-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathCodeActions.ts
52 lines (43 loc) · 1.93 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
52
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
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) {
// TODO: What type is `edit`, what uses this, and is it working?
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.applyEditsCommand = vscode.commands.registerCommand("PowerShell.ApplyCodeActionEdits", async (edit: any) => {
await 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", async (ruleName: string) => {
await this.showRuleDocumentation(ruleName);
});
}
public dispose(): void {
this.applyEditsCommand.dispose();
this.showDocumentationCommand.dispose();
}
public async showRuleDocumentation(ruleId: string): Promise<void> {
const pssaDocBaseURL = "https://docs.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/";
if (!ruleId) {
this.log.writeWarning("Cannot show documentation for code action, no ruleName was supplied.");
return;
}
if (ruleId.startsWith("PS")) {
ruleId = ruleId.substr(2);
}
await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(pssaDocBaseURL + `${ruleId}`));
}
}