@@ -27,12 +27,23 @@ export class GetCommandsFeature implements IFeature {
2727 private command : vscode . Disposable ;
2828 private languageClient : LanguageClient ;
2929 private commandsExplorerProvider : CommandsExplorerProvider ;
30+ private commandsExplorerTreeView : vscode . TreeView < Command > ;
3031
3132 constructor ( private log : Logger ) {
3233 this . command = vscode . commands . registerCommand ( "PowerShell.RefreshCommandsExplorer" ,
3334 ( ) => this . CommandExplorerRefresh ( ) ) ;
3435 this . commandsExplorerProvider = new CommandsExplorerProvider ( ) ;
35- vscode . window . registerTreeDataProvider ( "PowerShellCommands" , this . commandsExplorerProvider ) ;
36+
37+ this . commandsExplorerTreeView = vscode . window . createTreeView < Command > ( "PowerShellCommands" ,
38+ { treeDataProvider : this . commandsExplorerProvider } ) ;
39+
40+ // Refresh the command explorer when the view is visible
41+ this . commandsExplorerTreeView . onDidChangeVisibility ( ( e ) => {
42+ if ( e . visible ) {
43+ this . CommandExplorerRefresh ( ) ;
44+ }
45+ } ) ;
46+
3647 vscode . commands . registerCommand ( "PowerShell.InsertCommand" , ( item ) => this . InsertCommand ( item ) ) ;
3748 }
3849
@@ -42,13 +53,14 @@ export class GetCommandsFeature implements IFeature {
4253
4354 public setLanguageClient ( languageclient : LanguageClient ) {
4455 this . languageClient = languageclient ;
45- vscode . commands . executeCommand ( "PowerShell.RefreshCommandsExplorer" ) ;
56+ if ( this . commandsExplorerTreeView . visible ) {
57+ vscode . commands . executeCommand ( "PowerShell.RefreshCommandsExplorer" ) ;
58+ }
4659 }
4760
4861 private CommandExplorerRefresh ( ) {
4962 if ( this . languageClient === undefined ) {
50- this . log . writeAndShowError ( `<${ GetCommandsFeature . name } >: ` +
51- "Unable to instantiate; language client undefined." ) ;
63+ this . log . writeVerbose ( `<${ GetCommandsFeature . name } >: Unable to send getCommand request` ) ;
5264 return ;
5365 }
5466 this . languageClient . sendRequest ( GetCommandRequestType , "" ) . then ( ( result ) => {
0 commit comments