From 7eb186ae8aa03cb9c0c3cfa56987a6cf9e058ea5 Mon Sep 17 00:00:00 2001 From: Gabriel Gondim <52431033+GGVidal@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:06:20 -0300 Subject: [PATCH] feat(build): settings to keep the Build tool window hidden (#4539) Settings > Build, Execution, Deployment > Compiler chooses when builds open and focus the Build tool window (Always / Only on errors / Never; defaults: open without focus). Run/Debug before-launch builds stay hidden until they fail, then follow the open setting. Co-authored-by: GGVidal <52431033+GGVidal@users.noreply.github.com> --- crates/ide-core/src/settings.rs | 3 ++ crates/ide-core/src/workflow_settings.rs | 17 ++++++++ src/bindings.ts | 12 ++++++ src/features/build/build.test.tsx | 45 +++++++++++++++++++- src/features/build/store.ts | 51 +++++++++++++---------- src/features/settings/pages/execution.tsx | 40 ++++++++++++++++++ src/platform/locales/text/en.json | 7 +++- src/platform/locales/text/zh.json | 7 +++- src/platform/workflowSettings.test.ts | 11 +++++ src/platform/workflowSettings.ts | 22 ++++++++++ 10 files changed, 188 insertions(+), 27 deletions(-) diff --git a/crates/ide-core/src/settings.rs b/crates/ide-core/src/settings.rs index 8f0f0c031..9c8475455 100644 --- a/crates/ide-core/src/settings.rs +++ b/crates/ide-core/src/settings.rs @@ -34,6 +34,8 @@ pub struct Settings { pub project_structure: ProjectStructureSettings, /// Version Control (Git, Commit, Confirmation, Issue Navigation). pub vcs: VcsSettings, + /// Build, Execution, Deployment › Compiler (Build tool window). + pub build: BuildSettings, /// Build, Execution, Deployment › Console. pub console: ConsoleSettings, pub debugger: DebuggerSettings, @@ -508,6 +510,7 @@ impl Default for Settings { languages: LanguagesSettings::default(), project_structure: ProjectStructureSettings::default(), vcs: VcsSettings::default(), + build: BuildSettings::default(), console: ConsoleSettings::default(), debugger: DebuggerSettings::default(), run: RunSettings::default(), diff --git a/crates/ide-core/src/workflow_settings.rs b/crates/ide-core/src/workflow_settings.rs index 816a0281a..8c326ae92 100644 --- a/crates/ide-core/src/workflow_settings.rs +++ b/crates/ide-core/src/workflow_settings.rs @@ -317,6 +317,23 @@ pub struct SqlResolutionScope { pub schema: String, } +/// Build, Execution, Deployment › Compiler (Build tool window behaviour). +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)] +#[serde(default, rename_all = "camelCase")] +pub struct BuildSettings { + /// When to open the Build tool window: `always` | `onError` | `never`. + pub open_tool_window: String, + /// When to focus the Build tool window: `always` | `onError` | `never`. + pub focus_tool_window: String, +} + +impl Default for BuildSettings { + fn default() -> Self { + // Builds open the tool window without taking focus. + Self { open_tool_window: "always".into(), focus_tool_window: "never".into() } + } +} + /// Build, Execution, Deployment › Console. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)] #[serde(default, rename_all = "camelCase")] diff --git a/src/bindings.ts b/src/bindings.ts index c6ac9327f..01900b953 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -3299,6 +3299,14 @@ export type BuildResult = { messages: BuildMessage[], }; +/** Build, Execution, Deployment › Compiler (Build tool window behaviour). */ +export type BuildSettings = { + /** When to open the Build tool window: `always` | `onError` | `never`. */ + openToolWindow?: string, + /** When to focus the Build tool window: `always` | `onError` | `never`. */ + focusToolWindow?: string, +}; + export type BuildSystem = "maven" | "gradle" | "cargo" | "go" | "typescript" | "cmake" | "dotnet" | /** A Java project without a build tool, compiled from its Project Structure. */ "javac"; @@ -10954,6 +10962,8 @@ export type Settings_Deserialize = { projectStructure?: ProjectStructureSettings, /** Version Control (Git, Commit, Confirmation, Issue Navigation). */ vcs?: VcsSettings, + /** Build, Execution, Deployment › Compiler (Build tool window). */ + build?: BuildSettings, /** Build, Execution, Deployment › Console. */ console?: ConsoleSettings, debugger?: DebuggerSettings, @@ -11028,6 +11038,8 @@ export type Settings_Serialize = { projectStructure: ProjectStructureSettings, /** Version Control (Git, Commit, Confirmation, Issue Navigation). */ vcs: VcsSettings, + /** Build, Execution, Deployment › Compiler (Build tool window). */ + build: BuildSettings, /** Build, Execution, Deployment › Console. */ console: ConsoleSettings, debugger: DebuggerSettings, diff --git a/src/features/build/build.test.tsx b/src/features/build/build.test.tsx index 9746ca4ee..d7f278b03 100644 --- a/src/features/build/build.test.tsx +++ b/src/features/build/build.test.tsx @@ -165,7 +165,10 @@ describe("build feature", () => { provideNotificationService({ notify: (n) => void notes.push(n) }); fake = new FakeBackend(); setBuildBackend(fake); - useProject.setState({ project: { root: "/p", name: "demo" } as never }); + useProject.setState({ + project: { root: "/p", name: "demo" } as never, + settings: { build: { openToolWindow: "always", focusToolWindow: "never" } } as never, + }); setContext("projectOpen", true); dispose = activate(); }); @@ -173,7 +176,7 @@ describe("build feature", () => { afterEach(() => { dispose(); setBuildBackend(null); - useProject.setState({ project: null }); + useProject.setState({ project: null, settings: null }); setContext("projectOpen", false); setContext("run.cmakeBuild", null); }); @@ -305,6 +308,44 @@ describe("build feature", () => { ); }); + it('keeps successful builds hidden when Open Build tool window is "Never"', async () => { + useProject.setState({ + settings: { build: { openToolWindow: "never", focusToolWindow: "never" } } as never, + }); + const run = startBuild("build"); + await act(async () => {}); + expect(show).not.toHaveBeenCalled(); + await act(async () => { + fake.resolve(result([], true)); + await run; + }); + expect(show).not.toHaveBeenCalled(); + }); + + it('opens Build only on failure when Open is "Only on errors"', async () => { + useProject.setState({ + settings: { build: { openToolWindow: "onError", focusToolWindow: "onError" } } as never, + }); + const ok = startBuild("build"); + await act(async () => {}); + expect(show).not.toHaveBeenCalled(); + await act(async () => { + fake.resolve(result([], true)); + await ok; + }); + expect(show).not.toHaveBeenCalled(); + + const failed = startBuild("build"); + await act(async () => {}); + expect(show).not.toHaveBeenCalled(); + const messages = [err("/p/src/A.java", 3)]; + await act(async () => { + fake.resolve(result(messages, false)); + await failed; + }); + expect(show).toHaveBeenCalledExactlyOnceWith("build", true); + }); + it.each([ ["build.buildModule", { target: "/p/core", activate: false, wait: true }, "build", "/p/core"], ["build.buildArtifacts", { activate: false, wait: true }, "artifacts", null], diff --git a/src/features/build/store.ts b/src/features/build/store.ts index a266a4a6c..716356982 100644 --- a/src/features/build/store.ts +++ b/src/features/build/store.ts @@ -5,8 +5,9 @@ * Compiler messages reach the Problems view and editors as `build` * diagnostics, published (and cleared on the next build) by the backend. * - * Explicit builds show the tool window without taking focus. A failed build - * also selects the first error and opens its location in the editor. + * Build tool window open/focus follows Settings › Compiler (`build.openToolWindow` / + * `build.focusToolWindow`). Before-launch builds pass `activate: false` and stay + * hidden until a failure. A failed build also selects the first error and opens it. */ import { create } from "zustand"; import { Channel } from "@tauri-apps/api/core"; @@ -24,10 +25,30 @@ import { type RequestId, } from "@/platform/ipc"; import { useProject } from "@/platform/project"; +import { workflowSettings, type BuildToolWindowWhen } from "@/platform/workflowSettings"; import { maybeEditorService, notifications, toolWindowService } from "@/workbench/contributions"; import { cancelTask, removeTask, upsertTask, useTasks } from "@/workbench/tasks"; import { appendOutput, finishSummary, firstError, messageFiles, type BuildStatus, type ConsoleLine } from "./model"; +function whenMatches(when: BuildToolWindowWhen, reason: "start" | "error"): boolean { + return when === "always" || (when === "onError" && reason === "error"); +} + +/** + * Opens/focuses Build according to settings. `requested` is the caller's + * `activate` flag: false keeps before-launch builds hidden at start. + */ +function showBuildWindow(reason: "start" | "error", requested: boolean) { + if (reason === "start" && !requested) return; + const { openToolWindow, focusToolWindow } = workflowSettings().build; + if (!whenMatches(openToolWindow, reason)) return; + try { + toolWindowService().show("build", whenMatches(focusToolWindow, reason)); + } catch { + // No workbench (tests / settings window). + } +} + export const BUILD_TASK_ID = "build:compile"; export const BUILD_RUNNING = "build.running"; /** Outcome of the last build (`success` | `failed` | `cancelled`), e.g. for Run's "Build" before launch task. */ @@ -152,13 +173,7 @@ export async function startBuild( useBuildRun.setState({ ...INITIAL, request, kind, file, title: taskTitle, status: "running", files: previous }); setContext(BUILD_LAST_STATUS, null); setContext(BUILD_RUNNING, true); - if (activate) { - try { - toolWindowService().show("build", false); - } catch { - // No workbench (tests / settings window). - } - } + showBuildWindow("start", activate); upsertTask({ id: BUILD_TASK_ID, title: taskTitle, message: null, fraction: null, done: false, cancel }); return executeBuild( request, @@ -181,13 +196,7 @@ export async function startCompileFile(file: string, activate = true): Promise