From 7b5a4eec2ae122543146d61068e06956a88d50ef Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 4 Jul 2018 06:28:12 -0700 Subject: [PATCH 01/29] Implement TreeView First pass at bringing a TreeView into vscode-powershell. Built currently failing on unrelated code... --- package.json | 19 ++++++++++++++++++- src/main.ts | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0104f56f5a..7558690918 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,23 @@ "test": "node ./node_modules/vscode/bin/test" }, "contributes": { + "viewsContainers": { + "activitybar": [ + { + "id": "command-explorer", + "title": "Command Explorer", + "icon": "media/dep.svg" + } + ] + }, + "views": { + "function-explorer": [ + { + "id": "commands", + "name": "PowerShell Commands" + } + ] + }, "keybindings": [ { "command": "PowerShell.ShowHelp", @@ -602,4 +619,4 @@ ] }, "private": true -} +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 86482a05af..e9628eb752 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,7 @@ import vscode = require("vscode"); import { DocumentSelector } from "vscode-languageclient"; import { IFeature } from "./feature"; import { CodeActionsFeature } from "./features/CodeActions"; +import { CommandExplorerProvider } from "./features/CommandExplorer"; import { ConsoleFeature } from "./features/Console"; import { CustomViewsFeature } from "./features/CustomViews"; import { DebugSessionFeature } from "./features/DebugSession"; @@ -41,6 +42,7 @@ const requiredEditorServicesVersion = "1.9.1"; let logger: Logger; let sessionManager: SessionManager; let extensionFeatures: IFeature[] = []; +let commandExplorer: CommandExplorerProvider; const documentSelector: DocumentSelector = [ { language: "powershell", scheme: "file" }, @@ -140,6 +142,8 @@ export function activate(context: vscode.ExtensionContext): void { new FoldingFeature(logger, documentSelector), ]; + commandExplorer = new CommandExplorerProvider(); + vscode.window.registerTreeDataProvider("functions", commandExplorer); sessionManager.setExtensionFeatures(extensionFeatures); if (extensionSettings.startAutomatically) { From acfbfbf4e284a4669ab1808b630b75cb37d30723 Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 4 Jul 2018 06:28:26 -0700 Subject: [PATCH 02/29] Implement TreeView First pass at bringing a TreeView into vscode-powershell. Built currently failing on unrelated code... --- src/features/CommandExplorer.ts | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/features/CommandExplorer.ts diff --git a/src/features/CommandExplorer.ts b/src/features/CommandExplorer.ts new file mode 100644 index 0000000000..88f01b6c75 --- /dev/null +++ b/src/features/CommandExplorer.ts @@ -0,0 +1,47 @@ +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ + +"use strict"; + +import * as fs from "fs"; +import * as vscode from "vscode"; + +export class CommandExplorerProvider implements vscode.TreeDataProvider { + public readonly didChangeTreeDataEvent: vscode.Event; + private didChangeTreeData: vscode.EventEmitter; + + constructor() { + this.didChangeTreeData = new vscode.EventEmitter(); + this.didChangeTreeDataEvent = this.didChangeTreeData.event; + } + + public refresh(): void { + this.didChangeTreeData.fire(); + } + + public getTreeItem(element: Command): vscode.TreeItem { + return element; + } + + public getChildren(element?: Command): Thenable { + return Promise.resolve(this.getCommandsFromJson()); + } + + public getCommandsFromJson(): Command[] { + const commandsJson = JSON.parse(fs.readFileSync("e:\\temp\\commands.json", "utf-8")); + + const toCommand = (command: any): Command => { + return new Command(command.ModuleName + "\\" + command.Name, vscode.TreeItemCollapsibleState.None); }; + const commands = commandsJson.map(toCommand); + return commands; + } + +} + +class Command extends vscode.TreeItem { + constructor(public readonly label: string, + public readonly collapsibleState: vscode.TreeItemCollapsibleState) { + super(label, collapsibleState); + } +} From 9599d8651469cffb1512d1e722a0f90798ff9040 Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 4 Jul 2018 06:54:38 -0700 Subject: [PATCH 03/29] Missed some variable names. Updated from previous name incarnation.. --- package.json | 4 ++-- src/main.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7558690918..53df3a2e46 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ ] }, "views": { - "function-explorer": [ + "command-explorer": [ { "id": "commands", "name": "PowerShell Commands" @@ -619,4 +619,4 @@ ] }, "private": true -} \ No newline at end of file +} diff --git a/src/main.ts b/src/main.ts index e9628eb752..7ee7ab8126 100644 --- a/src/main.ts +++ b/src/main.ts @@ -143,7 +143,7 @@ export function activate(context: vscode.ExtensionContext): void { ]; commandExplorer = new CommandExplorerProvider(); - vscode.window.registerTreeDataProvider("functions", commandExplorer); + vscode.window.registerTreeDataProvider("commands", commandExplorer); sessionManager.setExtensionFeatures(extensionFeatures); if (extensionSettings.startAutomatically) { From 406888f2d53c1fab21e2ec0f9e7fbf6da21ed328 Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 4 Jul 2018 06:56:53 -0700 Subject: [PATCH 04/29] Adding svg for activitybar. Require an svg for the activity bar. Taken from https://github.com/Microsoft/vscode-extension-samples/tree/master/tree-view-sample/media (MIT Licensed I think...) --- media/dep.svg | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 media/dep.svg diff --git a/media/dep.svg b/media/dep.svg new file mode 100644 index 0000000000..53e5be5bdc --- /dev/null +++ b/media/dep.svg @@ -0,0 +1,14 @@ + + + + Slice + Created with Sketch. + + + + + + + + + From 874601d32bb79cecf2e27a1d784bb1b914b63fcd Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 4 Jul 2018 21:19:24 -0700 Subject: [PATCH 05/29] Added a PowerShell SVG. Taken from gist: https://gist.github.com/Xainey/d5bde7d01dcbac51ac951810e94313aa?short_path=ec01c8c --- media/PowerShell.svg | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 media/PowerShell.svg diff --git a/media/PowerShell.svg b/media/PowerShell.svg new file mode 100644 index 0000000000..ec01c8cb51 --- /dev/null +++ b/media/PowerShell.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + \ No newline at end of file From aa8d4b4d3189e99d0082ec39eb24b040b27fc40f Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 5 Jul 2018 07:16:08 -0700 Subject: [PATCH 06/29] First Attempt to call to PSES --- package.json | 5 +++++ src/features/CommandExplorer.ts | 4 +++- src/features/GetCommands.ts | 37 +++++++++++++++++++++++++++++++++ src/main.ts | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/features/GetCommands.ts diff --git a/package.json b/package.json index 53df3a2e46..5d8eff36c0 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,11 @@ "title": "Expand Alias", "category": "PowerShell" }, + { + "command": "PowerShell.GetCommands", + "title": "Get Commands", + "category": "PowerShell" + }, { "command": "PowerShell.OnlineHelp", "title": "Get Online Help for Command (Deprecated)", diff --git a/src/features/CommandExplorer.ts b/src/features/CommandExplorer.ts index 88f01b6c75..7f00e53e86 100644 --- a/src/features/CommandExplorer.ts +++ b/src/features/CommandExplorer.ts @@ -6,10 +6,12 @@ import * as fs from "fs"; import * as vscode from "vscode"; +import * as utils from "../utils"; export class CommandExplorerProvider implements vscode.TreeDataProvider { public readonly didChangeTreeDataEvent: vscode.Event; private didChangeTreeData: vscode.EventEmitter; + private test: any = utils; constructor() { this.didChangeTreeData = new vscode.EventEmitter(); @@ -30,7 +32,7 @@ export class CommandExplorerProvider implements vscode.TreeDataProvider public getCommandsFromJson(): Command[] { const commandsJson = JSON.parse(fs.readFileSync("e:\\temp\\commands.json", "utf-8")); - + vscode.commands.executeCommand("PowerShell.GetCommands"); const toCommand = (command: any): Command => { return new Command(command.ModuleName + "\\" + command.Name, vscode.TreeItemCollapsibleState.None); }; const commands = commandsJson.map(toCommand); diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts new file mode 100644 index 0000000000..a07249693d --- /dev/null +++ b/src/features/GetCommands.ts @@ -0,0 +1,37 @@ +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ + +import * as vscode from "vscode"; +import { LanguageClient, RequestType } from "vscode-languageclient"; +import { IFeature } from "../feature"; + +export const GetCommandsRequestType = new RequestType("powershell/expandAlias"); + +export class GetCommandsFeature implements IFeature { + private command: vscode.Disposable; + private languageClient: LanguageClient; + + constructor() { + this.command = vscode.commands.registerCommand("PowerShell.GetCommands", () => { + if (this.languageClient === undefined) { + // We be screwed + return; + } + vscode.window.showInformationMessage("Before calling PSES"); + this.languageClient.sendRequest(GetCommandsRequestType, "gci").then((result) => { + vscode.window.showInformationMessage("In the Promise from calling PSES") + vscode.window.showInformationMessage(result); + }); + vscode.window.showInformationMessage("After calling PSES"); + }); + } + + public dispose() { + this.command.dispose(); + } + + public setLanguageClient(languageclient: LanguageClient) { + this.languageClient = languageclient; + } +} diff --git a/src/main.ts b/src/main.ts index 7ee7ab8126..ee89e3e6aa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,7 @@ import { ExtensionCommandsFeature } from "./features/ExtensionCommands"; import { FindModuleFeature } from "./features/FindModule"; import { FoldingFeature } from "./features/Folding"; import { GenerateBugReportFeature } from "./features/GenerateBugReport"; +import { GetCommandsFeature } from "./features/GetCommands"; import { HelpCompletionFeature } from "./features/HelpCompletion"; import { NewFileOrProjectFeature } from "./features/NewFileOrProject"; import { OpenInISEFeature } from "./features/OpenInISE"; @@ -125,6 +126,7 @@ export function activate(context: vscode.ExtensionContext): void { new OpenInISEFeature(), new GenerateBugReportFeature(sessionManager), new ExpandAliasFeature(logger), + new GetCommandsFeature(), new ShowHelpFeature(logger), new FindModuleFeature(), new PesterTestsFeature(sessionManager), From ba75663e9ccea764ed58b98e39eeaa7ae74d26d6 Mon Sep 17 00:00:00 2001 From: corbob Date: Fri, 6 Jul 2018 07:09:11 -0700 Subject: [PATCH 07/29] Get data from PSES PSES isn't returning a string. Make sure we're expecting it. Allowing for console.log for debugging. These will all be removed prior to shipping. --- src/features/GetCommands.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index a07249693d..cc473dfdb0 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -1,12 +1,12 @@ /*--------------------------------------------------------- * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ - +// tslint:disable:no-console import * as vscode from "vscode"; import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; -export const GetCommandsRequestType = new RequestType("powershell/expandAlias"); +export const GetCommandsRequestType = new RequestType("powerShell/getCommands"); export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; @@ -18,12 +18,11 @@ export class GetCommandsFeature implements IFeature { // We be screwed return; } - vscode.window.showInformationMessage("Before calling PSES"); - this.languageClient.sendRequest(GetCommandsRequestType, "gci").then((result) => { - vscode.window.showInformationMessage("In the Promise from calling PSES") - vscode.window.showInformationMessage(result); + console.log("Before calling PSES"); + this.languageClient.sendRequest(GetCommandsRequestType, "").then((result) => { + console.log(result); }); - vscode.window.showInformationMessage("After calling PSES"); + console.log("After calling PSES"); }); } From 338da93acd8eb02ab5c4a141842ca87a46b4c91d Mon Sep 17 00:00:00 2001 From: corbob Date: Sat, 7 Jul 2018 16:26:36 -0700 Subject: [PATCH 08/29] Refactoring code --- src/features/CommandExplorer.ts | 49 --------------------------------- src/features/GetCommands.ts | 38 +++++++++++++++++++++++++ src/main.ts | 5 ---- 3 files changed, 38 insertions(+), 54 deletions(-) delete mode 100644 src/features/CommandExplorer.ts diff --git a/src/features/CommandExplorer.ts b/src/features/CommandExplorer.ts deleted file mode 100644 index 7f00e53e86..0000000000 --- a/src/features/CommandExplorer.ts +++ /dev/null @@ -1,49 +0,0 @@ -/*--------------------------------------------------------- - * Copyright (C) Microsoft Corporation. All rights reserved. - *--------------------------------------------------------*/ - -"use strict"; - -import * as fs from "fs"; -import * as vscode from "vscode"; -import * as utils from "../utils"; - -export class CommandExplorerProvider implements vscode.TreeDataProvider { - public readonly didChangeTreeDataEvent: vscode.Event; - private didChangeTreeData: vscode.EventEmitter; - private test: any = utils; - - constructor() { - this.didChangeTreeData = new vscode.EventEmitter(); - this.didChangeTreeDataEvent = this.didChangeTreeData.event; - } - - public refresh(): void { - this.didChangeTreeData.fire(); - } - - public getTreeItem(element: Command): vscode.TreeItem { - return element; - } - - public getChildren(element?: Command): Thenable { - return Promise.resolve(this.getCommandsFromJson()); - } - - public getCommandsFromJson(): Command[] { - const commandsJson = JSON.parse(fs.readFileSync("e:\\temp\\commands.json", "utf-8")); - vscode.commands.executeCommand("PowerShell.GetCommands"); - const toCommand = (command: any): Command => { - return new Command(command.ModuleName + "\\" + command.Name, vscode.TreeItemCollapsibleState.None); }; - const commands = commandsJson.map(toCommand); - return commands; - } - -} - -class Command extends vscode.TreeItem { - constructor(public readonly label: string, - public readonly collapsibleState: vscode.TreeItemCollapsibleState) { - super(label, collapsibleState); - } -} diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index cc473dfdb0..36f9657165 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -34,3 +34,41 @@ export class GetCommandsFeature implements IFeature { this.languageClient = languageclient; } } + +class CommandExplorerProvider implements vscode.TreeDataProvider { + public readonly didChangeTreeDataEvent: vscode.Event; + private didChangeTreeData: vscode.EventEmitter; + + constructor() { + this.didChangeTreeData = new vscode.EventEmitter(); + this.didChangeTreeDataEvent = this.didChangeTreeData.event; + } + + public refresh(): void { + this.didChangeTreeData.fire(); + } + + public getTreeItem(element: Command): vscode.TreeItem { + return element; + } + + public getChildren(element?: Command): Thenable { + return Promise.resolve(this.getCommandsFromJson()); + } + + public getCommandsFromJson(): Command[] { + const commandsJson = JSON.parse(fs.readFileSync("e:\\temp\\commands.json", "utf-8")); + // vscode.commands.executeCommand("PowerShell.GetCommands"); + const toCommand = (command: any): Command => { + return new Command(command.ModuleName + "\\" + command.Name); }; + const commands = commandsJson.map(toCommand); + return commands; + } + +} + +class Command extends vscode.TreeItem { + constructor(public readonly label: string) { + super(label); + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index ee89e3e6aa..715def3028 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,6 @@ import vscode = require("vscode"); import { DocumentSelector } from "vscode-languageclient"; import { IFeature } from "./feature"; import { CodeActionsFeature } from "./features/CodeActions"; -import { CommandExplorerProvider } from "./features/CommandExplorer"; import { ConsoleFeature } from "./features/Console"; import { CustomViewsFeature } from "./features/CustomViews"; import { DebugSessionFeature } from "./features/DebugSession"; @@ -43,7 +42,6 @@ const requiredEditorServicesVersion = "1.9.1"; let logger: Logger; let sessionManager: SessionManager; let extensionFeatures: IFeature[] = []; -let commandExplorer: CommandExplorerProvider; const documentSelector: DocumentSelector = [ { language: "powershell", scheme: "file" }, @@ -143,9 +141,6 @@ export function activate(context: vscode.ExtensionContext): void { new CustomViewsFeature(), new FoldingFeature(logger, documentSelector), ]; - - commandExplorer = new CommandExplorerProvider(); - vscode.window.registerTreeDataProvider("commands", commandExplorer); sessionManager.setExtensionFeatures(extensionFeatures); if (extensionSettings.startAutomatically) { From bcd569b66caa4e9453a356011f5d3e4aef9533c5 Mon Sep 17 00:00:00 2001 From: corbob Date: Sun, 8 Jul 2018 07:04:15 -0700 Subject: [PATCH 09/29] Pulling live data. Unable to currently update the list. If you run PowerShell.GetCommands prior to opening the treeview, it is populated with your commands. Need to get it to update. --- src/features/GetCommands.ts | 101 +++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 18 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 36f9657165..b16087242a 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -11,6 +11,7 @@ export const GetCommandsRequestType = new RequestType("pow export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; private languageClient: LanguageClient; + private commandsExplorerProvider: CommandsExplorerProvider; constructor() { this.command = vscode.commands.registerCommand("PowerShell.GetCommands", () => { @@ -18,12 +19,25 @@ export class GetCommandsFeature implements IFeature { // We be screwed return; } - console.log("Before calling PSES"); this.languageClient.sendRequest(GetCommandsRequestType, "").then((result) => { - console.log(result); + const toCommand = (command: any): Command => { + return new Command( + command.name, + command.moduleName, + command.defaultParameterSet, + command.parameterSets, + command.parameters, + ); + }; + this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); + this.commandsExplorerProvider.refresh(); }); - console.log("After calling PSES"); }); + this.commandsExplorerProvider = new CommandsExplorerProvider(); + vscode.window.registerTreeDataProvider("commands", this.commandsExplorerProvider); + vscode.commands.registerCommand( + "PowerShell.refreshCommandsExplorer", + () => this.commandsExplorerProvider.refresh()); } public dispose() { @@ -35,12 +49,12 @@ export class GetCommandsFeature implements IFeature { } } -class CommandExplorerProvider implements vscode.TreeDataProvider { - public readonly didChangeTreeDataEvent: vscode.Event; - private didChangeTreeData: vscode.EventEmitter; +class CommandsExplorerProvider implements vscode.TreeDataProvider { + public readonly didChangeTreeDataEvent: vscode.Event; + public powerShellCommands: Command[]; + private didChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); constructor() { - this.didChangeTreeData = new vscode.EventEmitter(); this.didChangeTreeDataEvent = this.didChangeTreeData.event; } @@ -52,23 +66,74 @@ class CommandExplorerProvider implements vscode.TreeDataProvider { return element; } - public getChildren(element?: Command): Thenable { + public async getChildren(element?: Command): Promise { return Promise.resolve(this.getCommandsFromJson()); } - public getCommandsFromJson(): Command[] { - const commandsJson = JSON.parse(fs.readFileSync("e:\\temp\\commands.json", "utf-8")); - // vscode.commands.executeCommand("PowerShell.GetCommands"); - const toCommand = (command: any): Command => { - return new Command(command.ModuleName + "\\" + command.Name); }; - const commands = commandsJson.map(toCommand); - return commands; + public getCommandsFromJson(element?: Command): Command[] { + if (undefined !== this.powerShellCommands) { + return this.powerShellCommands; + } + return []; } } class Command extends vscode.TreeItem { - constructor(public readonly label: string) { - super(label); + constructor( + public readonly Name: string, + public readonly ModuleName: string, + public readonly defaultParameterSet: string, + public readonly ParameterSets: object, + public readonly Parameters: object, + public readonly collapsibleState = vscode.TreeItemCollapsibleState.None, + ) { + super(Name, collapsibleState); } -} \ No newline at end of file + + public getTreeItem(): vscode.TreeItem { + return { + label: this.label, + collapsibleState: this.collapsibleState, + }; + } + + public async getChildren(element): Promise { + return []; + } +} + +class CommandNode extends Command { + public populatedCommands: Command[]; + constructor( + public eventEmitter: vscode.EventEmitter, + public readonly Name: string = "PowerShell", + public readonly ModuleName: string = "PowerShell", + public readonly defaultParameterSet: string = "", + public readonly ParameterSets: object = {}, + public readonly Parameters: object = {}, + public readonly collapsibleState = vscode.TreeItemCollapsibleState.Expanded, + ) { + super( + Name, + ModuleName, + defaultParameterSet, + ParameterSets, + Parameters, + collapsibleState, + ); + } + + public getTreeItem(): vscode.TreeItem { + return { + label: this.Name, + collapsibleState: this.collapsibleState, + }; + } + + public async getChildren(element): Promise { + if (undefined !== this.populatedCommands) { + return this.populatedCommands; + } + } +} From 6aae499de7eed4091285c23a5637d31243b4d658 Mon Sep 17 00:00:00 2001 From: corbob Date: Sun, 8 Jul 2018 17:12:53 -0700 Subject: [PATCH 10/29] WIP: Something something it's broken... --- media/PwSh.svg | 4 ++++ src/features/GetCommands.ts | 23 ++++++----------------- src/main.ts | 9 +++++++-- 3 files changed, 17 insertions(+), 19 deletions(-) create mode 100644 media/PwSh.svg diff --git a/media/PwSh.svg b/media/PwSh.svg new file mode 100644 index 0000000000..51055ddd36 --- /dev/null +++ b/media/PwSh.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index b16087242a..74433aa473 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -11,7 +11,6 @@ export const GetCommandsRequestType = new RequestType("pow export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; private languageClient: LanguageClient; - private commandsExplorerProvider: CommandsExplorerProvider; constructor() { this.command = vscode.commands.registerCommand("PowerShell.GetCommands", () => { @@ -29,15 +28,9 @@ export class GetCommandsFeature implements IFeature { command.parameters, ); }; - this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); - this.commandsExplorerProvider.refresh(); + // commandsExplorerProvider.powerShellCommands = result.map(toCommand); }); }); - this.commandsExplorerProvider = new CommandsExplorerProvider(); - vscode.window.registerTreeDataProvider("commands", this.commandsExplorerProvider); - vscode.commands.registerCommand( - "PowerShell.refreshCommandsExplorer", - () => this.commandsExplorerProvider.refresh()); } public dispose() { @@ -49,7 +42,7 @@ export class GetCommandsFeature implements IFeature { } } -class CommandsExplorerProvider implements vscode.TreeDataProvider { +export class CommandsExplorerProvider implements vscode.TreeDataProvider { public readonly didChangeTreeDataEvent: vscode.Event; public powerShellCommands: Command[]; private didChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); @@ -67,19 +60,13 @@ class CommandsExplorerProvider implements vscode.TreeDataProvider { } public async getChildren(element?: Command): Promise { - return Promise.resolve(this.getCommandsFromJson()); - } - - public getCommandsFromJson(element?: Command): Command[] { - if (undefined !== this.powerShellCommands) { - return this.powerShellCommands; - } - return []; + return Promise.resolve(this.powerShellCommands ? this.powerShellCommands : []); } } class Command extends vscode.TreeItem { + public contextValue = "command"; constructor( public readonly Name: string, public readonly ModuleName: string, @@ -89,6 +76,7 @@ class Command extends vscode.TreeItem { public readonly collapsibleState = vscode.TreeItemCollapsibleState.None, ) { super(Name, collapsibleState); + this.label = Name; } public getTreeItem(): vscode.TreeItem { @@ -101,6 +89,7 @@ class Command extends vscode.TreeItem { public async getChildren(element): Promise { return []; } + } class CommandNode extends Command { diff --git a/src/main.ts b/src/main.ts index 715def3028..f8e1bbf477 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,7 @@ import { ExtensionCommandsFeature } from "./features/ExtensionCommands"; import { FindModuleFeature } from "./features/FindModule"; import { FoldingFeature } from "./features/Folding"; import { GenerateBugReportFeature } from "./features/GenerateBugReport"; -import { GetCommandsFeature } from "./features/GetCommands"; +import { CommandsExplorerProvider, GetCommandsFeature } from "./features/GetCommands"; import { HelpCompletionFeature } from "./features/HelpCompletion"; import { NewFileOrProjectFeature } from "./features/NewFileOrProject"; import { OpenInISEFeature } from "./features/OpenInISE"; @@ -42,6 +42,7 @@ const requiredEditorServicesVersion = "1.9.1"; let logger: Logger; let sessionManager: SessionManager; let extensionFeatures: IFeature[] = []; +const commandsExplorerProvider = new CommandsExplorerProvider(); const documentSelector: DocumentSelector = [ { language: "powershell", scheme: "file" }, @@ -141,6 +142,10 @@ export function activate(context: vscode.ExtensionContext): void { new CustomViewsFeature(), new FoldingFeature(logger, documentSelector), ]; + vscode.window.registerTreeDataProvider("powerShellCommands", commandsExplorerProvider); + vscode.commands.registerCommand( + "PowerShell.refreshCommandsExplorer", + () => commandsExplorerProvider.refresh()); sessionManager.setExtensionFeatures(extensionFeatures); if (extensionSettings.startAutomatically) { @@ -187,7 +192,7 @@ function checkForUpdatedVersion(context: vscode.ExtensionContext) { export function deactivate(): void { // Clean up all extension features extensionFeatures.forEach((feature) => { - feature.dispose(); + feature.dispose(); }); // Dispose of the current session From 2366df33ad56537a73b93faa5f099ebb0168d45b Mon Sep 17 00:00:00 2001 From: corbob Date: Sun, 8 Jul 2018 19:24:49 -0700 Subject: [PATCH 11/29] Still not refreshing. I give up for now :'( --- package.json | 24 ++++++++++++++++++++---- resources/dark/refresh.svg | 1 + resources/light/refresh.svg | 1 + src/features/GetCommands.ts | 20 ++++++++++++-------- src/main.ts | 9 ++------- 5 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 resources/dark/refresh.svg create mode 100644 resources/light/refresh.svg diff --git a/package.json b/package.json index 5d8eff36c0..7a409ca86a 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "onCommand:PowerShell.SpecifyScriptArgs", "onCommand:PowerShell.ShowSessionConsole", "onCommand:PowerShell.ShowSessionMenu", - "onCommand:PowerShell.RestartSession" + "onCommand:PowerShell.RestartSession", + "onView:powerShellCommands" ], "dependencies": { "vscode": "~1.1.21", @@ -63,14 +64,14 @@ { "id": "command-explorer", "title": "Command Explorer", - "icon": "media/dep.svg" + "icon": "media/PwSh.svg" } ] }, "views": { "command-explorer": [ { - "id": "commands", + "id": "powerShellCommands", "name": "PowerShell Commands" } ] @@ -108,6 +109,14 @@ "title": "Get Commands", "category": "PowerShell" }, + { + "command": "PowerShell.refreshCommandsExplorer", + "title": "Refresh", + "icon": { + "light": "resources/light/refresh.svg", + "dark": "resources/dark/refresh.svg" + } + }, { "command": "PowerShell.OnlineHelp", "title": "Get Online Help for Command (Deprecated)", @@ -196,6 +205,13 @@ "command": "PowerShell.ShowHelp", "group": "2_powershell" } + ], + "view/title": [ + { + "command": "PowerShell.refreshCommandsExplorer", + "when": "view == powerShellCommands", + "group": "navigation" + } ] }, "problemMatchers": [ @@ -589,7 +605,7 @@ "Warning", "Error" ], - "default": "Normal", + "default": "Diagnostic", "description": "Sets the logging verbosity level for the PowerShell Editor Services host executable. Valid values are 'Diagnostic', 'Verbose', 'Normal', 'Warning', and 'Error'" }, "powershell.developer.editorServicesWaitForDebugger": { diff --git a/resources/dark/refresh.svg b/resources/dark/refresh.svg new file mode 100644 index 0000000000..d79fdaa4e8 --- /dev/null +++ b/resources/dark/refresh.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/light/refresh.svg b/resources/light/refresh.svg new file mode 100644 index 0000000000..e034574819 --- /dev/null +++ b/resources/light/refresh.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 74433aa473..53292b3be8 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -11,6 +11,7 @@ export const GetCommandsRequestType = new RequestType("pow export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; private languageClient: LanguageClient; + private commandsExplorerProvider: CommandsExplorerProvider; constructor() { this.command = vscode.commands.registerCommand("PowerShell.GetCommands", () => { @@ -28,9 +29,15 @@ export class GetCommandsFeature implements IFeature { command.parameters, ); }; - // commandsExplorerProvider.powerShellCommands = result.map(toCommand); + this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); + // this.commandsExplorerProvider.refresh(); }); }); + this.commandsExplorerProvider = new CommandsExplorerProvider(); + vscode.window.registerTreeDataProvider("powerShellCommands", this.commandsExplorerProvider); + vscode.commands.registerCommand( + "PowerShell.refreshCommandsExplorer", + () => this.commandsExplorerProvider.refresh()); } public dispose() { @@ -42,10 +49,10 @@ export class GetCommandsFeature implements IFeature { } } -export class CommandsExplorerProvider implements vscode.TreeDataProvider { - public readonly didChangeTreeDataEvent: vscode.Event; +class CommandsExplorerProvider implements vscode.TreeDataProvider { + public readonly didChangeTreeDataEvent: vscode.Event; public powerShellCommands: Command[]; - private didChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); + private didChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); constructor() { this.didChangeTreeDataEvent = this.didChangeTreeData.event; @@ -59,14 +66,13 @@ export class CommandsExplorerProvider implements vscode.TreeDataProvider { + public getChildren(element?: Command): Thenable { return Promise.resolve(this.powerShellCommands ? this.powerShellCommands : []); } } class Command extends vscode.TreeItem { - public contextValue = "command"; constructor( public readonly Name: string, public readonly ModuleName: string, @@ -76,7 +82,6 @@ class Command extends vscode.TreeItem { public readonly collapsibleState = vscode.TreeItemCollapsibleState.None, ) { super(Name, collapsibleState); - this.label = Name; } public getTreeItem(): vscode.TreeItem { @@ -89,7 +94,6 @@ class Command extends vscode.TreeItem { public async getChildren(element): Promise { return []; } - } class CommandNode extends Command { diff --git a/src/main.ts b/src/main.ts index f8e1bbf477..715def3028 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,7 @@ import { ExtensionCommandsFeature } from "./features/ExtensionCommands"; import { FindModuleFeature } from "./features/FindModule"; import { FoldingFeature } from "./features/Folding"; import { GenerateBugReportFeature } from "./features/GenerateBugReport"; -import { CommandsExplorerProvider, GetCommandsFeature } from "./features/GetCommands"; +import { GetCommandsFeature } from "./features/GetCommands"; import { HelpCompletionFeature } from "./features/HelpCompletion"; import { NewFileOrProjectFeature } from "./features/NewFileOrProject"; import { OpenInISEFeature } from "./features/OpenInISE"; @@ -42,7 +42,6 @@ const requiredEditorServicesVersion = "1.9.1"; let logger: Logger; let sessionManager: SessionManager; let extensionFeatures: IFeature[] = []; -const commandsExplorerProvider = new CommandsExplorerProvider(); const documentSelector: DocumentSelector = [ { language: "powershell", scheme: "file" }, @@ -142,10 +141,6 @@ export function activate(context: vscode.ExtensionContext): void { new CustomViewsFeature(), new FoldingFeature(logger, documentSelector), ]; - vscode.window.registerTreeDataProvider("powerShellCommands", commandsExplorerProvider); - vscode.commands.registerCommand( - "PowerShell.refreshCommandsExplorer", - () => commandsExplorerProvider.refresh()); sessionManager.setExtensionFeatures(extensionFeatures); if (extensionSettings.startAutomatically) { @@ -192,7 +187,7 @@ function checkForUpdatedVersion(context: vscode.ExtensionContext) { export function deactivate(): void { // Clean up all extension features extensionFeatures.forEach((feature) => { - feature.dispose(); + feature.dispose(); }); // Dispose of the current session From 219fb8af5545e589d335eee8e8469b8185a5fa51 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 9 Jul 2018 11:55:58 -0700 Subject: [PATCH 12/29] Correct dimensions on sidebar icon Other icons appear to be 32 px square. This one was 50. Adjusting size to 32. --- media/PwSh.svg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/media/PwSh.svg b/media/PwSh.svg index 51055ddd36..8557cb5d95 100644 --- a/media/PwSh.svg +++ b/media/PwSh.svg @@ -1,4 +1,4 @@ - + - \ No newline at end of file + From 29d246b20d40564520ea17a6c35c82bf55a9b050 Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 12 Jul 2018 21:03:16 -0700 Subject: [PATCH 13/29] Minor cleanup Cleaning up the tslinter hints. Remove CommandNode, was part of a failed experiment to get the tree refresh working. --- src/features/GetCommands.ts | 40 ++----------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 53292b3be8..cf73346681 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -1,7 +1,6 @@ /*--------------------------------------------------------- * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ -// tslint:disable:no-console import * as vscode from "vscode"; import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; @@ -16,7 +15,7 @@ export class GetCommandsFeature implements IFeature { constructor() { this.command = vscode.commands.registerCommand("PowerShell.GetCommands", () => { if (this.languageClient === undefined) { - // We be screwed + // TODO: Log error message return; } this.languageClient.sendRequest(GetCommandsRequestType, "").then((result) => { @@ -36,7 +35,7 @@ export class GetCommandsFeature implements IFeature { this.commandsExplorerProvider = new CommandsExplorerProvider(); vscode.window.registerTreeDataProvider("powerShellCommands", this.commandsExplorerProvider); vscode.commands.registerCommand( - "PowerShell.refreshCommandsExplorer", + "PowerShell.RefreshCommandsExplorer", () => this.commandsExplorerProvider.refresh()); } @@ -95,38 +94,3 @@ class Command extends vscode.TreeItem { return []; } } - -class CommandNode extends Command { - public populatedCommands: Command[]; - constructor( - public eventEmitter: vscode.EventEmitter, - public readonly Name: string = "PowerShell", - public readonly ModuleName: string = "PowerShell", - public readonly defaultParameterSet: string = "", - public readonly ParameterSets: object = {}, - public readonly Parameters: object = {}, - public readonly collapsibleState = vscode.TreeItemCollapsibleState.Expanded, - ) { - super( - Name, - ModuleName, - defaultParameterSet, - ParameterSets, - Parameters, - collapsibleState, - ); - } - - public getTreeItem(): vscode.TreeItem { - return { - label: this.Name, - collapsibleState: this.collapsibleState, - }; - } - - public async getChildren(element): Promise { - if (undefined !== this.populatedCommands) { - return this.populatedCommands; - } - } -} From 9b3da0fc7244e27deee5b157729f18f50a832a3d Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 12 Jul 2018 21:10:25 -0700 Subject: [PATCH 14/29] Cleanup casing and variable names. Correct casing of some things. Adjust names to increase chance of uniqueness. --- package.json | 10 +++++----- src/features/GetCommands.ts | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 7a409ca86a..9724498953 100644 --- a/package.json +++ b/package.json @@ -62,16 +62,16 @@ "viewsContainers": { "activitybar": [ { - "id": "command-explorer", - "title": "Command Explorer", + "id": "PowerShellCommandExplorer", + "title": "PowerShell Command Explorer", "icon": "media/PwSh.svg" } ] }, "views": { - "command-explorer": [ + "PowerShellCommandExplorer": [ { - "id": "powerShellCommands", + "id": "PowerShellCommands", "name": "PowerShell Commands" } ] @@ -110,7 +110,7 @@ "category": "PowerShell" }, { - "command": "PowerShell.refreshCommandsExplorer", + "command": "PowerShell.RefreshCommandsExplorer", "title": "Refresh", "icon": { "light": "resources/light/refresh.svg", diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index cf73346681..3719cfcb4d 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -28,12 +28,12 @@ export class GetCommandsFeature implements IFeature { command.parameters, ); }; - this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); + this.commandsExplorerProvider.PowerShellCommands = result.map(toCommand); // this.commandsExplorerProvider.refresh(); }); }); this.commandsExplorerProvider = new CommandsExplorerProvider(); - vscode.window.registerTreeDataProvider("powerShellCommands", this.commandsExplorerProvider); + vscode.window.registerTreeDataProvider("PowerShellCommands", this.commandsExplorerProvider); vscode.commands.registerCommand( "PowerShell.RefreshCommandsExplorer", () => this.commandsExplorerProvider.refresh()); @@ -50,7 +50,7 @@ export class GetCommandsFeature implements IFeature { class CommandsExplorerProvider implements vscode.TreeDataProvider { public readonly didChangeTreeDataEvent: vscode.Event; - public powerShellCommands: Command[]; + public PowerShellCommands: Command[]; private didChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); constructor() { @@ -66,7 +66,7 @@ class CommandsExplorerProvider implements vscode.TreeDataProvider { } public getChildren(element?: Command): Thenable { - return Promise.resolve(this.powerShellCommands ? this.powerShellCommands : []); + return Promise.resolve(this.PowerShellCommands ? this.PowerShellCommands : []); } } From 728b0102ffe8b01dd89595a543dbb51925ef6127 Mon Sep 17 00:00:00 2001 From: corbob Date: Tue, 17 Jul 2018 22:32:51 -0700 Subject: [PATCH 15/29] Fix the refresh. Thanks to glennsarti for finding that the API expects to call back to a particular variable. --- package.json | 12 +++--------- src/features/GetCommands.ts | 11 ++++------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 9724498953..d223e6e581 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,7 @@ "onCommand:PowerShell.SpecifyScriptArgs", "onCommand:PowerShell.ShowSessionConsole", "onCommand:PowerShell.ShowSessionMenu", - "onCommand:PowerShell.RestartSession", - "onView:powerShellCommands" + "onCommand:PowerShell.RestartSession" ], "dependencies": { "vscode": "~1.1.21", @@ -104,11 +103,6 @@ "title": "Expand Alias", "category": "PowerShell" }, - { - "command": "PowerShell.GetCommands", - "title": "Get Commands", - "category": "PowerShell" - }, { "command": "PowerShell.RefreshCommandsExplorer", "title": "Refresh", @@ -208,8 +202,8 @@ ], "view/title": [ { - "command": "PowerShell.refreshCommandsExplorer", - "when": "view == powerShellCommands", + "command": "PowerShell.RefreshCommandsExplorer", + "when": "view == PowerShellCommands", "group": "navigation" } ] diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 3719cfcb4d..bf451b48fe 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -13,7 +13,7 @@ export class GetCommandsFeature implements IFeature { private commandsExplorerProvider: CommandsExplorerProvider; constructor() { - this.command = vscode.commands.registerCommand("PowerShell.GetCommands", () => { + this.command = vscode.commands.registerCommand("PowerShell.RefreshCommandsExplorer", () => { if (this.languageClient === undefined) { // TODO: Log error message return; @@ -29,14 +29,11 @@ export class GetCommandsFeature implements IFeature { ); }; this.commandsExplorerProvider.PowerShellCommands = result.map(toCommand); - // this.commandsExplorerProvider.refresh(); + this.commandsExplorerProvider.refresh(); }); }); this.commandsExplorerProvider = new CommandsExplorerProvider(); vscode.window.registerTreeDataProvider("PowerShellCommands", this.commandsExplorerProvider); - vscode.commands.registerCommand( - "PowerShell.RefreshCommandsExplorer", - () => this.commandsExplorerProvider.refresh()); } public dispose() { @@ -49,12 +46,12 @@ export class GetCommandsFeature implements IFeature { } class CommandsExplorerProvider implements vscode.TreeDataProvider { - public readonly didChangeTreeDataEvent: vscode.Event; + public readonly onDidChangeTreeData: vscode.Event; public PowerShellCommands: Command[]; private didChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); constructor() { - this.didChangeTreeDataEvent = this.didChangeTreeData.event; + this.onDidChangeTreeData = this.didChangeTreeData.event; } public refresh(): void { From 277d154673d1edce8b628dc5ab142c0f5f710285 Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 18 Jul 2018 21:21:46 -0700 Subject: [PATCH 16/29] Insert Command from treeview Add Insert Command Add Right Click Options to View Reset PSES Logging to Normal Update OnlineHelp to take an item from the treeview. Pass that to online help PSES handler. --- package.json | 25 +++++++++++++++++++++---- src/features/GetCommands.ts | 11 +++++++++++ src/features/ShowHelp.ts | 18 +++++++++++------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index d223e6e581..5b4bfc5794 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "onCommand:PowerShell.SpecifyScriptArgs", "onCommand:PowerShell.ShowSessionConsole", "onCommand:PowerShell.ShowSessionMenu", - "onCommand:PowerShell.RestartSession" + "onCommand:PowerShell.RestartSession", + "onView:PowerShellCommands" ], "dependencies": { "vscode": "~1.1.21", @@ -109,8 +110,14 @@ "icon": { "light": "resources/light/refresh.svg", "dark": "resources/dark/refresh.svg" - } - }, + }, + "category": "PowerShell" + }, + { + "command": "PowerShell.InsertCommand", + "title": "Insert Command", + "category": "PowerShell" + }, { "command": "PowerShell.OnlineHelp", "title": "Get Online Help for Command (Deprecated)", @@ -206,6 +213,16 @@ "when": "view == PowerShellCommands", "group": "navigation" } + ], + "view/item/context": [ + { + "command": "PowerShell.OnlineHelp", + "when": "view == PowerShellCommands" + }, + { + "command": "PowerShell.InsertCommand", + "when": "view == PowerShellCommands" + } ] }, "problemMatchers": [ @@ -599,7 +616,7 @@ "Warning", "Error" ], - "default": "Diagnostic", + "default": "Normal", "description": "Sets the logging verbosity level for the PowerShell Editor Services host executable. Valid values are 'Diagnostic', 'Verbose', 'Normal', 'Warning', and 'Error'" }, "powershell.developer.editorServicesWaitForDebugger": { diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index bf451b48fe..3f8799e763 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -34,6 +34,17 @@ export class GetCommandsFeature implements IFeature { }); this.commandsExplorerProvider = new CommandsExplorerProvider(); vscode.window.registerTreeDataProvider("PowerShellCommands", this.commandsExplorerProvider); + vscode.commands.registerCommand("PowerShell.InsertCommand", (item) => { + const editor = vscode.window.activeTextEditor; + const document = editor.document; + const selection = editor.selection; + const sls = selection.start; + const sle = selection.end; + const range = new vscode.Range(sls.line, sls.character, sle.line, sle.character); + editor.edit((editBuilder) => { + editBuilder.replace(range, item.Name); + }); + }); } public dispose() { diff --git a/src/features/ShowHelp.ts b/src/features/ShowHelp.ts index 5e8660eb34..1f15efd055 100644 --- a/src/features/ShowHelp.ts +++ b/src/features/ShowHelp.ts @@ -16,20 +16,24 @@ export class ShowHelpFeature implements IFeature { private languageClient: LanguageClient; constructor(private log: Logger) { - this.command = vscode.commands.registerCommand("PowerShell.ShowHelp", () => { + this.command = vscode.commands.registerCommand("PowerShell.ShowHelp", (item?) => { if (this.languageClient === undefined) { this.log.writeAndShowError(`<${ShowHelpFeature.name}>: ` + "Unable to instantiate; language client undefined."); return; } + if (item === undefined) { - const editor = vscode.window.activeTextEditor; - const selection = editor.selection; - const doc = editor.document; - const cwr = doc.getWordRangeAtPosition(selection.active); - const text = doc.getText(cwr); + const editor = vscode.window.activeTextEditor; + const selection = editor.selection; + const doc = editor.document; + const cwr = doc.getWordRangeAtPosition(selection.active); + const text = doc.getText(cwr); - this.languageClient.sendRequest(ShowHelpRequestType, text); + this.languageClient.sendRequest(ShowHelpRequestType, text); + } else { + this.languageClient.sendRequest(ShowOnlineHelpRequestType, item.Name); + } }); this.deprecatedCommand = vscode.commands.registerCommand("PowerShell.OnlineHelp", () => { From 2e44c7edde8a5642c80ce590d2fa712b2f2f8264 Mon Sep 17 00:00:00 2001 From: corbob Date: Fri, 20 Jul 2018 05:39:09 -0700 Subject: [PATCH 17/29] Have Command Explorer load fully on extension load. --- src/features/GetCommands.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 3f8799e763..beaac4b69b 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -53,6 +53,7 @@ export class GetCommandsFeature implements IFeature { public setLanguageClient(languageclient: LanguageClient) { this.languageClient = languageclient; + vscode.commands.executeCommand("PowerShell.RefreshCommandsExplorer"); } } From 3ecaf43a4f115a60c3e295ea77cdaee6bc51cbb0 Mon Sep 17 00:00:00 2001 From: corbob Date: Sat, 21 Jul 2018 06:50:55 -0700 Subject: [PATCH 18/29] Change to match PSES changes. Adding functionality to PSES to get all commands (Name and Module Name), or get all of a single command. This solves performance issues with getting all of all of them. --- src/features/GetCommands.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index beaac4b69b..c22cad3c91 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -5,7 +5,7 @@ import * as vscode from "vscode"; import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; -export const GetCommandsRequestType = new RequestType("powerShell/getCommands"); +export const GetAllCommandsRequestType = new RequestType("powerShell/getAllCommands"); export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; @@ -18,7 +18,7 @@ export class GetCommandsFeature implements IFeature { // TODO: Log error message return; } - this.languageClient.sendRequest(GetCommandsRequestType, "").then((result) => { + this.languageClient.sendRequest(GetAllCommandsRequestType, "").then((result) => { const toCommand = (command: any): Command => { return new Command( command.name, From a8ea23c0d33cdc02ea3d60f2355261f39a169c64 Mon Sep 17 00:00:00 2001 From: corbob Date: Tue, 31 Jul 2018 20:27:27 -0700 Subject: [PATCH 19/29] Move toCommand to be a standalone function --- src/features/GetCommands.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index c22cad3c91..2abbdec66c 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -19,15 +19,6 @@ export class GetCommandsFeature implements IFeature { return; } this.languageClient.sendRequest(GetAllCommandsRequestType, "").then((result) => { - const toCommand = (command: any): Command => { - return new Command( - command.name, - command.moduleName, - command.defaultParameterSet, - command.parameterSets, - command.parameters, - ); - }; this.commandsExplorerProvider.PowerShellCommands = result.map(toCommand); this.commandsExplorerProvider.refresh(); }); @@ -79,6 +70,15 @@ class CommandsExplorerProvider implements vscode.TreeDataProvider { } } +function toCommand(command: any): Command { + return new Command( + command.name, + command.moduleName, + command.defaultParameterSet, + command.parameterSets, + command.parameters, + ); +} class Command extends vscode.TreeItem { constructor( From bd0bc9b88a13c226035530b73ee1a62c552537f7 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 13 Aug 2018 20:09:04 -0700 Subject: [PATCH 20/29] Remove unneccesary svg files. --- media/PowerShell.svg | 29 ----------------------------- media/dep.svg | 14 -------------- 2 files changed, 43 deletions(-) delete mode 100644 media/PowerShell.svg delete mode 100644 media/dep.svg diff --git a/media/PowerShell.svg b/media/PowerShell.svg deleted file mode 100644 index ec01c8cb51..0000000000 --- a/media/PowerShell.svg +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/media/dep.svg b/media/dep.svg deleted file mode 100644 index 53e5be5bdc..0000000000 --- a/media/dep.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - Slice - Created with Sketch. - - - - - - - - - From 4bc69421a5ac9e85f17d9332fae6809b468ec296 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 13 Aug 2018 20:29:19 -0700 Subject: [PATCH 21/29] Fix formatting. Remove overly verbose selection --- .gitattributes | 3 +++ package.json | 12 ++++++------ src/features/GetCommands.ts | 13 ++++++------- src/features/ShowHelp.ts | 11 ++++++----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.gitattributes b/.gitattributes index acd2115566..2a922ee8df 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,9 @@ # Set the default behavior, in case people don't have core.autocrlf set. * text=auto +# Set svg to binary type, as SVG is unlikely to be editted by hand. Can be treated as checked in blob +*.svg binary + # .gitattributes in project root # npm now seems to be insisting on LF - see https://github.com/npm/npm/issues/17161 package.json text eol=lf diff --git a/package.json b/package.json index 5b4bfc5794..d3f9702648 100644 --- a/package.json +++ b/package.json @@ -105,11 +105,11 @@ "category": "PowerShell" }, { - "command": "PowerShell.RefreshCommandsExplorer", - "title": "Refresh", - "icon": { - "light": "resources/light/refresh.svg", - "dark": "resources/dark/refresh.svg" + "command": "PowerShell.RefreshCommandsExplorer", + "title": "Refresh", + "icon": { + "light": "resources/light/refresh.svg", + "dark": "resources/dark/refresh.svg" }, "category": "PowerShell" }, @@ -651,4 +651,4 @@ ] }, "private": true -} +} \ No newline at end of file diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 2abbdec66c..0e76a1f361 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -19,7 +19,7 @@ export class GetCommandsFeature implements IFeature { return; } this.languageClient.sendRequest(GetAllCommandsRequestType, "").then((result) => { - this.commandsExplorerProvider.PowerShellCommands = result.map(toCommand); + this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); this.commandsExplorerProvider.refresh(); }); }); @@ -27,10 +27,8 @@ export class GetCommandsFeature implements IFeature { vscode.window.registerTreeDataProvider("PowerShellCommands", this.commandsExplorerProvider); vscode.commands.registerCommand("PowerShell.InsertCommand", (item) => { const editor = vscode.window.activeTextEditor; - const document = editor.document; - const selection = editor.selection; - const sls = selection.start; - const sle = selection.end; + const sls = editor.selection.start; + const sle = editor.selection.end; const range = new vscode.Range(sls.line, sls.character, sle.line, sle.character); editor.edit((editBuilder) => { editBuilder.replace(range, item.Name); @@ -50,7 +48,7 @@ export class GetCommandsFeature implements IFeature { class CommandsExplorerProvider implements vscode.TreeDataProvider { public readonly onDidChangeTreeData: vscode.Event; - public PowerShellCommands: Command[]; + public powerShellCommands: Command[]; private didChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); constructor() { @@ -66,10 +64,11 @@ class CommandsExplorerProvider implements vscode.TreeDataProvider { } public getChildren(element?: Command): Thenable { - return Promise.resolve(this.PowerShellCommands ? this.PowerShellCommands : []); + return Promise.resolve(this.powerShellCommands || []); } } + function toCommand(command: any): Command { return new Command( command.name, diff --git a/src/features/ShowHelp.ts b/src/features/ShowHelp.ts index 1f15efd055..9fe372be19 100644 --- a/src/features/ShowHelp.ts +++ b/src/features/ShowHelp.ts @@ -24,11 +24,12 @@ export class ShowHelpFeature implements IFeature { } if (item === undefined) { - const editor = vscode.window.activeTextEditor; - const selection = editor.selection; - const doc = editor.document; - const cwr = doc.getWordRangeAtPosition(selection.active); - const text = doc.getText(cwr); + const editor = vscode.window.activeTextEditor; + + const selection = editor.selection; + const doc = editor.document; + const cwr = doc.getWordRangeAtPosition(selection.active); + const text = doc.getText(cwr); this.languageClient.sendRequest(ShowHelpRequestType, text); } else { From c22577018ec55f40189548c1bf78e112ef420ca0 Mon Sep 17 00:00:00 2001 From: corbob Date: Sat, 18 Aug 2018 10:11:36 -0700 Subject: [PATCH 22/29] Add some TODOs so we don't forget to do this. --- src/features/GetCommands.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 0e76a1f361..cd256da031 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -5,6 +5,8 @@ import * as vscode from "vscode"; import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; +// TODO: Document this export: https://github.com/PowerShell/vscode-powershell/pull/1406#discussion_r209325655 +// TODO: Also use something other than any if possible... We may have already addressed this with a previous attempt. export const GetAllCommandsRequestType = new RequestType("powerShell/getAllCommands"); export class GetCommandsFeature implements IFeature { @@ -18,6 +20,7 @@ export class GetCommandsFeature implements IFeature { // TODO: Log error message return; } + // TODO: Refactor network code out of constructor this.languageClient.sendRequest(GetAllCommandsRequestType, "").then((result) => { this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); this.commandsExplorerProvider.refresh(); @@ -69,6 +72,7 @@ class CommandsExplorerProvider implements vscode.TreeDataProvider { } +// TODO: Define and export an ICommand interface to describe the properties we require. function toCommand(command: any): Command { return new Command( command.name, @@ -100,5 +104,6 @@ class Command extends vscode.TreeItem { public async getChildren(element): Promise { return []; + // TODO: Determine why we're returning an empty array... I think it's because we have to return something and we're not actually using the tree view part just yet... } } From 565e0ada207ab10c97001684c6e87dd9dc479a7c Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 3 Sep 2018 07:47:17 -0700 Subject: [PATCH 23/29] Remove GetAllCommands. Refactor into a single command. If nothing is passed, it will return all objects. --- src/features/GetCommands.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index cd256da031..7d49bb2229 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -7,7 +7,7 @@ import { IFeature } from "../feature"; // TODO: Document this export: https://github.com/PowerShell/vscode-powershell/pull/1406#discussion_r209325655 // TODO: Also use something other than any if possible... We may have already addressed this with a previous attempt. -export const GetAllCommandsRequestType = new RequestType("powerShell/getAllCommands"); +export const GetAllCommandsRequestType = new RequestType("powerShell/getCommand"); export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; @@ -104,6 +104,8 @@ class Command extends vscode.TreeItem { public async getChildren(element): Promise { return []; - // TODO: Determine why we're returning an empty array... I think it's because we have to return something and we're not actually using the tree view part just yet... + // TODO: Determine why we're returning an empty array... + // I think it's because we have to return something and + // we're not actually using the tree view part just yet... } } From a36e053317295f841eae943576d472434eea6dc1 Mon Sep 17 00:00:00 2001 From: corbob Date: Fri, 28 Sep 2018 21:34:45 -0700 Subject: [PATCH 24/29] Add logging when language client not defined. Clean up TODO comments Clean up request type naming. White space cleanup --- src/features/GetCommands.ts | 13 ++++++------- src/features/ShowHelp.ts | 4 ++-- src/main.ts | 3 ++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index 7d49bb2229..f98704673e 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -4,6 +4,7 @@ import * as vscode from "vscode"; import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; +import { Logger } from "../logging"; // TODO: Document this export: https://github.com/PowerShell/vscode-powershell/pull/1406#discussion_r209325655 // TODO: Also use something other than any if possible... We may have already addressed this with a previous attempt. @@ -14,13 +15,13 @@ export class GetCommandsFeature implements IFeature { private languageClient: LanguageClient; private commandsExplorerProvider: CommandsExplorerProvider; - constructor() { + constructor(private log: Logger) { this.command = vscode.commands.registerCommand("PowerShell.RefreshCommandsExplorer", () => { if (this.languageClient === undefined) { - // TODO: Log error message + this.log.writeAndShowError(`<${GetCommandsFeature.name}>: ` + + "Unable to instantiate; language client undefined."); return; } - // TODO: Refactor network code out of constructor this.languageClient.sendRequest(GetAllCommandsRequestType, "").then((result) => { this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); this.commandsExplorerProvider.refresh(); @@ -102,10 +103,8 @@ class Command extends vscode.TreeItem { }; } - public async getChildren(element): Promise { + public async getChildren(element?): Promise { return []; - // TODO: Determine why we're returning an empty array... - // I think it's because we have to return something and - // we're not actually using the tree view part just yet... + // Returning an empty array because we need to return something. } } diff --git a/src/features/ShowHelp.ts b/src/features/ShowHelp.ts index 9fe372be19..e61f74d0a5 100644 --- a/src/features/ShowHelp.ts +++ b/src/features/ShowHelp.ts @@ -31,9 +31,9 @@ export class ShowHelpFeature implements IFeature { const cwr = doc.getWordRangeAtPosition(selection.active); const text = doc.getText(cwr); - this.languageClient.sendRequest(ShowHelpRequestType, text); + this.languageClient.sendRequest(ShowHelpRequestType, text); } else { - this.languageClient.sendRequest(ShowOnlineHelpRequestType, item.Name); + this.languageClient.sendRequest(ShowHelpRequestType, item.Name); } }); diff --git a/src/main.ts b/src/main.ts index 715def3028..9313f7d026 100644 --- a/src/main.ts +++ b/src/main.ts @@ -124,7 +124,7 @@ export function activate(context: vscode.ExtensionContext): void { new OpenInISEFeature(), new GenerateBugReportFeature(sessionManager), new ExpandAliasFeature(logger), - new GetCommandsFeature(), + new GetCommandsFeature(logger), new ShowHelpFeature(logger), new FindModuleFeature(), new PesterTestsFeature(sessionManager), @@ -141,6 +141,7 @@ export function activate(context: vscode.ExtensionContext): void { new CustomViewsFeature(), new FoldingFeature(logger, documentSelector), ]; + sessionManager.setExtensionFeatures(extensionFeatures); if (extensionSettings.startAutomatically) { From f60f2a6a2bef669e9b0da6e0b7062278d7a76a74 Mon Sep 17 00:00:00 2001 From: corbob Date: Fri, 28 Sep 2018 22:04:22 -0700 Subject: [PATCH 25/29] Bring Treeview into using ShowHelp OnlineHelp has been deprecated as of 1.9.0. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3f9702648..d94bb98656 100644 --- a/package.json +++ b/package.json @@ -216,7 +216,7 @@ ], "view/item/context": [ { - "command": "PowerShell.OnlineHelp", + "command": "PowerShell.ShowHelp", "when": "view == PowerShellCommands" }, { From 3d08f80b4a19b288e5f020cbd76928842d703e7e Mon Sep 17 00:00:00 2001 From: corbob Date: Tue, 30 Oct 2018 07:03:02 -0700 Subject: [PATCH 26/29] Move anonymous functions to Named. Clean up some naming and whitespace. --- src/features/GetCommands.ts | 48 ++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index f98704673e..c9aeb19c4c 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -8,7 +8,7 @@ import { Logger } from "../logging"; // TODO: Document this export: https://github.com/PowerShell/vscode-powershell/pull/1406#discussion_r209325655 // TODO: Also use something other than any if possible... We may have already addressed this with a previous attempt. -export const GetAllCommandsRequestType = new RequestType("powerShell/getCommand"); +export const GetCommandRequestType = new RequestType("powerShell/getCommand"); export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; @@ -16,28 +16,11 @@ export class GetCommandsFeature implements IFeature { private commandsExplorerProvider: CommandsExplorerProvider; constructor(private log: Logger) { - this.command = vscode.commands.registerCommand("PowerShell.RefreshCommandsExplorer", () => { - if (this.languageClient === undefined) { - this.log.writeAndShowError(`<${GetCommandsFeature.name}>: ` + - "Unable to instantiate; language client undefined."); - return; - } - this.languageClient.sendRequest(GetAllCommandsRequestType, "").then((result) => { - this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); - this.commandsExplorerProvider.refresh(); - }); - }); + this.command = vscode.commands.registerCommand("PowerShell.RefreshCommandsExplorer", + () => this.CommandExplorerRefresh()); this.commandsExplorerProvider = new CommandsExplorerProvider(); vscode.window.registerTreeDataProvider("PowerShellCommands", this.commandsExplorerProvider); - vscode.commands.registerCommand("PowerShell.InsertCommand", (item) => { - const editor = vscode.window.activeTextEditor; - const sls = editor.selection.start; - const sle = editor.selection.end; - const range = new vscode.Range(sls.line, sls.character, sle.line, sle.character); - editor.edit((editBuilder) => { - editBuilder.replace(range, item.Name); - }); - }); + vscode.commands.registerCommand("PowerShell.InsertCommand", (item) => this.InsertCommand(item)); } public dispose() { @@ -48,6 +31,28 @@ export class GetCommandsFeature implements IFeature { this.languageClient = languageclient; vscode.commands.executeCommand("PowerShell.RefreshCommandsExplorer"); } + + private CommandExplorerRefresh() { + if (this.languageClient === undefined) { + this.log.writeAndShowError(`<${GetCommandsFeature.name}>: ` + + "Unable to instantiate; language client undefined."); + return; + } + this.languageClient.sendRequest(GetCommandRequestType, "").then((result) => { + this.commandsExplorerProvider.powerShellCommands = result.map(toCommand); + this.commandsExplorerProvider.refresh(); + }); + } + + private InsertCommand(item) { + const editor = vscode.window.activeTextEditor; + const sls = editor.selection.start; + const sle = editor.selection.end; + const range = new vscode.Range(sls.line, sls.character, sle.line, sle.character); + editor.edit((editBuilder) => { + editBuilder.replace(range, item.Name); + }); + } } class CommandsExplorerProvider implements vscode.TreeDataProvider { @@ -70,7 +75,6 @@ class CommandsExplorerProvider implements vscode.TreeDataProvider { public getChildren(element?: Command): Thenable { return Promise.resolve(this.powerShellCommands || []); } - } // TODO: Define and export an ICommand interface to describe the properties we require. From b8be7564ce762aa303d729ff48a93e09f1835723 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 5 Nov 2018 21:05:21 -0800 Subject: [PATCH 27/29] Add interface for command. Eliminate any from RequestType --- src/features/GetCommands.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index c9aeb19c4c..c4a0b4ee5c 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -6,10 +6,23 @@ import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; import { Logger } from "../logging"; -// TODO: Document this export: https://github.com/PowerShell/vscode-powershell/pull/1406#discussion_r209325655 -// TODO: Also use something other than any if possible... We may have already addressed this with a previous attempt. -export const GetCommandRequestType = new RequestType("powerShell/getCommand"); +interface ICommand { + name: string; + moduleName: string; + defaultParameterSet: string; + parameterSets: object; + parameters: object; +} + +/** + * RequestType sent over to PSES. + * Expects: ICommand to be returned + */ +export const GetCommandRequestType = new RequestType("powerShell/getCommand"); +/** + * A PowerShell Command listing feature. Implements a treeview control. + */ export class GetCommandsFeature implements IFeature { private command: vscode.Disposable; private languageClient: LanguageClient; @@ -77,8 +90,7 @@ class CommandsExplorerProvider implements vscode.TreeDataProvider { } } -// TODO: Define and export an ICommand interface to describe the properties we require. -function toCommand(command: any): Command { +function toCommand(command: ICommand): Command { return new Command( command.name, command.moduleName, @@ -111,4 +123,5 @@ class Command extends vscode.TreeItem { return []; // Returning an empty array because we need to return something. } + } From 4ef509369fee1c4e2f25e41f86f050ef2c09f194 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 5 Nov 2018 21:18:03 -0800 Subject: [PATCH 28/29] Eliminate another any. --- src/features/GetCommands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/GetCommands.ts b/src/features/GetCommands.ts index c4a0b4ee5c..0821a65a2d 100644 --- a/src/features/GetCommands.ts +++ b/src/features/GetCommands.ts @@ -18,7 +18,7 @@ interface ICommand { * RequestType sent over to PSES. * Expects: ICommand to be returned */ -export const GetCommandRequestType = new RequestType("powerShell/getCommand"); +export const GetCommandRequestType = new RequestType("powerShell/getCommand"); /** * A PowerShell Command listing feature. Implements a treeview control. From a99feef1b6e645a85bb4ae51307633417cff555b Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 21 Nov 2018 21:15:09 -0800 Subject: [PATCH 29/29] Adjust casing --- media/PwSh.svg | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/media/PwSh.svg b/media/PwSh.svg index 8557cb5d95..681704b769 100644 --- a/media/PwSh.svg +++ b/media/PwSh.svg @@ -1,4 +1,4 @@ - - - - + + + + diff --git a/package.json b/package.json index d94bb98656..7c429a586e 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ { "id": "PowerShellCommandExplorer", "title": "PowerShell Command Explorer", - "icon": "media/PwSh.svg" + "icon": "media/pwsh.svg" } ] },