Skip to content

Commit 1f17832

Browse files
committed
Refine online help feature
This change gives a namespace to the 'showonlinehelp' message type, making it 'powerShell/showOnlineHelp'. Also moves registration for the command into the feature file.
1 parent e61743d commit 1f17832

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ that VS Code provides.
1313
- Go to Definition of cmdlets and variables
1414
- Find References of cmdlets and variables
1515
- Document and workspace symbol discovery
16+
- Launch online help for the symbol under the cursor using `Ctrl+F1`
1617
- Local script debugging and basic interactive console support!
1718

1819
## Example Scripts

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@
4343
"key": "ctrl+f1",
4444
"when": "editorTextFocus"
4545
}],
46-
"commands": [{
47-
"command": "PowerShell.OnlineHelp",
48-
"title": "Get online help for command",
49-
"category": "PowerShell"
50-
}],
46+
"commands": [{
47+
"command": "PowerShell.OnlineHelp",
48+
"title": "Get online help for command",
49+
"category": "PowerShell"
50+
}],
5151
"languages": [{
5252
"id": "PowerShell",
5353
"extensions": [ ".ps1", ".psm1", ".psd1", ".pssc", ".psrc" ],

src/features/ShowOnlineHelp.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
import vscode = require('vscode');
2+
import { LanguageClient } from 'vscode-languageclient';
13
import { RequestType, NotificationType, ResponseError } from 'vscode-jsonrpc';
24

35
export namespace ShowOnlineHelpRequest {
4-
export const type: RequestType<string, void, void> = { get method() { return 'showonlinehelp'; } };
6+
export const type: RequestType<string, void, void> = { get method() { return 'powerShell/showOnlineHelp'; } };
7+
}
8+
9+
export function registerShowHelpCommand(client: LanguageClient): void {
10+
var disposable = vscode.commands.registerCommand('PowerShell.OnlineHelp', () => {
11+
12+
const editor = vscode.window.activeTextEditor;
13+
14+
var selection = editor.selection;
15+
var doc = editor.document;
16+
var cwr = doc.getWordRangeAtPosition(selection.active)
17+
var text = doc.getText(cwr);
18+
19+
client.sendRequest(ShowOnlineHelpRequest.type, text);
20+
});
521
}

src/main.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import settingsManager = require('./settings');
1010
import { LanguageClient, LanguageClientOptions, Executable } from 'vscode-languageclient';
1111

1212
import { RequestType, NotificationType, ResponseError } from 'vscode-jsonrpc';
13-
import powerShellMessage = require('./features/ShowOnlineHelp');
13+
import { registerShowHelpCommand } from './features/ShowOnlineHelp';
1414

1515
export function activate(context: vscode.ExtensionContext): void {
1616

@@ -57,7 +57,6 @@ export function activate(context: vscode.ExtensionContext): void {
5757
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
5858
]
5959
}
60-
6160
});
6261

6362
let args = [];
@@ -94,17 +93,8 @@ export function activate(context: vscode.ExtensionContext): void {
9493

9594
client.start();
9695

97-
var disposable = vscode.commands.registerCommand('PowerShell.OnlineHelp', () => {
98-
99-
const editor = vscode.window.activeTextEditor;
100-
101-
var selection = editor.selection;
102-
var doc = editor.document;
103-
var cwr = doc.getWordRangeAtPosition(selection.active)
104-
var text = doc.getText(cwr);
105-
106-
client.sendRequest(powerShellMessage.ShowOnlineHelpRequest.type, text);
107-
});
96+
// Register other features
97+
registerShowHelpCommand(client);
10898
}
10999

110100
function resolveLanguageServerPath(settings: settingsManager.ISettings) : string {

0 commit comments

Comments
 (0)