-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathShowHelp.ts
44 lines (34 loc) · 1.4 KB
/
ShowHelp.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import vscode = require("vscode");
import { NotificationType } from "vscode-languageclient";
import { LanguageClientConsumer } from "../languageClientConsumer";
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface IShowHelpNotificationArguments {
}
export const ShowHelpNotificationType =
new NotificationType<IShowHelpNotificationArguments>("powerShell/showHelp");
export class ShowHelpFeature extends LanguageClientConsumer {
private command: vscode.Disposable;
constructor() {
super();
this.command = vscode.commands.registerCommand("PowerShell.ShowHelp", async (item?) => {
if (!item?.Name) {
const editor = vscode.window.activeTextEditor;
if (editor === undefined) {
return;
}
const selection = editor.selection;
const doc = editor.document;
const cwr = doc.getWordRangeAtPosition(selection.active);
const text = doc.getText(cwr);
await this.languageClient?.sendNotification(ShowHelpNotificationType, { text });
} else {
await this.languageClient?.sendNotification(ShowHelpNotificationType, { text: item.Name });
}
});
}
public dispose() {
this.command.dispose();
}
}