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+ }
0 commit comments