Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 51f7652

Browse files
Add CodeAction support to show PSSA rule documentation (#1600)
This corresponds to PSES PR: PowerShell/PowerShellEditorServices#789 Currently this points to the PSSA development branch. Maybe that should point to the master branch. Could be a setting I suppose but that seems like overkill.
1 parent 452d5ac commit 51f7652

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

‎src/features/CodeActions.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import vscode = require("vscode");
66
import { LanguageClient } from "vscode-languageclient";
77
import Window = vscode.window;
88
import { IFeature } from "../feature";
9+
import { ILogger } from "../logging";
910

1011
export class CodeActionsFeature implements IFeature {
11-
private command: vscode.Disposable;
12+
private applyEditsCommand: vscode.Disposable;
13+
private showDocumentationCommand: vscode.Disposable;
1214
private languageClient: LanguageClient;
1315

14-
constructor() {
15-
this.command = vscode.commands.registerCommand("PowerShell.ApplyCodeActionEdits", (edit: any) => {
16+
constructor(privatelog: ILogger) {
17+
this.applyEditsCommand = vscode.commands.registerCommand("PowerShell.ApplyCodeActionEdits", (edit: any) => {
1618
Window.activeTextEditor.edit((editBuilder) => {
1719
editBuilder.replace(
1820
new vscode.Range(
@@ -23,13 +25,34 @@ export class CodeActionsFeature implements IFeature {
2325
edit.Text);
2426
});
2527
});
28+
29+
this.showDocumentationCommand =
30+
vscode.commands.registerCommand("PowerShell.ShowCodeActionDocumentation", (ruleName: any) => {
31+
this.showRuleDocumentation(ruleName);
32+
});
2633
}
2734

2835
public dispose() {
29-
this.command.dispose();
36+
this.applyEditsCommand.dispose();
37+
this.showDocumentationCommand.dispose();
3038
}
3139

3240
public setLanguageClient(languageclient: LanguageClient) {
3341
this.languageClient = languageclient;
3442
}
43+
44+
public showRuleDocumentation(ruleId: string) {
45+
const pssaDocBaseURL = "https://github.com/PowerShell/PSScriptAnalyzer/blob/development/RuleDocumentation";
46+
47+
if (!ruleId) {
48+
this.log.writeWarning("Cannot show documentation for code action, no ruleName was supplied.");
49+
return;
50+
}
51+
52+
if (ruleId.startsWith("PS")) {
53+
ruleId = ruleId.substr(2);
54+
}
55+
56+
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(pssaDocBaseURL + `/${ruleId}.md`));
57+
}
3558
}

‎src/main.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function activate(context: vscode.ExtensionContext): void {
128128
new PesterTestsFeature(sessionManager),
129129
new ExtensionCommandsFeature(logger),
130130
new SelectPSSARulesFeature(logger),
131-
new CodeActionsFeature(),
131+
new CodeActionsFeature(logger),
132132
new NewFileOrProjectFeature(),
133133
new DocumentFormatterFeature(logger, documentSelector),
134134
new RemoteFilesFeature(),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /