Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(build): show the Build tool window when explicit builds start (#487)

l0ng-aif592ff5b05d8
diff --git a/src/features/build/build.test.tsx b/src/features/build/build.test.tsx
index ac96fa84b..26036e07b 100644
--- a/src/features/build/build.test.tsx
+++ b/src/features/build/build.test.tsx
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { act, fireEvent, render, screen } from "@testing-library/react";
-import { getAction, isActionEnabled } from "@/platform/actions";
+import { executeAction, getAction, isActionEnabled } from "@/platform/actions";
import { getContext, setContext } from "@/platform/context";
import { bindingsFor } from "@/platform/keymap";
import { IpcError, type BuildEvent, type BuildMessage, type BuildResult } from "@/platform/ipc";
@@ -173,7 +173,7 @@ describe("build feature", () => {
await act(async () => {});
expect(getContext()["build.running"]).toBe(true);
expect(isActionEnabled(getAction("build.buildProject")!)).toBe(false);
- expect(show).not.toHaveBeenCalled();
+ expect(show).toHaveBeenCalledWith("build", false);
expect(useTasks.getState().tasks.some((t) => t.id === BUILD_TASK_ID && !t.done)).toBe(true);
const messages = [err("/p/src/A.java", 11), warn("/p/src/B.java", 2)];
await act(async () => {
@@ -213,9 +213,67 @@ describe("build feature", () => {
await second;
});
expect(notes.at(-1)).toMatchObject({ level: "info", title: "Build completed successfully in 3 s" });
+ expect(show).toHaveBeenCalledTimes(3);
+ });
+
+ it.each([
+ ["build.buildProject", undefined],
+ ["build.buildModule", "/p/core/src/A.java"],
+ ["build.rebuildProject", undefined],
+ ])("opens the Build window without focus when %s starts", async (id, arg) => {
+ const run = executeAction(id!, arg);
+ await act(async () => {});
+ expect(useBuildRun.getState().status).toBe("running");
+ expect(show).toHaveBeenCalledExactlyOnceWith("build", false);
+ expect(openFile).not.toHaveBeenCalled();
+ await act(async () => {
+ fake.resolve(result([], true));
+ await run;
+ });
expect(show).toHaveBeenCalledTimes(1);
});
+ it("keeps before-launch builds hidden until a failure", async () => {
+ const run = executeAction("build.buildProject", { activate: false });
+ await act(async () => {});
+ expect(useBuildRun.getState().status).toBe("running");
+ expect(show).not.toHaveBeenCalled();
+ await act(async () => {
+ fake.resolve(result([], true));
+ await run;
+ });
+ expect(show).not.toHaveBeenCalled();
+
+ const failed = executeAction("build.buildProject", { activate: false });
+ await act(async () => {});
+ expect(show).not.toHaveBeenCalled();
+ const messages = [err("/p/src/A.java", 11)];
+ await act(async () => {
+ fake.resolve(result(messages, false));
+ await failed;
+ });
+ expect(show).toHaveBeenCalledExactlyOnceWith("build", false);
+ expect(useBuildRun.getState().selected).toBe(firstError(messages)!.key);
+ expect(openFile).toHaveBeenCalledWith(
+ "/p/src/A.java",
+ expect.objectContaining({ focus: true, selection: { line: 11, col: 4 } }),
+ );
+ });
+
+ it("starts a build without a workbench", async () => {
+ show.mockImplementation(() => {
+ throw new Error("No workbench");
+ });
+ const run = startBuild("build");
+ await act(async () => {});
+ expect(fake.calls).toHaveLength(1);
+ await act(async () => {
+ fake.resolve(result([], true));
+ await run;
+ });
+ expect(useBuildRun.getState().status).toBe("success");
+ });
+
it("shows a message on single click and navigates on F4", async () => {
const messages = [err("/p/src/A.java", 11, "first problem"), warn("/p/src/B.java", 2)];
const run = startBuild("build");
diff --git a/src/features/build/index.ts b/src/features/build/index.ts
index 7af0d7877..7eaab3c00 100644
--- a/src/features/build/index.ts
+++ b/src/features/build/index.ts
@@ -59,7 +59,10 @@ export function activate(): () => void {
when: WHEN,
keywords: ["compile", "make", "mvn", "gradle", "cargo", "tsc", "go build"],
// Awaitable: Run's "Build" before launch task waits for the result.
- run: async () => void (await startBuild("build")),
+ run: async ({ arg }) => {
+ const activate = !(typeof arg === "object" && arg !== null && "activate" in arg && arg.activate === false);
+ await startBuild("build", null, activate);
+ },
},
{
id: "build.buildModule",
diff --git a/src/features/build/store.ts b/src/features/build/store.ts
index effa7a6a7..17bbaf63c 100644
--- a/src/features/build/store.ts
+++ b/src/features/build/store.ts
@@ -5,8 +5,8 @@
* Compiler messages reach the Problems view and editors as `build`
* diagnostics, published (and cleared on the next build) by the backend.
*
- * Like IDEA, the tool window is not shown when a build starts; a failed build
- * shows it, selects the first error and opens its location in the editor.
+ * Explicit builds show the tool window without taking focus. A failed build
+ * also selects the first error and opens its location in the editor.
*/
import { create } from "zustand";
import { Channel } from "@tauri-apps/api/core";
@@ -123,7 +123,11 @@ export function isBuilding(): boolean {
* Builds the project (`file` null) or the module containing `file`. Saves all
* documents first; a second build while one runs is ignored (IDEA disables the actions).
*/
-export async function startBuild(kind: BuildKind, file: string | null = null): Promise<BuildResult | null> {
+export async function startBuild(
+ kind: BuildKind,
+ file: string | null = null,
+ activate = true,
+): Promise<BuildResult | null> {
if (isBuilding() || !useProject.getState().project) return null;
const request = nextRequestId();
const taskTitle = TITLES[kind];
@@ -131,6 +135,13 @@ export async function startBuild(kind: BuildKind, file: string | null = null): P
const previous = useBuildRun.getState().files;
useBuildRun.setState({ ...INITIAL, request, kind, file, title: taskTitle, status: "running", files: previous });
setContext(BUILD_RUNNING, true);
+ if (activate) {
+ try {
+ toolWindowService().show("build", false);
+ } catch {
+ // No workbench (tests / settings window).
+ }
+ }
upsertTask({ id: BUILD_TASK_ID, title: taskTitle, message: null, fraction: null, done: false, cancel });
await maybeEditorService()
?.saveAll()
diff --git a/src/features/run/beforeLaunch.ts b/src/features/run/beforeLaunch.ts
index 648111e5f..fc0e632f8 100644
--- a/src/features/run/beforeLaunch.ts
+++ b/src/features/run/beforeLaunch.ts
@@ -60,7 +60,7 @@ async function runTask(task: BeforeLaunchTask, config: RunConfig, chain: readonl
switch (task.kind) {
case "build": {
if (!getAction(BUILD_ACTION)) return "Building is not available";
- if (!(await executeAction(BUILD_ACTION))) return "A build is already running";
+ if (!(await executeAction(BUILD_ACTION, { activate: false }))) return "A build is already running";
return getContext()[BUILD_STATUS] === "success" ? null : "Build failed";
}
case "run": {
diff --git a/src/features/run/runConfigTypes.test.tsx b/src/features/run/runConfigTypes.test.tsx
index 50b37602b..27c4cb67a 100644
--- a/src/features/run/runConfigTypes.test.tsx
+++ b/src/features/run/runConfigTypes.test.tsx
@@ -379,7 +379,7 @@ describe("before launch tasks", () => {
],
});
expect(await runBeforeLaunch(app, [app.id])).toBe(true);
- expect(build).toHaveBeenCalledOnce();
+ expect(build).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ arg: { activate: false } }));
expect(show).toHaveBeenCalledWith("todo", true);
build.mockImplementation(async () => setContext("build.lastStatus", "failed"));