Skip to content

Commit 21c3f2b

Browse files
committed
Added Get-Installed and Expand-Alias
1 parent adfcf41 commit 21c3f2b

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,28 @@
4444
"key": "ctrl+f1",
4545
"when": "editorTextFocus && editorLangId == 'powershell'"
4646
},
47+
{
48+
"command": "PowerShell.ExpandAlias",
49+
"key": "ctrl+f5",
50+
"when": "editorTextFocus && editorLangId == 'powershell'"
51+
},
4752
{
4853
"command": "PowerShell.RunSelection",
4954
"key": "f8",
5055
"when": "editorTextFocus && editorLangId == 'powershell'"
5156
}
5257
],
53-
"commands": [
58+
"commands": [
59+
{
60+
"command": "PowerShell.ExpandAlias",
61+
"title": "Expand Alias",
62+
"category": "PowerShell"
63+
},
64+
{
65+
"command": "PowerShell.GetInstalledModule",
66+
"title": "Show Installed PowerShell Modules",
67+
"category": "PowerShell"
68+
},
5469
{
5570
"command": "PowerShell.FindModule",
5671
"title": "Install PowerShell Module",

src/features/ExpandAlias.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import vscode = require('vscode');
2+
import { LanguageClient } from 'vscode-languageclient';
3+
import { RequestType, NotificationType, ResponseError } from 'vscode-jsonrpc';
4+
import Window = vscode.window;
5+
6+
export namespace ExpandAliasRequest {
7+
export const type: RequestType<string, any, void> = { get method() { return 'powerShell/expandAlias'; } };
8+
}
9+
10+
export function registerExpandAliasCommand(client: LanguageClient): void {
11+
var disposable = vscode.commands.registerCommand('PowerShell.ExpandAlias', () => {
12+
13+
var editor = Window.activeTextEditor;
14+
var document = editor.document;
15+
var selection = editor.selection;
16+
var text = document.getText(selection);
17+
var range=new vscode.Range(selection.start.line, selection.start.character, selection.end.line, selection.end.character);
18+
19+
client.sendRequest(ExpandAliasRequest.type, text).then((result) => {
20+
editor.edit((editBuilder) => {
21+
editBuilder.replace(range, result);
22+
});
23+
});
24+
});
25+
}

src/features/GetInstalledModule.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import vscode = require('vscode');
2+
import { LanguageClient } from 'vscode-languageclient';
3+
import { RequestType, NotificationType, ResponseError } from 'vscode-jsonrpc';
4+
import Window = vscode.window;
5+
import QuickPickItem = vscode.QuickPickItem;
6+
7+
export namespace GetInstalledModuleRequest {
8+
export const type: RequestType<string, any, void> = { get method() { return 'powerShell/getInstalledModule'; } };
9+
}
10+
11+
export function registerGetInstalledModuleCommand(client: LanguageClient): void {
12+
var disposable = vscode.commands.registerCommand('PowerShell.GetInstalledModule', () => {
13+
14+
var items: QuickPickItem[] = [];
15+
16+
Window.showInformationMessage("Searching local PowerShell modules...");
17+
18+
client.sendRequest(GetInstalledModuleRequest.type, null).then((modules) => {
19+
console.log(modules.moduleList.length);
20+
for(var i=0 ; i < modules.moduleList.length; i++) {
21+
var module = modules.moduleList[i];
22+
items.push({ label: module.name, description: module.description });
23+
}
24+
25+
Window.showQuickPick(items).then((selection) => {
26+
switch (selection.label) {
27+
default :
28+
Window.showInformationMessage("Installing PowerShell Module " + selection.label);
29+
}
30+
});
31+
});
32+
33+
});
34+
}

src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { LanguageClient, LanguageClientOptions, Executable } from 'vscode-langua
1111

1212
import { RequestType, NotificationType, ResponseError } from 'vscode-jsonrpc';
1313
import { registerFindModuleCommand } from './features/FindModule';
14+
import { registerExpandAliasCommand } from './features/ExpandAlias';
15+
import { registerGetInstalledModuleCommand } from './features/GetInstalledModule';
1416
import { registerShowHelpCommand } from './features/ShowOnlineHelp';
1517
import { registerConsoleCommands } from './features/Console';
1618

@@ -97,6 +99,8 @@ export function activate(context: vscode.ExtensionContext): void {
9799

98100
// Register other features
99101
registerFindModuleCommand(client);
102+
registerExpandAliasCommand(client);
103+
registerGetInstalledModuleCommand(client);
100104
registerShowHelpCommand(client);
101105
registerConsoleCommands(client);
102106
}

0 commit comments

Comments
 (0)