-
Notifications
You must be signed in to change notification settings - Fork 513
Show-Command explorer v1 #1406
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
Merged
Merged
Show-Command explorer v1 #1406
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
7b5a4ee
Implement TreeView
corbob acfbfbf
Implement TreeView
corbob 9599d86
Missed some variable names.
corbob 406888f
Adding svg for activitybar.
corbob 874601d
Added a PowerShell SVG.
corbob aa8d4b4
First Attempt to call to PSES
corbob ba75663
Get data from PSES
corbob 338da93
Refactoring code
corbob bcd569b
Pulling live data.
corbob 6aae499
WIP: Something something it's broken...
corbob 2366df3
Still not refreshing. I give up for now :'(
corbob 219fb8a
Correct dimensions on sidebar icon
corbob 29d246b
Minor cleanup
corbob 9b3da0f
Cleanup casing and variable names.
corbob 728b010
Fix the refresh.
corbob 277d154
Insert Command from treeview
corbob 2e44c7e
Have Command Explorer load fully on extension load.
corbob 3ecaf43
Change to match PSES changes.
corbob a8ea23c
Move toCommand to be a standalone function
corbob bd0bc9b
Remove unneccesary svg files.
corbob 4bc6942
Fix formatting. Remove overly verbose selection
corbob c225770
Add some TODOs so we don't forget to do this.
corbob 565e0ad
Remove GetAllCommands.
corbob a36e053
Add logging when language client not defined.
corbob f60f2a6
Bring Treeview into using ShowHelp
corbob 3d08f80
Move anonymous functions to Named.
corbob b8be756
Add interface for command. Eliminate any from RequestType
corbob 4ef5093
Eliminate another any.
corbob a99feef
Adjust casing
corbob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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. | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.