Skip to content

Commit

Permalink
*WIP* Fix Hanging Progress Bar (#536)
Browse files Browse the repository at this point in the history
* Remove await from ProgressNotification.show

* Remove async from ProgressNotification.show

* Revert async execute method

@W-5227494@
  • Loading branch information
Allison Leong authored Jul 30, 2018
1 parent db32fe1 commit 7f3cba2
Show file tree
Hide file tree
Showing 22 changed files with 47 additions and 88 deletions.
14 changes: 5 additions & 9 deletions packages/salesforcedx-vscode-core/src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export abstract class SfdxCommandletExecutor<T>
implements CommandletExecutor<T> {
protected showChannelOutput = true;

protected async attachExecution(
protected attachExecution(
execution: CommandExecution,
cancellationTokenSource: vscode.CancellationTokenSource,
cancellationToken: vscode.CancellationToken
Expand All @@ -334,22 +334,18 @@ export abstract class SfdxCommandletExecutor<T>
execution,
cancellationToken
);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}

public async execute(response: ContinueResponse<T>): Promise<void> {
public execute(response: ContinueResponse<T>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;
const execution = new CliCommandExecutor(this.build(response.data), {
cwd: vscode.workspace.rootPath
}).execute(cancellationToken);

await this.attachExecution(
execution,
cancellationTokenSource,
cancellationToken
);
this.attachExecution(execution, cancellationTokenSource, cancellationToken);
}

public abstract build(data: T): Command;
Expand Down Expand Up @@ -379,7 +375,7 @@ export class SfdxCommandlet<T> {
inputs = await this.postchecker.check(inputs);
switch (inputs.type) {
case 'CONTINUE':
return await this.executor.execute(inputs);
return this.executor.execute(inputs);
case 'CANCEL':
if (inputs.msg) {
notificationService.showErrorMessage(inputs.msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class ForceApexClassCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -79,7 +77,7 @@ class ForceApexClassCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ForceApexExecuteExecutor extends SfdxCommandletExecutor<{}> {
.build();
}

public async execute(response: ContinueResponse<TempFile>): Promise<void> {
public execute(response: ContinueResponse<TempFile>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand All @@ -56,7 +56,7 @@ class ForceApexExecuteExecutor extends SfdxCommandletExecutor<{}> {
);
channelService.showChannelOutput();
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ForceApexLogGetExecutor extends SfdxCommandletExecutor<
.build();
}

protected async attachExecution(
protected attachExecution(
execution: CommandExecution,
cancellationTokenSource: vscode.CancellationTokenSource,
cancellationToken: vscode.CancellationToken
Expand All @@ -55,7 +55,7 @@ export class ForceApexLogGetExecutor extends SfdxCommandletExecutor<
execution,
cancellationToken
);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}

Expand All @@ -67,11 +67,7 @@ export class ForceApexLogGetExecutor extends SfdxCommandletExecutor<
const execution = new CliCommandExecutor(this.build(response.data), {
cwd: vscode.workspace.rootPath
}).execute(cancellationToken);
await this.attachExecution(
execution,
cancellationTokenSource,
cancellationToken
);
this.attachExecution(execution, cancellationTokenSource, cancellationToken);
const result = await new CommandOutput().getCmdResult(execution);
const resultJson = JSON.parse(result);
if (resultJson.status === 0) {
Expand Down Expand Up @@ -166,7 +162,7 @@ export class ForceApexLogList {
.build(),
{ cwd: vscode.workspace.workspaceFolders![0].uri.fsPath }
).execute();
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
notificationService.reportExecutionError(
execution.command.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export class ForceApexTriggerCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -78,7 +76,7 @@ export class ForceApexTriggerCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export abstract class ForceAuthDemoModeExecutor<
);

channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class StopActiveDebuggerSessionExecutor extends SfdxCommandletExecutor<{}
const resultPromise = new CommandOutput().getCmdResult(execution);
channelService.streamCommandOutput(execution);
channelService.showChannelOutput();
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ class ForceGenerateFauxClassesExecutor extends SfdxCommandletExecutor<{}> {

const execution = new LocalCommandExecution(this.build(response.data));

await this.attachExecution(
execution,
cancellationTokenSource,
cancellationToken
);
this.attachExecution(execution, cancellationTokenSource, cancellationToken);

const projectPath: string = vscode.workspace.rootPath as string;
const gen: FauxClassGenerator = new FauxClassGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class ForceLightningAppCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -80,7 +78,7 @@ class ForceLightningAppCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class ForceLightningComponentCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -80,7 +78,7 @@ class ForceLightningComponentCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class ForceLightningEventCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -80,7 +78,7 @@ class ForceLightningEventCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class ForceLightningInterfaceCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -80,7 +78,7 @@ class ForceLightningInterfaceCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ export class ForceProjectCreateExecutor extends SfdxCommandletExecutor<
return builder.build();
}

public async execute(
response: ContinueResponse<ProjectNameAndPath>
): Promise<void> {
public execute(response: ContinueResponse<ProjectNameAndPath>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand All @@ -85,7 +83,7 @@ export class ForceProjectCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ForceStartApexDebugLoggingExecutor extends SfdxCommandletExecutor<{
const executionWrapper = new CompositeCliCommandExecutor(
this.build()
).execute(this.cancellationToken);
await this.attachExecution(
this.attachExecution(
executionWrapper,
this.cancellationTokenSource,
this.cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ export class ForceStopApexDebugLoggingExecutor extends SfdxCommandletExecutor<{}
return deleteTraceFlag();
}

public async execute(response: ContinueResponse<{}>): Promise<void> {
public execute(response: ContinueResponse<{}>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

const execution = new CliCommandExecutor(this.build(), {
cwd: vscode.workspace.rootPath
}).execute(cancellationToken);

await this.attachExecution(
execution,
cancellationTokenSource,
cancellationToken
);
this.attachExecution(execution, cancellationTokenSource, cancellationToken);
execution.processExitSubject.subscribe(async data => {
if (data !== undefined && data.toString() === '0') {
developerLogTraceFlag.turnOffLogging();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class ForceVisualForceComponentCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -79,7 +77,7 @@ class ForceVisualForceComponentCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class ForceVisualForcePageCreateExecutor extends SfdxCommandletExecutor<
.build();
}

public async execute(
response: ContinueResponse<DirFileNameSelection>
): Promise<void> {
public execute(response: ContinueResponse<DirFileNameSelection>): void {
const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

Expand Down Expand Up @@ -79,7 +77,7 @@ class ForceVisualForcePageCreateExecutor extends SfdxCommandletExecutor<
(execution.stderrSubject as any) as Observable<Error | undefined>
);
channelService.streamCommandOutput(execution);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,12 @@ export class IsvDebugBootstrapExecutor extends SfdxCommandletExecutor<{}> {

const result = new CommandOutput().getCmdResult(execution);

await this.attachExecution(
execution,
cancellationTokenSource,
cancellationToken
);
this.attachExecution(execution, cancellationTokenSource, cancellationToken);

return result;
}

protected async attachExecution(
protected attachExecution(
execution: CommandExecution,
cancellationTokenSource: vscode.CancellationTokenSource,
cancellationToken: vscode.CancellationToken
Expand All @@ -531,7 +527,7 @@ export class IsvDebugBootstrapExecutor extends SfdxCommandletExecutor<{}> {
execution.command.toString(),
(execution.stderrSubject as any) as Observable<Error | undefined>
);
await ProgressNotification.show(execution, cancellationTokenSource);
ProgressNotification.show(execution, cancellationTokenSource);
taskViewService.addCommandExecution(execution, cancellationTokenSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ import { nls } from '../../src/messages';
import { CommandExecution } from '@salesforce/salesforcedx-utils-vscode/out/src/cli';

export class ProgressNotification {
public static async show(
public static show(
execution: CommandExecution,
token: vscode.CancellationTokenSource
) {
await vscode.window.withProgress(
return vscode.window.withProgress(
{
title: nls.localize('progress_notification_text', execution.command),
location: vscode.ProgressLocation.Notification,
cancellable: true
},
async (progress, cancellationToken) => {
(progress, cancellationToken) => {
return new Promise(resolve => {
cancellationToken.onCancellationRequested(() => {
token.cancel();
return resolve();
});

execution.processExitSubject.subscribe(data => {
Expand Down
Loading

0 comments on commit 7f3cba2

Please sign in to comment.