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.
TypeScript code-editorcross-platformdapdatabase-clientdebuggerdesktop-appdeveloper-toolsgithttp-clientideintellijlsprusttauriterminal
feat(build): link file locations in the build console (#1869)
arookieofc1f969694a0e6
diff --git a/src/features/build/Build.module.css b/src/features/build/Build.module.cssindex a6a6c6fe3..962511197 100644--- a/src/features/build/Build.module.css+++ b/src/features/build/Build.module.css@@ -113,6 +113,17 @@color: var(--fg-subtle);font-style: italic;}+.link {+ color: var(--link);+ text-decoration: underline;+ text-decoration-color: color-mix(in srgb, var(--link) 45%, transparent);+ text-underline-offset: 2px;+ cursor: pointer;+}+.link:hover {+ color: var(--link-hover);+ text-decoration-color: currentColor;+}.titleButton {width: 30px;height: 30px;diff --git a/src/features/build/BuildView.tsx b/src/features/build/BuildView.tsxindex 8448b1e05..5a64a330e 100644--- a/src/features/build/BuildView.tsx+++ b/src/features/build/BuildView.tsx@@ -5,7 +5,7 @@* its source (as IDEA: selection shows, navigation jumps).*/import { copySelectionOnKeyDown } from "@/ui/selectableText";-import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent, type ReactNode } from "react";import clsx from "clsx";import { useVirtualizer } from "@tanstack/react-virtual";import { basename, relativeDir, useProject } from "@/platform/project";@@ -34,7 +34,10 @@ import {rootNode,type BuildNode,type BuildStatus,+ type ConsoleLine,} from "./model";+import { findOutputLinks, type OutputLink } from "@/features/run/links";+import { openTarget, openUrl } from "@/features/run/navigate";import { navigateToMessage, rerunBuild, selectBuildNode, useBuildRun } from "./store";import styles from "./Build.module.css";import { tx } from "@/platform/i18n";@@ -201,7 +204,45 @@ function BuildTree() {const LINE_HEIGHT = 20;+/**+ * One console line: file locations and URLs (compiler diagnostics, stack+ * frames) are links, resolved against the directory of the step that printed+ * the line (Maven reactor modules run in their own directory), then the+ * project root and a name search as in the run console.+ */+function ConsoleLineText({ line, root }: { line: ConsoleLine; root: string }) {+ const links = useMemo(() => (line.kind === "system" ? [] : findOutputLinks(line.text)), [line.text, line.kind]);+ const activate = (e: MouseEvent, link: OutputLink) => {+ e.preventDefault();+ if (window.getSelection()?.toString()) return;+ if (link.kind === "url") void openUrl(link.url);+ else void openTarget(link.target, line.cwd ?? root);+ };+ if (!links.length) return <>{line.text}</>;+ const out: ReactNode[] = [];+ let pos = 0;+ for (const link of links) {+ if (link.start > pos) out.push(line.text.slice(pos, link.start));+ out.push(+ <a+ key={link.start}+ href={link.kind === "url" ? link.url : undefined}+ className={styles.link}+ onClick={(e) => activate(e, link)}+ role="link"+ tabIndex={-1}+ >+ {line.text.slice(link.start, link.end)}+ </a>,+ );+ pos = link.end;+ }+ out.push(line.text.slice(pos));+ return <>{out}</>;+}+function BuildConsole() {+ const root = useProject((s) => s.project?.root ?? "/");const lines = useBuildRun((s) => s.lines);const ref = useRef<HTMLDivElement>(null);const stick = useRef(true);@@ -236,7 +277,7 @@ function BuildConsole() {className={clsx(styles.line, styles[line.kind])}style={{ transform: `translateY(${v.start}px)` }}>- {line.text || " "}+ <ConsoleLineText line={line} root={root} /></div>);})}diff --git a/src/features/build/model.ts b/src/features/build/model.tsindex 79bb341d5..eb0c9cc77 100644--- a/src/features/build/model.ts+++ b/src/features/build/model.ts@@ -9,16 +9,28 @@ export type BuildStatus = "running" | "success" | "failed" | "cancelled";export interface ConsoleLine {text: string;kind: "out" | "err" | "system";+ /** Directory of the step that printed the line (links resolve against it). */+ cwd?: string | null;}/** Oldest lines are dropped beyond this (IDEA's console cycle buffer). */export const MAX_CONSOLE_LINES = 20_000;-/** Appends streamed text (one or more `\n`-terminated lines) to `lines`. */-export function appendOutput(lines: ConsoleLine[], text: string, kind: ConsoleLine["kind"]): ConsoleLine[] {+/**+ * Appends streamed text (one or more `\n`-terminated lines) to `lines`.+ * `cwd` is the running step's directory (a step may append several chunks).+ */+export function appendOutput(+ lines: ConsoleLine[],+ text: string,+ kind: ConsoleLine["kind"],+ cwd?: string,+): ConsoleLine[] {const parts = text.split("\n");if (parts.at(-1) === "") parts.pop();- const next = lines.concat(parts.map((t) => ({ text: t.replace(/\r$/, ""), kind })));+ const next = lines.concat(+ parts.map((t) => ({ text: t.replace(/\r$/, ""), kind, ...(cwd !== undefined ? { cwd } : {}) })),+ );return next.length > MAX_CONSOLE_LINES ? next.slice(next.length - MAX_CONSOLE_LINES) : next;}diff --git a/src/features/build/store.ts b/src/features/build/store.tsindex 17bbaf63c..84454e792 100644--- a/src/features/build/store.ts+++ b/src/features/build/store.ts@@ -78,6 +78,8 @@ export interface BuildState {files: string[];/** Key of the selected tree node (a message node shows its detail beside the tree). */selected: string | null;+ /** Directory of the running step (console lines after it resolve paths against it). */+ stepCwd: string | null;}const INITIAL: BuildState = {@@ -93,6 +95,7 @@ const INITIAL: BuildState = {lines: [],files: [],selected: null,+ stepCwd: null,};export const useBuildRun = create<BuildState>(() => INITIAL);@@ -103,11 +106,11 @@ const TITLES: Record<BuildKind, string> = { build: "Build", rebuild: "Rebuild",export function applyBuildEvent(s: BuildState, e: BuildEvent): Partial<BuildState> {switch (e.kind) {case "started":- return { title: e.title, system: e.system };+ return { title: e.title, system: e.system, stepCwd: null };case "step":- return { lines: appendOutput(s.lines, `${e.command}\n`, "system") };+ return { stepCwd: e.cwd, lines: appendOutput(s.lines, `${e.command}\n`, "system", e.cwd) };case "output":- return { lines: appendOutput(s.lines, e.text, e.stderr ? "err" : "out") };+ return { lines: appendOutput(s.lines, e.text, e.stderr ? "err" : "out", s.stepCwd ?? undefined) };case "message":return { messages: [...s.messages, e.message] };case "progress":diff --git a/src/features/run/links.test.ts b/src/features/run/links.test.tsindex a24ad7a32..a62e2f36e 100644--- a/src/features/run/links.test.ts+++ b/src/features/run/links.test.ts@@ -68,6 +68,26 @@ describe("findOutputLinks", () => {expect(files("src/App.tsx(14,3): error TS2322")[0]).toMatchObject({ path: "src/App.tsx", line: 14, col: 3 });});+ it("maven diagnostics [ERROR] path:[line,col]", () => {+ expect(files("[ERROR] /p/src/main/java/a/A.java:[12,5] cannot find symbol")[0]).toEqual({+ path: "/p/src/main/java/a/A.java",+ line: 12,+ col: 5,+ resolve: "path",+ text: "/p/src/main/java/a/A.java:[12,5]",+ });+ expect(files("[WARNING] src/main/java/B.java:[3,8] [deprecation] old() has been deprecated")[0]).toMatchObject({+ path: "src/main/java/B.java",+ line: 3,+ col: 8,+ });+ expect(files("[ERROR] C:\\proj\\A.java:[7,1] error: x")[0]).toMatchObject({+ path: "C:\\proj\\A.java",+ line: 7,+ col: 1,+ });+ });+it("URLs, trimming trailing punctuation", () => {const links = findOutputLinks("Listening on http://localhost:8080/api. (see https://x.dev/a_(b))");expect(links.filter((l) => l.kind === "url").map((l) => (l.kind === "url" ? l.url : ""))).toEqual([diff --git a/src/features/run/links.ts b/src/features/run/links.tsindex cd195ecb5..745576943 100644--- a/src/features/run/links.ts+++ b/src/features/run/links.ts@@ -89,9 +89,10 @@ const PATTERNS: Pattern[] = [};},},- // Generic `path:line` (Go `file.go:12`, Rust `--> src/main.rs:10`, gcc, eslint…) and `path(line,col)`.+ // Generic `path:line` (Go `file.go:12`, Rust `--> src/main.rs:10`, gcc, eslint…),+ // `path(line,col)` (tsc) and Maven's `path:[line,col]` (`[ERROR] /p/A.java:[12,5] msg`).{- re: new RegExp(String.raw`(${PATH})(?::(\d+)(?::(\d+))?|\((\d+)(?:,(\d+))?\))`, "dg"),+ re: new RegExp(String.raw`(${PATH})(?::\[?(\d+)(?::(\d+)|,(\d+)\])?|\((\d+)(?:,(\d+))?\))`, "dg"),build: (m) => {if (m.index! > 0 && /[\w/.~-]/.test(m.input![m.index! - 1]!)) return null;const [start, end] = [m.index!, m.index! + m[0].length];@@ -99,7 +100,7 @@ const PATTERNS: Pattern[] = [kind: "file",start,end,- target: { path: m[1]!, line: num(m[2] ?? m[4]), col: num(m[3] ?? m[5]), resolve: "path" },+ target: { path: m[1]!, line: num(m[2] ?? m[5]), col: num(m[3] ?? m[4] ?? m[6]), resolve: "path" },};},},