Skip to content

Find module display quick pick list first. #484

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 1 commit into from
Feb 18, 2017
Merged
Changes from all commits
Commits
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
90 changes: 61 additions & 29 deletions src/features/PowerShellFindModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,35 @@ export class FindModuleFeature implements IFeature {

private command: vscode.Disposable;
private languageClient: LanguageClient;
private cancelFindToken: vscode.CancellationTokenSource;

constructor() {
this.command = vscode.commands.registerCommand('PowerShell.PowerShellFindModule', () => {
var items: QuickPickItem[] = [];
// It takes a while to get the list of PowerShell modules, display some UI to let user know
this.cancelFindToken = new vscode.CancellationTokenSource();
vscode.window
.showQuickPick(
["Cancel"],
{ placeHolder: "Please wait, retrieving list of PowerShell modules. This can take some time..." },
this.cancelFindToken.token)
.then(response => { if (response === "Cancel") { this.clearCancelFindToken(); } });

// Cancel the loading prompt after 60 seconds
setTimeout(() => {
if (this.cancelFindToken) {
this.clearCancelFindToken();

vscode.window.showErrorMessage(
"The online source for PowerShell modules is not responding. Cancelling Find/Install PowerShell command.");
}
}, 60000);

vscode.window.setStatusBarMessage(this.getCurrentTime() + " Initializing...");
this.languageClient.sendRequest(FindModuleRequest.type, null).then((modules) => {
for(var item in modules) {
items.push({ label: modules[item].name, description: modules[item].description });
};

vscode.window.setStatusBarMessage("");
Window.showQuickPick(items,{placeHolder: "Results: (" + modules.length + ")"}).then((selection) => {
if (!selection) { return; }
switch (selection.label) {
default :
var moduleName = selection.label;
//vscode.window.setStatusBarMessage("Installing PowerShell Module " + moduleName, 1500);
this.languageClient.sendRequest(InstallModuleRequest.type, moduleName);
}
});
});
this.pickPowerShellModule().then((moduleName) => {
if (moduleName) {
// vscode.window.setStatusBarMessage("Installing PowerShell Module " + moduleName, 1500);
this.languageClient.sendRequest(InstallModuleRequest.type, moduleName);
Copy link
Contributor Author

@rkeithhill rkeithhill Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this comment in. I think the thought was it would be nice to display this status bar message but the extension should probably receive a message back from PSES that the module has been installed. Then it would display an "Install complete" message for say 5 seconds before being cleared.

}
});
});
}

Expand All @@ -53,18 +60,43 @@ export class FindModuleFeature implements IFeature {
this.command.dispose();
}

private getCurrentTime() {
private pickPowerShellModule(): Thenable<string> {
return this.languageClient.sendRequest(FindModuleRequest.type, null).then((modules) => {
var items: QuickPickItem[] = [];

// We've got the modules info, let's cancel the timeout unless it's already been cancelled
if (this.cancelFindToken) {
this.clearCancelFindToken();
}
else {
// Already timed out, would be weird to dislay modules after we said it timed out.
return Promise.resolve("");
}

var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
for (var item in modules) {
items.push({ label: modules[item].name, description: modules[item].description });
};

var timeString = "" + ((hours > 12) ? hours - 12 : hours);
timeString += ((minutes < 10) ? ":0" : ":") + minutes;
timeString += ((seconds < 10) ? ":0" : ":") + seconds;
timeString += (hours >= 12) ? " PM" : " AM";
if (items.length === 0) {
return Promise.reject("No PowerShell modules were found.");
}

return timeString;
let options: vscode.QuickPickOptions = {
placeHolder: "Select a PowerShell module to install",
matchOnDescription: true,
matchOnDetail: true
};

return vscode.window.showQuickPick(items, options).then(item => {
return item ? item.label : "";
});
});
}
}

private clearCancelFindToken() {
if (this.cancelFindToken) {
this.cancelFindToken.dispose();
this.cancelFindToken = undefined;
}
}
}