Skip to content

Commit b3fb068

Browse files
Merge pull request #4187 from PowerShell/andschwa/editor-command-status
Re-implement indicator when running registered editor commands
2 parents 18c38d1 + 0021e6e commit b3fb068

File tree

3 files changed

+22
-79
lines changed

3 files changed

+22
-79
lines changed

src/features/Console.ts

+6-43
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/check
1010
import { Logger } from "../logging";
1111
import Settings = require("../settings");
1212
import { LanguageClientConsumer } from "../languageClientConsumer";
13+
import { SessionManager } from "../session";
1314

1415
export const EvaluateRequestType = new RequestType<IEvaluateRequestArguments, void, void>("evaluate");
1516
export const OutputNotificationType = new NotificationType<IOutputNotificationBody>("output");
1617
export const ExecutionStatusChangedNotificationType =
17-
new NotificationType<IExecutionStatusDetails>("powerShell/executionStatusChanged");
18+
new NotificationType<ExecutionStatus>("powerShell/executionStatusChanged");
1819

1920
export const ShowChoicePromptRequestType =
2021
new RequestType<IShowChoicePromptRequestArgs,
@@ -33,12 +34,6 @@ export interface IOutputNotificationBody {
3334
output: string;
3435
}
3536

36-
interface IExecutionStatusDetails {
37-
executionOptions: IExecutionOptions;
38-
executionStatus: ExecutionStatus;
39-
hadErrors: boolean;
40-
}
41-
4237
interface IChoiceDetails {
4338
label: string;
4439
helpMessage: string;
@@ -75,13 +70,6 @@ enum ExecutionStatus {
7570
Completed,
7671
}
7772

78-
interface IExecutionOptions {
79-
writeOutputToHost: boolean;
80-
writeErrorsToHost: boolean;
81-
addToHistory: boolean;
82-
interruptCommandPrompt: boolean;
83-
}
84-
8573
function showChoicePrompt(
8674
promptDetails: IShowChoicePromptRequestArgs,
8775
client: LanguageClient): Thenable<IShowChoicePromptResponseBody> {
@@ -196,7 +184,7 @@ export class ConsoleFeature extends LanguageClientConsumer {
196184
private handlers: vscode.Disposable[];
197185
private resolveStatusBarPromise: (value?: {} | PromiseLike<{}>) => void;
198186

199-
constructor(private log: Logger) {
187+
constructor(private log: Logger, private sessionManager: SessionManager) {
200188
super();
201189
this.commands = [
202190
vscode.commands.registerCommand("PowerShell.RunSelection", async () => {
@@ -236,8 +224,6 @@ export class ConsoleFeature extends LanguageClientConsumer {
236224
}
237225

238226
public dispose() {
239-
// Make sure we cancel any status bar
240-
this.clearStatusBar();
241227
for (const command of this.commands) {
242228
command.dispose();
243229
}
@@ -257,44 +243,21 @@ export class ConsoleFeature extends LanguageClientConsumer {
257243
ShowInputPromptRequestType,
258244
(promptDetails) => showInputPrompt(promptDetails)),
259245

260-
// TODO: We're not receiving these events from the server any more.
261246
// Set up status bar alerts for when PowerShell is executing a script.
262247
this.languageClient.onNotification(
263248
ExecutionStatusChangedNotificationType,
264249
(executionStatusDetails) => {
265-
switch (executionStatusDetails.executionStatus) {
266-
// If execution has changed to running, make a notification
250+
switch (executionStatusDetails) {
267251
case ExecutionStatus.Running:
268-
this.showExecutionStatus("PowerShell");
252+
this.sessionManager.setSessionBusyStatus();
269253
break;
270-
271-
// If the execution has stopped, destroy the previous notification
272254
case ExecutionStatus.Completed:
273255
case ExecutionStatus.Aborted:
274256
case ExecutionStatus.Failed:
275-
this.clearStatusBar();
257+
this.sessionManager.setSessionRunningStatus();
276258
break;
277259
}
278260
})
279261
]
280262
}
281-
282-
private showExecutionStatus(message: string) {
283-
vscode.window.withProgress({
284-
location: vscode.ProgressLocation.Window,
285-
}, (progress) => {
286-
return new Promise((resolve, _reject) => {
287-
this.clearStatusBar();
288-
289-
this.resolveStatusBarPromise = resolve;
290-
progress.report({ message });
291-
});
292-
});
293-
}
294-
295-
private clearStatusBar() {
296-
if (this.resolveStatusBarPromise) {
297-
this.resolveStatusBarPromise();
298-
}
299-
}
300263
}

src/main.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
"use strict";
55

6-
import path = require("path");
76
import vscode = require("vscode");
87
import TelemetryReporter from "@vscode/extension-telemetry";
98
import { DocumentSelector } from "vscode-languageclient";
@@ -150,7 +149,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
150149

151150
// Features and command registrations that require language client
152151
languageClientConsumers = [
153-
new ConsoleFeature(logger),
152+
new ConsoleFeature(logger, sessionManager),
154153
new ExpandAliasFeature(logger),
155154
new GetCommandsFeature(logger),
156155
new ShowHelpFeature(logger),

src/session.ts

+15-34
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export enum SessionStatus {
3333
NotStarted,
3434
Initializing,
3535
Running,
36+
Busy,
3637
Stopping,
3738
Failed,
3839
}
@@ -76,10 +77,6 @@ export const PowerShellVersionRequestType =
7677
new RequestType0<IPowerShellVersionDetails, void>(
7778
"powerShell/getVersion");
7879

79-
export const RunspaceChangedEventType =
80-
new NotificationType<IRunspaceDetails>(
81-
"powerShell/runspaceChanged");
82-
8380
export class SessionManager implements Middleware {
8481
public HostName: string;
8582
public HostVersion: string;
@@ -502,21 +499,6 @@ Type 'help' to get help.
502499
}
503500
}
504501

505-
private setStatusBarVersionString(runspaceDetails: IRunspaceDetails) {
506-
const psVersion = runspaceDetails.powerShellVersion;
507-
508-
let versionString =
509-
this.versionDetails.architecture === "x86"
510-
? `${psVersion.displayVersion} (${psVersion.architecture})`
511-
: psVersion.displayVersion;
512-
513-
if (runspaceDetails.runspaceType !== RunspaceType.Local) {
514-
versionString += ` [${runspaceDetails.connectionString}]`;
515-
}
516-
517-
this.setSessionVersion(versionString);
518-
}
519-
520502
private registerCommands(): void {
521503
this.registeredCommands = [
522504
vscode.commands.registerCommand("PowerShell.RestartSession", async () => { await this.restartSession(); }),
@@ -676,11 +658,6 @@ Type 'help' to get help.
676658
this.languageClient.onNotification(
677659
SendKeyPressNotificationType,
678660
() => { this.languageServerProcess.sendKeyPress(); }),
679-
680-
// TODO: I'm not sure we're still receiving these notifications...
681-
this.languageClient.onNotification(
682-
RunspaceChangedEventType,
683-
(runspaceDetails) => { this.setStatusBarVersionString(runspaceDetails); }),
684661
]
685662

686663
try {
@@ -691,13 +668,9 @@ Type 'help' to get help.
691668
}
692669

693670
this.versionDetails = await this.languageClient.sendRequest(PowerShellVersionRequestType);
694-
671+
this.setSessionRunningStatus(); // This requires the version details to be set.
695672
this.sendTelemetryEvent("powershellVersionCheck", { powershellVersion: this.versionDetails.version });
696673

697-
this.setSessionVersion(this.versionDetails.architecture === "x86"
698-
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`
699-
: this.versionDetails.displayVersion);
700-
701674
// We haven't "started" until we're done getting the version information.
702675
this.started = true;
703676

@@ -753,30 +726,38 @@ Type 'help' to get help.
753726
case SessionStatus.NeverStarted:
754727
case SessionStatus.NotStarted:
755728
this.languageStatusItem.busy = false;
756-
// @ts-ignore
729+
this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Information;
730+
break;
731+
case SessionStatus.Busy:
732+
this.languageStatusItem.busy = true;
757733
this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Information;
758734
break;
759735
case SessionStatus.Initializing:
760736
case SessionStatus.Stopping:
761737
this.languageStatusItem.busy = true;
762-
// @ts-ignore
763738
this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Warning;
764739
break;
765740
case SessionStatus.Failed:
766741
this.languageStatusItem.busy = false;
767-
// @ts-ignore
768742
this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Error;
769743
break;
770744
}
771745

772746
}
773747

774-
private setSessionVersion(version: string): void {
775-
// TODO: Accept a VersionDetails object instead of a string.
748+
public setSessionRunningStatus(): void {
749+
const version = this.versionDetails.architecture === "x86"
750+
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`
751+
: this.versionDetails.displayVersion;
752+
776753
this.languageStatusItem.text = "$(terminal-powershell) " + version;
777754
this.setSessionStatus(version, SessionStatus.Running);
778755
}
779756

757+
public setSessionBusyStatus(): void {
758+
this.setSessionStatus("Executing...", SessionStatus.Busy);
759+
}
760+
780761
private async setSessionFailure(message: string, ...additionalMessages: string[]) {
781762
this.setSessionStatus("Initialization Error", SessionStatus.Failed);
782763
await this.log.writeAndShowError(message, ...additionalMessages);

0 commit comments

Comments
 (0)