Skip to content

Commit 2371e04

Browse files
committed
Merge pull request PowerShell#74 from PowerShell/spike-dcf-psgallery
Add support for finding and installing modules from the PowerShell Gallery
2 parents 6651a20 + d7816f2 commit 2371e04

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

package.json

+11
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@
6363
"command": "PowerShell.OpenInISE",
6464
"key": "ctrl+alt+i",
6565
"when": "editorTextFocus && editorLangId == 'powershell'"
66+
},
67+
{
68+
"command": "PowerShell.PowerShellFindModule",
69+
"key": "ctrl+K ctrl+f",
70+
"when": "editorTextFocus && editorLangId == 'powershell'"
6671
}
72+
6773
],
6874
"commands": [
6975
{
@@ -85,6 +91,11 @@
8591
"command": "PowerShell.OpenInISE",
8692
"title": "Open current file in PowerShell ISE",
8793
"category": "PowerShell"
94+
},
95+
{
96+
"command": "PowerShell.PowerShellFindModule",
97+
"title": "Find/Install PowerShell modules from the gallery",
98+
"category": "PowerShell"
8899
}
89100
],
90101
"snippets": [

src/features/PowerShellFindModule.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import vscode = require('vscode');
2+
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
3+
import Window = vscode.window;
4+
import QuickPickItem = vscode.QuickPickItem;
5+
6+
export namespace FindModuleRequest {
7+
export const type: RequestType<any, any, void> = { get method() { return 'powerShell/findModule'; } };
8+
}
9+
10+
export namespace InstallModuleRequest {
11+
export const type: RequestType<string, void, void> = { get method() { return 'powerShell/installModule'; } };
12+
}
13+
14+
function GetCurrentTime() {
15+
16+
var timeNow = new Date();
17+
var hours = timeNow.getHours();
18+
var minutes = timeNow.getMinutes();
19+
var seconds = timeNow.getSeconds();
20+
21+
var timeString = "" + ((hours > 12) ? hours - 12 : hours);
22+
timeString += ((minutes < 10) ? ":0" : ":") + minutes;
23+
timeString += ((seconds < 10) ? ":0" : ":") + seconds;
24+
timeString += (hours >= 12) ? " PM" : " AM";
25+
26+
return timeString;
27+
}
28+
29+
export function registerPowerShellFindModuleCommand(client: LanguageClient): void {
30+
var disposable = vscode.commands.registerCommand('PowerShell.PowerShellFindModule', () => {
31+
var items: QuickPickItem[] = [];
32+
33+
vscode.window.setStatusBarMessage(GetCurrentTime() + " Initializing...");
34+
client.sendRequest(FindModuleRequest.type, null).then((modules) => {
35+
for(var item in modules) {
36+
items.push({ label: modules[item].name, description: modules[item].description });
37+
};
38+
39+
vscode.window.setStatusBarMessage("");
40+
Window.showQuickPick(items,{placeHolder: "Results: (" + modules.length + ")"}).then((selection) => {
41+
if (!selection) { return; }
42+
switch (selection.label) {
43+
default :
44+
var moduleName = selection.label;
45+
//vscode.window.setStatusBarMessage("Installing PowerShell Module " + moduleName, 1500);
46+
client.sendRequest(InstallModuleRequest.type, moduleName);
47+
}
48+
});
49+
});
50+
});
51+
}

src/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { LanguageClient, LanguageClientOptions, Executable, RequestType, Notific
1212
import { registerExpandAliasCommand } from './features/ExpandAlias';
1313
import { registerShowHelpCommand } from './features/ShowOnlineHelp';
1414
import { registerOpenInISECommand } from './features/OpenInISE';
15+
import { registerPowerShellFindModuleCommand } from './features/PowerShellFindModule';
1516
import { registerConsoleCommands } from './features/Console';
1617

1718
var languageServerClient: LanguageClient = undefined;
@@ -101,6 +102,7 @@ export function activate(context: vscode.ExtensionContext): void {
101102
registerShowHelpCommand(languageServerClient);
102103
registerConsoleCommands(languageServerClient);
103104
registerOpenInISECommand();
105+
registerPowerShellFindModuleCommand(languageServerClient);
104106
}
105107

106108
export function deactivate(): void {

0 commit comments

Comments
 (0)