Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show-Command explorer v1 #1406

Merged
merged 29 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7b5a4ee
Implement TreeView
corbob Jul 4, 2018
acfbfbf
Implement TreeView
corbob Jul 4, 2018
9599d86
Missed some variable names.
corbob Jul 4, 2018
406888f
Adding svg for activitybar.
corbob Jul 4, 2018
874601d
Added a PowerShell SVG.
corbob Jul 5, 2018
aa8d4b4
First Attempt to call to PSES
corbob Jul 5, 2018
ba75663
Get data from PSES
corbob Jul 6, 2018
338da93
Refactoring code
corbob Jul 7, 2018
bcd569b
Pulling live data.
corbob Jul 8, 2018
6aae499
WIP: Something something it's broken...
corbob Jul 9, 2018
2366df3
Still not refreshing. I give up for now :'(
corbob Jul 9, 2018
219fb8a
Correct dimensions on sidebar icon
corbob Jul 9, 2018
29d246b
Minor cleanup
corbob Jul 13, 2018
9b3da0f
Cleanup casing and variable names.
corbob Jul 13, 2018
728b010
Fix the refresh.
corbob Jul 18, 2018
277d154
Insert Command from treeview
corbob Jul 19, 2018
2e44c7e
Have Command Explorer load fully on extension load.
corbob Jul 20, 2018
3ecaf43
Change to match PSES changes.
corbob Jul 21, 2018
a8ea23c
Move toCommand to be a standalone function
corbob Aug 1, 2018
bd0bc9b
Remove unneccesary svg files.
corbob Aug 14, 2018
4bc6942
Fix formatting. Remove overly verbose selection
corbob Aug 14, 2018
c225770
Add some TODOs so we don't forget to do this.
corbob Aug 18, 2018
565e0ad
Remove GetAllCommands.
corbob Sep 3, 2018
a36e053
Add logging when language client not defined.
corbob Sep 29, 2018
f60f2a6
Bring Treeview into using ShowHelp
corbob Sep 29, 2018
3d08f80
Move anonymous functions to Named.
corbob Oct 30, 2018
b8be756
Add interface for command. Eliminate any from RequestType
corbob Nov 6, 2018
4ef5093
Eliminate another any.
corbob Nov 6, 2018
a99feef
Adjust casing
corbob Nov 22, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions media/PwSh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 51 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -58,6 +59,23 @@
"test": "node ./node_modules/vscode/bin/test"
},
"contributes": {
"viewsContainers": {
"activitybar": [
{
"id": "PowerShellCommandExplorer",
"title": "PowerShell Command Explorer",
"icon": "media/pwsh.svg"
}
]
},
"views": {
"PowerShellCommandExplorer": [
{
"id": "PowerShellCommands",
"name": "PowerShell Commands"
}
]
},
"keybindings": [
{
"command": "PowerShell.ShowHelp",
Expand Down Expand Up @@ -86,6 +104,20 @@
"title": "Expand Alias",
"category": "PowerShell"
},
{
"command": "PowerShell.RefreshCommandsExplorer",
"title": "Refresh",
"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)",
Expand Down Expand Up @@ -174,6 +206,23 @@
"command": "PowerShell.ShowHelp",
"group": "2_powershell"
}
],
"view/title": [
{
"command": "PowerShell.RefreshCommandsExplorer",
"when": "view == PowerShellCommands",
"group": "navigation"
}
],
"view/item/context": [
{
"command": "PowerShell.ShowHelp",
"when": "view == PowerShellCommands"
},
{
"command": "PowerShell.InsertCommand",
"when": "view == PowerShellCommands"
}
]
},
"problemMatchers": [
Expand Down Expand Up @@ -602,4 +651,4 @@
]
},
"private": true
}
}
1 change: 1 addition & 0 deletions resources/dark/refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/light/refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions src/features/GetCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as vscode from "vscode";
import { LanguageClient, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { Logger } from "../logging";

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<string, ICommand[], void, void>("powerShell/getCommand");

/**
* A PowerShell Command listing feature. Implements a treeview control.
*/
export class GetCommandsFeature implements IFeature {
rjmholt marked this conversation as resolved.
Show resolved Hide resolved
private command: vscode.Disposable;
private languageClient: LanguageClient;
private commandsExplorerProvider: CommandsExplorerProvider;

constructor(private log: Logger) {
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) => this.InsertCommand(item));
}

public dispose() {
this.command.dispose();
}

public setLanguageClient(languageclient: LanguageClient) {
corbob marked this conversation as resolved.
Show resolved Hide resolved
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<Command> {
public readonly onDidChangeTreeData: vscode.Event<Command | undefined>;
public powerShellCommands: Command[];
private didChangeTreeData: vscode.EventEmitter<Command | undefined> = new vscode.EventEmitter<Command>();

constructor() {
this.onDidChangeTreeData = this.didChangeTreeData.event;
}

public refresh(): void {
this.didChangeTreeData.fire();
}

public getTreeItem(element: Command): vscode.TreeItem {
return element;
}

public getChildren(element?: Command): Thenable<Command[]> {
return Promise.resolve(this.powerShellCommands || []);
}
}
corbob marked this conversation as resolved.
Show resolved Hide resolved

function toCommand(command: ICommand): Command {
return new Command(
command.name,
command.moduleName,
command.defaultParameterSet,
command.parameterSets,
command.parameters,
);
}

class Command extends vscode.TreeItem {
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);
}

public getTreeItem(): vscode.TreeItem {
return {
label: this.label,
collapsibleState: this.collapsibleState,
};
}

public async getChildren(element?): Promise<Command[]> {
return [];
corbob marked this conversation as resolved.
Show resolved Hide resolved
// Returning an empty array because we need to return something.
}

}
19 changes: 12 additions & 7 deletions src/features/ShowHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ 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;

this.languageClient.sendRequest(ShowHelpRequestType, text);
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 {
this.languageClient.sendRequest(ShowHelpRequestType, item.Name);
}
});

this.deprecatedCommand = vscode.commands.registerCommand("PowerShell.OnlineHelp", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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 { HelpCompletionFeature } from "./features/HelpCompletion";
import { NewFileOrProjectFeature } from "./features/NewFileOrProject";
import { OpenInISEFeature } from "./features/OpenInISE";
Expand Down Expand Up @@ -123,6 +124,7 @@ export function activate(context: vscode.ExtensionContext): void {
new OpenInISEFeature(),
new GenerateBugReportFeature(sessionManager),
new ExpandAliasFeature(logger),
new GetCommandsFeature(logger),
new ShowHelpFeature(logger),
new FindModuleFeature(),
new PesterTestsFeature(sessionManager),
Expand Down