Skip to content

Notify build is preparing before progress starts #1323

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 file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions src/SwiftSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { createSwiftTask } from "./tasks/SwiftTaskProvider";
import { WorkspaceContext } from "./WorkspaceContext";
import { createSnippetConfiguration, debugLaunchConfig } from "./debugger/launch";
import { TaskOperation } from "./tasks/TaskQueue";
import configuration from "./configuration";

/**
* Set context key indicating whether current file is a Swift Snippet
Expand Down Expand Up @@ -82,7 +81,6 @@ export async function debugSnippetWithOptions(
presentationOptions: {
reveal: vscode.TaskRevealKind.Always,
},
showBuildStatus: configuration.showBuildStatus,
},
ctx.toolchain
);
Expand Down
15 changes: 9 additions & 6 deletions src/tasks/SwiftTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export function createBuildAllTask(
reveal: getBuildRevealOption(),
},
disableTaskQueue: true,
showBuildStatus: configuration.showBuildStatus,
},
folderContext.workspaceContext.toolchain
);
Expand Down Expand Up @@ -239,7 +238,6 @@ function createBuildTasks(product: Product, folderContext: FolderContext): vscod
},
disableTaskQueue: true,
dontTriggerTestDiscovery: true,
showBuildStatus: configuration.showBuildStatus,
},
folderContext.workspaceContext.toolchain
);
Expand Down Expand Up @@ -268,7 +266,6 @@ function createBuildTasks(product: Product, folderContext: FolderContext): vscod
},
disableTaskQueue: true,
dontTriggerTestDiscovery: true,
showBuildStatus: configuration.showBuildStatus,
},
folderContext.workspaceContext.toolchain
);
Expand Down Expand Up @@ -314,9 +311,15 @@ export function createSwiftTask(
args: args,
env: env,
cwd: cwd,
showBuildStatus: config.showBuildStatus,
disableTaskQueue: config.disableTaskQueue,
dontTriggerTestDiscovery: config.dontTriggerTestDiscovery,
...(config.showBuildStatus !== undefined
? { showBuildStatus: config.showBuildStatus }
: {}),
...(config.disableTaskQueue !== undefined
? { disableTaskQueue: config.disableTaskQueue }
: {}),
...(config.dontTriggerTestDiscovery !== undefined
? { dontTriggerTestDiscovery: config.dontTriggerTestDiscovery }
: {}),
},
config?.scope ?? vscode.TaskScope.Workspace,
name,
Expand Down
88 changes: 55 additions & 33 deletions src/ui/SwiftBuildStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ export class SwiftBuildStatus implements vscode.Disposable {
res();
};
disposables.push(
execution.onDidWrite(data => {
if (this.parseEvents(task, 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) {
Expand All @@ -102,37 +104,57 @@ export class SwiftBuildStatus implements vscode.Disposable {
}
}

/**
* @param data
* @returns true if done, false otherwise
*/
private parseEvents(
task: vscode.Task,
data: string,
update: (message: string) => void
): boolean {
const name = new RunningTask(task).name;
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 {
Expand Down
8 changes: 4 additions & 4 deletions test/unit-tests/ui/SwiftBuildStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ suite("SwiftBuildStatus Unit Test Suite", async function () {
"Fetched https://github.com/apple/swift-testing.git from cache (0.77s)\n"
);

const expected = "My Task fetching dependencies";
const expected = "My Task: Fetching Dependencies";
expect(mockedProgress.report).to.have.been.calledWith({ message: expected });
expect(mockedStatusItem.update).to.have.been.calledWith(mockedTaskExecution.task, expected);
});
Expand All @@ -186,15 +186,15 @@ suite("SwiftBuildStatus Unit Test Suite", async function () {
"[7/7] Applying MyCLI\n"
);

const expected = "My Task [7/7]";
const expected = "My Task: [7/7]";
expect(mockedProgress.report).to.have.been.calledWith({ message: expected });
expect(mockedStatusItem.update).to.have.been.calledWith(mockedTaskExecution.task, expected);

// Ignore old stuff
expect(mockedProgress.report).to.not.have.been.calledWith({
message: "My Task fetching dependencies",
message: "My Task: Fetching Dependencies",
});
expect(mockedProgress.report).to.not.have.been.calledWith({ message: "My Task [6/7]" });
expect(mockedProgress.report).to.not.have.been.calledWith({ message: "My Task: [6/7]" });
});

test("Build complete", async () => {
Expand Down
Loading