From a15518fb4825d99d9b716781b22513830a3c38c8 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Tue, 21 Jan 2025 13:20:15 -0500 Subject: [PATCH] Refactor so no preparing is shown if build completes immediately --- src/ui/SwiftBuildStatus.ts | 99 +++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/src/ui/SwiftBuildStatus.ts b/src/ui/SwiftBuildStatus.ts index d93c6c7b..db1681b5 100644 --- a/src/ui/SwiftBuildStatus.ts +++ b/src/ui/SwiftBuildStatus.ts @@ -71,28 +71,14 @@ export class SwiftBuildStatus implements vscode.Disposable { disposables.forEach(d => d.dispose()); res(); }; - let started = false; disposables.push( - execution.onDidWrite(data => { - const name = new RunningTask(task).name; - - // If we've found nothing that matches a known state then put up a temporary - // message that we're preparing the build, as there is sometimes a delay before - // building starts while the build system is preparing, especially in large projects. - // The status bar has a message immediately, so only show this when using a - // notification to show progress. - if ( - !started && - (showBuildStatus === "notification" || showBuildStatus === "progress") - ) { - update(`${name}: Preparing...`); - } - - started = true; - if (this.parseEvents(name, data, update)) { - done(); - } - }), + this.outputParser( + new RunningTask(task).name, + execution, + showBuildStatus, + update, + done + ), execution.onDidClose(done), vscode.tasks.onDidEndTask(e => { if (e.execution.task === task) { @@ -118,32 +104,57 @@ export class SwiftBuildStatus implements vscode.Disposable { } } - /** - * @param data - * @returns true if done, false otherwise - */ - private parseEvents(name: string, data: string, update: (message: string) => void): boolean { - const sanitizedData = stripAnsi(data); - // We'll process data one line at a time, in reverse order - // since the latest interesting message is all we need to - // be concerned with - const lines = sanitizedData.split(/\r\n|\n|\r/gm).reverse(); - for (const line of lines) { - if (checkIfBuildComplete(line)) { - return true; + private outputParser( + name: string, + execution: SwiftExecution, + showBuildStatus: ShowBuildStatusOptions, + update: (message: string) => void, + done: () => void + ): vscode.Disposable { + let started = false; + + const parseEvents = (data: string) => { + const sanitizedData = stripAnsi(data); + // We'll process data one line at a time, in reverse order + // since the latest interesting message is all we need to + // be concerned with + const lines = sanitizedData.split(/\r\n|\n|\r/gm).reverse(); + for (const line of lines) { + if (checkIfBuildComplete(line)) { + return true; + } + const progress = this.findBuildProgress(line); + if (progress) { + update(`${name}: [${progress.completed}/${progress.total}]`); + started = true; + return false; + } + if (this.checkIfFetching(line)) { + // this.statusItem.update(task, `Fetching dependencies "${task.name}"`); + update(`${name}: Fetching Dependencies`); + started = true; + return false; + } } - const progress = this.findBuildProgress(line); - if (progress) { - update(`${name}: [${progress.completed}/${progress.total}]`); - return false; + // If we've found nothing that matches a known state then put up a temporary + // message that we're preparing the build, as there is sometimes a delay before + // building starts while the build system is preparing, especially in large projects. + // The status bar has a message immediately, so only show this when using a + // notification to show progress. + if ( + !started && + (showBuildStatus === "notification" || showBuildStatus === "progress") + ) { + update(`${name}: Preparing...`); } - if (this.checkIfFetching(line)) { - // this.statusItem.update(task, `Fetching dependencies "${task.name}"`); - update(`${name}: Fetching Dependencies`); - return false; + return false; + }; + + return execution.onDidWrite(data => { + if (parseEvents(data)) { + done(); } - } - return false; + }); } private checkIfFetching(line: string): boolean {