дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-26 03:14:38 +02:00
fix(build): say how many lines the Build output's line cap discarded (#5982)
The Build tool window keeps the last 20,000 console lines and dropped older ones with nothing on screen, so a long build silently lost its beginning. The Build store now counts the lines the cap drops and the Build output shows the "N earlier lines were discarded" notice the Run and Debug consoles already show; the count resets with each new build. Co-authored-by: audichuang <[email protected]>
Цей коміт міститься в:
1 джерело
12eb2db641
коміт
ec02a121e9
5 files changed
+75
-7
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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" ? <MessageDetail message={node.message} /> : <BuildConsole rowHeight={rowHeight} />;
|
||||
const dropped = useBuildRun((s) => s.dropped);
|
||||
if (node?.kind === "message") return <MessageDetail message={node.message} />;
|
||||
return (
|
||||
<>
|
||||
{dropped > 0 && (
|
||||
<div className={styles.notice}>{tx`${dropped.toLocaleString()} earlier lines were discarded`}</div>
|
||||
)}
|
||||
<BuildConsole rowHeight={rowHeight} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function BuildView() {
|
||||
|
||||
@@ -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(<BuildView />);
|
||||
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"],
|
||||
|
||||
@@ -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 } : {}) })),
|
||||
);
|
||||
|
||||
@@ -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<BuildState>(() => INITIAL);
|
||||
|
||||
const TITLES: Record<BuildKind, string> = { 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<BuildState> {
|
||||
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({
|
||||
|
||||
Reference in new issue
Заблокувати користувача