forked from PowerShell/vscode-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerShellFindModule.ts
More file actions
70 lines (56 loc) · 2.64 KB
/
PowerShellFindModule.ts
File metadata and controls
70 lines (56 loc) · 2.64 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import vscode = require('vscode');
import Window = vscode.window;
import { IFeature } from '../feature';
import QuickPickItem = vscode.QuickPickItem;
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
export namespace FindModuleRequest {
export const type: RequestType<any, any, void> = { get method() { return 'powerShell/findModule'; } };
}
export namespace InstallModuleRequest {
export const type: RequestType<string, void, void> = { get method() { return 'powerShell/installModule'; } };
}
export class FindModuleFeature implements IFeature {
private command: vscode.Disposable;
private languageClient: LanguageClient;
constructor() {
this.command = vscode.commands.registerCommand('PowerShell.PowerShellFindModule', () => {
var items: QuickPickItem[] = [];
vscode.window.setStatusBarMessage(this.getCurrentTime() + " Initializing...");
this.languageClient.sendRequest(FindModuleRequest.type, null).then((modules) => {
for(var item in modules) {
items.push({ label: modules[item].name, description: modules[item].description });
};
vscode.window.setStatusBarMessage("");
Window.showQuickPick(items,{placeHolder: "Results: (" + modules.length + ")"}).then((selection) => {
if (!selection) { return; }
switch (selection.label) {
default :
var moduleName = selection.label;
//vscode.window.setStatusBarMessage("Installing PowerShell Module " + moduleName, 1500);
this.languageClient.sendRequest(InstallModuleRequest.type, moduleName);
}
});
});
});
}
public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}
public dispose() {
this.command.dispose();
}
private getCurrentTime() {
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeString = "" + ((hours > 12) ? hours - 12 : hours);
timeString += ((minutes < 10) ? ":0" : ":") + minutes;
timeString += ((seconds < 10) ? ":0" : ":") + seconds;
timeString += (hours >= 12) ? " PM" : " AM";
return timeString;
}
}