Skip to content

Commit 4e6bbf9

Browse files
authored
Merge pull request #12778 from quarto-dev/feature/dev-call-view-ast-trace
feature - dev-call show-ast-trace
2 parents 3e8f1e6 + 94727b4 commit 4e6bbf9

File tree

11 files changed

+77
-9
lines changed

11 files changed

+77
-9
lines changed

src/command/dev-call/cmd.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { quartoConfig } from "../../core/quarto.ts";
33
import { commands } from "../command.ts";
44
import { buildJsCommand } from "./build-artifacts/cmd.ts";
55
import { validateYamlCommand } from "./validate-yaml/cmd.ts";
6+
import { showAstTraceCommand } from "./show-ast-trace/cmd.ts";
67

78
type CommandOptionInfo = {
89
name: string;
@@ -71,4 +72,5 @@ export const devCallCommand = new Command()
7172
})
7273
.command("cli-info", generateCliInfoCommand)
7374
.command("validate-yaml", validateYamlCommand)
74-
.command("build-artifacts", buildJsCommand);
75+
.command("build-artifacts", buildJsCommand)
76+
.command("show-ast-trace", showAstTraceCommand);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* cmd.ts
3+
*
4+
* Copyright (C) 2025 Posit Software, PBC
5+
*/
6+
7+
import { Command } from "cliffy/command/mod.ts";
8+
import { quartoCacheDir } from "../../../core/appdirs.ts";
9+
import { quartoConfig } from "../../../core/quarto.ts";
10+
import {
11+
ensureDir,
12+
moveSync,
13+
safeRemoveDirSync,
14+
} from "../../../deno_ral/fs.ts";
15+
import { basename, dirname, join } from "../../../deno_ral/path.ts";
16+
import { copy } from "fs/copy";
17+
import { resourcePath } from "../../../core/resources.ts";
18+
import { execProcess } from "../../../core/process.ts";
19+
20+
const ensureTracingToolsCopied = async () => {
21+
const cacheDir = quartoCacheDir();
22+
const tracingDir = `${cacheDir}/ast-tracing`;
23+
await ensureDir(tracingDir);
24+
safeRemoveDirSync(join(tracingDir, "qmd"), cacheDir);
25+
await copy(
26+
resourcePath(join("tools", "ast-tracing")),
27+
join(tracingDir, "qmd"),
28+
);
29+
return join(tracingDir, "qmd");
30+
};
31+
32+
export const showAstTraceCommand = new Command()
33+
.name("show-ast-trace")
34+
.hidden()
35+
.arguments("<arguments...>")
36+
.description(
37+
"Renders the document with AST tracing enabled and then shows the debugging output.\n\n",
38+
)
39+
.action(async (_options: unknown, input: string, ...args: string[]) => {
40+
const toolsPath = await ensureTracingToolsCopied();
41+
42+
const dir = dirname(input);
43+
const base = basename(input, ".qmd");
44+
const traceName = join(dir, `${base}-quarto-ast-trace.json`);
45+
46+
const renderOpts = {
47+
cmd: "quarto",
48+
env: {
49+
"QUARTO_TRACE_FILTERS": traceName,
50+
},
51+
args: [
52+
"render",
53+
input,
54+
...args,
55+
"--quiet",
56+
],
57+
};
58+
const _renderResult = await execProcess(renderOpts);
59+
// we don't check for errors here because we want to show the trace even if
60+
// the render fails
61+
62+
moveSync(traceName, join(toolsPath, basename(traceName)));
63+
64+
const _previewResult = await execProcess({
65+
cmd: "quarto",
66+
cwd: toolsPath,
67+
args: [
68+
"preview",
69+
"trace-viewer.qmd",
70+
"-M",
71+
`trace_1:${basename(traceName)}`,
72+
],
73+
});
74+
});
File renamed without changes.

tools/trace-viewer/index.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)