-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathCodeActions.ts
40 lines (32 loc) · 1.44 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import vscode = require("vscode");
import { ILogger } from "../logging";
export class CodeActionsFeature implements vscode.Disposable {
private command: vscode.Disposable;
constructor(private log: ILogger) {
// NOTE: While not exposed to the user via package.json, this is
// required as the server's code action sends across a command name.
//
// TODO: In the far future with LSP 3.19 the server can just set a URL
// and this can go away. See https://github.com/microsoft/language-server-protocol/issues/1548
this.command =
vscode.commands.registerCommand("PowerShell.ShowCodeActionDocumentation", async (ruleName: string) => {
await this.showRuleDocumentation(ruleName);
});
}
public dispose(): void {
this.command.dispose();
}
private 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));
}
}