diff --git a/src/features/build/Build.module.css b/src/features/build/Build.module.css
index 1165dbbc6..91df03131 100644
--- a/src/features/build/Build.module.css
+++ b/src/features/build/Build.module.css
@@ -18,6 +18,16 @@
flex: 1;
min-height: 0;
}
+/* Matches the Run console's notice; sits above the output in the console font's pane. */
+.pane > .notice {
+ flex: none;
+ padding: 4px 12px;
+ font-family: var(--font-ui);
+ font-size: var(--fs-small);
+ line-height: normal;
+ color: var(--fg-subtle);
+ border-bottom: 1px solid var(--border);
+}
.row {
display: flex;
diff --git a/src/features/build/BuildView.tsx b/src/features/build/BuildView.tsx
index 8554fc1f1..9a4ce2838 100644
--- a/src/features/build/BuildView.tsx
+++ b/src/features/build/BuildView.tsx
@@ -346,7 +346,16 @@ function BuildOutput({ rowHeight }: { rowHeight: number }) {
const selected = useBuildRun((s) => s.selected);
const messages = useBuildRun((s) => s.messages);
const node = useMemo(() => (selected ? findNode(messages, selected) : undefined), [selected, messages]);
- return node?.kind === "message" ? : ;
+ const dropped = useBuildRun((s) => s.dropped);
+ if (node?.kind === "message") return ;
+ return (
+ <>
+ {dropped > 0 && (
+
{tx`${dropped.toLocaleString()} earlier lines were discarded`}
+ )}
+
+ >
+ );
}
export function BuildView() {
diff --git a/src/features/build/build.test.tsx b/src/features/build/build.test.tsx
index ee66a7656..03152e432 100644
--- a/src/features/build/build.test.tsx
+++ b/src/features/build/build.test.tsx
@@ -324,6 +324,32 @@ describe("build feature", () => {
expect(show).toHaveBeenCalledTimes(3);
});
+ it("says how many earlier lines the console line cap discarded", async () => {
+ const run = startBuild("build");
+ await act(async () => {});
+ render();
+ await act(async () => {
+ fake.emit!({ kind: "started", system: "maven", title: "demo" });
+ fake.emit!({ kind: "output", text: "line\n".repeat(MAX_CONSOLE_LINES + 5_000), stderr: false });
+ await new Promise((r) => setTimeout(r, 30));
+ });
+ expect(useBuildRun.getState().lines).toHaveLength(MAX_CONSOLE_LINES);
+ expect(screen.getByText("5,000 earlier lines were discarded")).toBeInTheDocument();
+ await act(async () => {
+ fake.resolve(result([], true));
+ await run;
+ });
+
+ // The next build starts with an empty console and no notice.
+ const second = startBuild("build");
+ await act(async () => {});
+ expect(screen.queryByText(/earlier lines were discarded/)).not.toBeInTheDocument();
+ await act(async () => {
+ fake.resolve(result([], true));
+ await second;
+ });
+ });
+
it.each([
["build.buildProject", undefined],
["build.buildModule", "/p/core/src/A.java"],
diff --git a/src/features/build/model.ts b/src/features/build/model.ts
index eb0c9cc77..08e8816d3 100644
--- a/src/features/build/model.ts
+++ b/src/features/build/model.ts
@@ -16,6 +16,13 @@ export interface ConsoleLine {
/** Oldest lines are dropped beyond this (IDEA's console cycle buffer). */
export const MAX_CONSOLE_LINES = 20_000;
+/** The lines of streamed text (one or more `\n`-terminated lines). */
+export function outputLines(text: string): string[] {
+ const parts = text.split("\n");
+ if (parts.at(-1) === "") parts.pop();
+ return parts;
+}
+
/**
* Appends streamed text (one or more `\n`-terminated lines) to `lines`.
* `cwd` is the running step's directory (a step may append several chunks).
@@ -26,8 +33,7 @@ export function appendOutput(
kind: ConsoleLine["kind"],
cwd?: string,
): ConsoleLine[] {
- const parts = text.split("\n");
- if (parts.at(-1) === "") parts.pop();
+ const parts = outputLines(text);
const next = lines.concat(
parts.map((t) => ({ text: t.replace(/\r$/, ""), kind, ...(cwd !== undefined ? { cwd } : {}) })),
);
diff --git a/src/features/build/store.ts b/src/features/build/store.ts
index e040ffbac..ab2ccbfd5 100644
--- a/src/features/build/store.ts
+++ b/src/features/build/store.ts
@@ -28,7 +28,15 @@ import { useProject } from "@/platform/project";
import { workflowSettings, type BuildToolWindowWhen } from "@/platform/workflowSettings";
import { maybeEditorService, notifications, notifyBuildCompleted, toolWindowService } from "@/workbench/contributions";
import { cancelTask, removeTask, upsertTask, useTasks } from "@/workbench/tasks";
-import { appendOutput, finishSummary, firstError, messageFiles, type BuildStatus, type ConsoleLine } from "./model";
+import {
+ appendOutput,
+ finishSummary,
+ firstError,
+ messageFiles,
+ outputLines,
+ type BuildStatus,
+ type ConsoleLine,
+} from "./model";
function whenMatches(when: BuildToolWindowWhen, reason: "start" | "error"): boolean {
return when === "always" || (when === "onError" && reason === "error");
@@ -109,6 +117,8 @@ export interface BuildState {
durationMs: number | null;
messages: BuildMessage[];
lines: ConsoleLine[];
+ /** Lines dropped from the front by `MAX_CONSOLE_LINES`. */
+ dropped: number;
/** Files with diagnostics from the last build. */
files: string[];
/** Key of the selected tree node (a message node shows its detail beside the tree). */
@@ -129,6 +139,7 @@ const INITIAL: BuildState = {
durationMs: null,
messages: [],
lines: [],
+ dropped: 0,
files: [],
selected: null,
stepCwd: null,
@@ -138,15 +149,21 @@ export const useBuildRun = create(() => INITIAL);
const TITLES: Record = { build: "Build", rebuild: "Rebuild", artifacts: "Build Artifacts" };
+/** Appends console output, counting the lines the cap drops from the front. */
+function withOutput(s: BuildState, text: string, kind: ConsoleLine["kind"], cwd?: string) {
+ const lines = appendOutput(s.lines, text, kind, cwd);
+ return { lines, dropped: s.dropped + s.lines.length + outputLines(text).length - lines.length };
+}
+
/** Applies one streamed event (pure; batched by the caller). */
export function applyBuildEvent(s: BuildState, e: BuildEvent): Partial {
switch (e.kind) {
case "started":
return { title: e.title, system: e.system, stepCwd: null };
case "step":
- return { stepCwd: e.cwd, lines: appendOutput(s.lines, `${e.command}\n`, "system", e.cwd) };
+ return { stepCwd: e.cwd, ...withOutput(s, `${e.command}\n`, "system", e.cwd) };
case "output":
- return { lines: appendOutput(s.lines, e.text, e.stderr ? "err" : "out", s.stepCwd ?? undefined) };
+ return withOutput(s, e.text, e.stderr ? "err" : "out", s.stepCwd ?? undefined);
case "message":
return { messages: [...s.messages, e.message] };
case "progress":
@@ -302,7 +319,7 @@ async function executeBuild(
status: "failed",
files: [],
message: null,
- lines: appendOutput(s.lines, `${text}\n`, "err"),
+ ...withOutput(s, `${text}\n`, "err"),
messages: [...s.messages, { severity: "error", text, path: null, range: null, code: null }],
}));
notifications().notify({