@@ -27,12 +27,23 @@ export class GetCommandsFeature implements IFeature {
27
27
private command : vscode . Disposable ;
28
28
private languageClient : LanguageClient ;
29
29
private commandsExplorerProvider : CommandsExplorerProvider ;
30
+ private commandsExplorerTreeView : vscode . TreeView < Command > ;
30
31
31
32
constructor ( private log : Logger ) {
32
33
this . command = vscode . commands . registerCommand ( "PowerShell.RefreshCommandsExplorer" ,
33
34
( ) => this . CommandExplorerRefresh ( ) ) ;
34
35
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
+
36
47
vscode . commands . registerCommand ( "PowerShell.InsertCommand" , ( item ) => this . InsertCommand ( item ) ) ;
37
48
}
38
49
@@ -42,13 +53,14 @@ export class GetCommandsFeature implements IFeature {
42
53
43
54
public setLanguageClient ( languageclient : LanguageClient ) {
44
55
this . languageClient = languageclient ;
45
- vscode . commands . executeCommand ( "PowerShell.RefreshCommandsExplorer" ) ;
56
+ if ( this . commandsExplorerTreeView . visible ) {
57
+ vscode . commands . executeCommand ( "PowerShell.RefreshCommandsExplorer" ) ;
58
+ }
46
59
}
47
60
48
61
private CommandExplorerRefresh ( ) {
49
62
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` ) ;
52
64
return ;
53
65
}
54
66
this . languageClient . sendRequest ( GetCommandRequestType , "" ) . then ( ( result ) => {
0 commit comments