From 64894e5702a3c17e3eb288252691632b56c0ba7a Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 10 Jan 2019 11:28:13 -0800 Subject: [PATCH 1/2] refresh on visible --- src/features/GetCommands.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 0821a65a2d..006ba9e6fa 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -27,12 +27,23 @@ export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; private languageClient: LanguageClient; private commandsExplorerProvider: CommandsExplorerProvider; + private commandsExplorerTreeView: vscode.TreeView; constructor(private log: Logger) { this.command = vscode.commands.registerCommand("PowerShell.RefreshCommandsExplorer", () => this.CommandExplorerRefresh()); this.commandsExplorerProvider = new CommandsExplorerProvider(); - vscode.window.registerTreeDataProvider("PowerShellCommands", this.commandsExplorerProvider); + + this.commandsExplorerTreeView = vscode.window.createTreeView("PowerShellCommands", + { treeDataProvider: this.commandsExplorerProvider }); + + // Refresh the command explorer when the view is visible + this.commandsExplorerTreeView.onDidChangeVisibility( (e) => { + if (e.visible) { + this.CommandExplorerRefresh(); + } + }); + vscode.commands.registerCommand("PowerShell.InsertCommand", (item) => this.InsertCommand(item)); } @@ -42,12 +53,14 @@ export class GetCommandsFeature implements IFeature { public setLanguageClient(languageclient: LanguageClient) { this.languageClient = languageclient; - vscode.commands.executeCommand("PowerShell.RefreshCommandsExplorer"); + if (this.commandsExplorerTreeView.visible) { + vscode.commands.executeCommand("PowerShell.RefreshCommandsExplorer"); + } } private CommandExplorerRefresh() { if (this.languageClient === undefined) { - this.log.writeAndShowError(`<${GetCommandsFeature.name}>: ` + + this.log.writeVerbose(`<${GetCommandsFeature.name}>: ` + "Unable to instantiate; language client undefined."); return; } From 345dad4fe60a2c410f312d4867f705f52bb1b9a6 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Thu, 10 Jan 2019 23:24:23 -0800 Subject: [PATCH 2/2] Address feedback --- src/features/GetCommands.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 006ba9e6fa..0a269f3d3a 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -60,8 +60,7 @@ export class GetCommandsFeature implements IFeature { private CommandExplorerRefresh() { if (this.languageClient === undefined) { - this.log.writeVerbose(`<${GetCommandsFeature.name}>: ` + - "Unable to instantiate; language client undefined."); + this.log.writeVerbose(`<${GetCommandsFeature.name}>: Unable to send getCommand request`); return; } this.languageClient.sendRequest(GetCommandRequestType, "").then((result) => {