mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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>
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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],
|
||||
|
||||
+28
-23
@@ -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<B
|
||||
useBuildRun.setState({ ...INITIAL, request, kind: null, 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,
|
||||
@@ -310,15 +319,11 @@ export function selectBuildNode(key: string | null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A failed build activates the tool window without focusing it, selects the
|
||||
* first error and navigates to it, as IDEA does by default.
|
||||
* A failed build may open/focus the tool window (per settings), then selects
|
||||
* the first error and navigates to it, as IDEA does by default.
|
||||
*/
|
||||
function showFailure() {
|
||||
try {
|
||||
toolWindowService().show("build", false);
|
||||
} catch {
|
||||
// No workbench (tests / settings window).
|
||||
}
|
||||
showBuildWindow("error", true);
|
||||
const first = firstError(useBuildRun.getState().messages);
|
||||
if (!first) return;
|
||||
selectBuildNode(first.key);
|
||||
|
||||
@@ -141,7 +141,47 @@ function TooltipDelayRow() {
|
||||
);
|
||||
}
|
||||
|
||||
const BUILD_WINDOW_WHEN = [
|
||||
{ value: "always", label: "Always" },
|
||||
{ value: "onError", label: "Only on errors" },
|
||||
{ value: "never", label: "Never" },
|
||||
];
|
||||
|
||||
export const EXECUTION_PAGES: PageSpec[] = [
|
||||
{
|
||||
id: "build.compiler",
|
||||
title: "Compiler",
|
||||
group: BUILD_GROUP,
|
||||
order: 355,
|
||||
projectScope: true,
|
||||
keywords: [
|
||||
"Build tool window",
|
||||
"Open Build tool window",
|
||||
"Focus Build tool window",
|
||||
"automatic build",
|
||||
"before launch",
|
||||
],
|
||||
sections: [
|
||||
{
|
||||
options: [
|
||||
{
|
||||
kind: "select",
|
||||
key: "build.openToolWindow",
|
||||
label: "Open Build tool window",
|
||||
options: BUILD_WINDOW_WHEN,
|
||||
hint: "Automatic and explicit builds. Run/Debug before-launch builds stay hidden until they fail.",
|
||||
},
|
||||
{
|
||||
kind: "select",
|
||||
key: "build.focusToolWindow",
|
||||
label: "Focus Build tool window",
|
||||
options: BUILD_WINDOW_WHEN,
|
||||
hint: "When Build opens, whether it takes keyboard focus from the editor.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "build.cmake",
|
||||
title: "CMake",
|
||||
|
||||
@@ -2674,5 +2674,10 @@
|
||||
"Run from Parent Directory of Current File ({shown})": "Run from Parent Directory of Current File ({shown})",
|
||||
"Detect commands that can be run right from Markdown files": "Detect commands that can be run right from Markdown files",
|
||||
"Run commands from": "Run commands from",
|
||||
"Markdown file parent directory": "Markdown file parent directory"
|
||||
"Markdown file parent directory": "Markdown file parent directory",
|
||||
"Open Build tool window": "Open Build tool window",
|
||||
"Focus Build tool window": "Focus Build tool window",
|
||||
"Only on errors": "Only on errors",
|
||||
"Automatic and explicit builds. Run/Debug before-launch builds stay hidden until they fail.": "Automatic and explicit builds. Run/Debug before-launch builds stay hidden until they fail.",
|
||||
"When Build opens, whether it takes keyboard focus from the editor.": "When Build opens, whether it takes keyboard focus from the editor."
|
||||
}
|
||||
|
||||
@@ -9049,5 +9049,10 @@
|
||||
"Run from Parent Directory of Current File ({shown})": "从当前文件的父目录运行({shown})",
|
||||
"Detect commands that can be run right from Markdown files": "检测可以直接从 Markdown 文件运行的命令",
|
||||
"Run commands from": "运行命令的目录",
|
||||
"Markdown file parent directory": "Markdown 文件的父目录"
|
||||
"Markdown file parent directory": "Markdown 文件的父目录",
|
||||
"Open Build tool window": "打开构建工具窗口",
|
||||
"Focus Build tool window": "聚焦构建工具窗口",
|
||||
"Only on errors": "仅在出错时",
|
||||
"Automatic and explicit builds. Run/Debug before-launch builds stay hidden until they fail.": "自动构建与手动构建均适用。运行/调试的启动前构建在失败前保持隐藏。",
|
||||
"When Build opens, whether it takes keyboard focus from the editor.": "构建窗口打开时,是否从编辑器夺取键盘焦点。"
|
||||
}
|
||||
|
||||
@@ -27,6 +27,17 @@ describe("validateWorkflow", () => {
|
||||
expect(commit("yes")).toBeNull();
|
||||
});
|
||||
|
||||
it("defaults Build tool window open/focus and rejects unknown values", () => {
|
||||
expect(DEFAULT_WORKFLOW.build).toEqual({ openToolWindow: "always", focusToolWindow: "never" });
|
||||
expect(validateWorkflow({ build: { openToolWindow: "onError", focusToolWindow: "always" } }).build).toEqual({
|
||||
openToolWindow: "onError",
|
||||
focusToolWindow: "always",
|
||||
});
|
||||
expect(validateWorkflow({ build: { openToolWindow: "sometimes", focusToolWindow: 1 } }).build).toEqual(
|
||||
DEFAULT_WORKFLOW.build,
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to defaults for missing or malformed values", () => {
|
||||
expect(validateWorkflow(undefined)).toEqual(DEFAULT_WORKFLOW);
|
||||
const v = validateWorkflow({
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DEFAULT_REMOTE, validateRemote, type RemoteSettings } from "./remoteSet
|
||||
|
||||
export type UpdateMethod = "merge" | "rebase";
|
||||
export type IncomingCheck = "auto" | "always" | "never";
|
||||
export type BuildToolWindowWhen = "always" | "onError" | "never";
|
||||
export type VcsConfirm = "ask" | "silently" | "never";
|
||||
export type PatchCreated = "ask" | "no" | "reveal";
|
||||
export type CursorShape = "block" | "underline" | "bar";
|
||||
@@ -99,6 +100,11 @@ export interface LogLevelColorsValid {
|
||||
trace: string;
|
||||
}
|
||||
|
||||
export interface BuildSettingsValid {
|
||||
openToolWindow: BuildToolWindowWhen;
|
||||
focusToolWindow: BuildToolWindowWhen;
|
||||
}
|
||||
|
||||
export interface ConsoleSettingsValid {
|
||||
softWrap: boolean;
|
||||
overrideBuffer: boolean;
|
||||
@@ -222,6 +228,7 @@ export interface AgentRunSettingsValid {
|
||||
|
||||
export interface WorkflowSettings extends RemoteSettings {
|
||||
vcs: VcsSettingsValid;
|
||||
build: BuildSettingsValid;
|
||||
console: ConsoleSettingsValid;
|
||||
debugger: DebuggerSettingsValid;
|
||||
run: RunSettingsValid;
|
||||
@@ -321,6 +328,10 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = {
|
||||
issueNavigation: [],
|
||||
mappings: { excluded: [], added: [] },
|
||||
},
|
||||
build: {
|
||||
openToolWindow: "always",
|
||||
focusToolWindow: "never",
|
||||
},
|
||||
console: {
|
||||
softWrap: false,
|
||||
overrideBuffer: true,
|
||||
@@ -499,6 +510,16 @@ export function validateVcs(raw: unknown): VcsSettingsValid {
|
||||
};
|
||||
}
|
||||
|
||||
export function validateBuild(raw: unknown): BuildSettingsValid {
|
||||
const d = DEFAULT_WORKFLOW.build;
|
||||
const v = obj(raw);
|
||||
const when = ["always", "onError", "never"] as const;
|
||||
return {
|
||||
openToolWindow: oneOf(v.openToolWindow, when, d.openToolWindow),
|
||||
focusToolWindow: oneOf(v.focusToolWindow, when, d.focusToolWindow),
|
||||
};
|
||||
}
|
||||
|
||||
export function validateConsole(raw: unknown): ConsoleSettingsValid {
|
||||
const d = DEFAULT_WORKFLOW.console;
|
||||
const v = obj(raw);
|
||||
@@ -669,6 +690,7 @@ export function validateWorkflow(raw: unknown): WorkflowSettings {
|
||||
const root = obj(raw);
|
||||
return {
|
||||
vcs: validateVcs(root.vcs),
|
||||
build: validateBuild(root.build),
|
||||
console: validateConsole(root.console),
|
||||
debugger: validateDebugger(root.debugger),
|
||||
run: validateRun(root.run),
|
||||
|
||||
Reference in New Issue
Block a user