Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/command/dev-call/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { quartoConfig } from "../../core/quarto.ts";
import { commands } from "../command.ts";
import { buildJsCommand } from "./build-artifacts/cmd.ts";
import { validateYamlCommand } from "./validate-yaml/cmd.ts";
import { showAstTraceCommand } from "./show-ast-trace/cmd.ts";

type CommandOptionInfo = {
name: string;
Expand Down Expand Up @@ -71,4 +72,5 @@ export const devCallCommand = new Command()
})
.command("cli-info", generateCliInfoCommand)
.command("validate-yaml", validateYamlCommand)
.command("build-artifacts", buildJsCommand);
.command("build-artifacts", buildJsCommand)
.command("show-ast-trace", showAstTraceCommand);
74 changes: 74 additions & 0 deletions src/command/dev-call/show-ast-trace/cmd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* cmd.ts
*
* Copyright (C) 2025 Posit Software, PBC
*/

import { Command } from "cliffy/command/mod.ts";
import { quartoCacheDir } from "../../../core/appdirs.ts";
import { quartoConfig } from "../../../core/quarto.ts";
import {
ensureDir,
moveSync,
safeRemoveDirSync,
} from "../../../deno_ral/fs.ts";
import { basename, dirname, join } from "../../../deno_ral/path.ts";
import { copy } from "fs/copy";
import { resourcePath } from "../../../core/resources.ts";
import { execProcess } from "../../../core/process.ts";

const ensureTracingToolsCopied = async () => {
const cacheDir = quartoCacheDir();
const tracingDir = `${cacheDir}/ast-tracing`;
await ensureDir(tracingDir);
safeRemoveDirSync(join(tracingDir, "qmd"), cacheDir);
await copy(
resourcePath(join("tools", "ast-tracing")),
join(tracingDir, "qmd"),
);
return join(tracingDir, "qmd");
};

export const showAstTraceCommand = new Command()
.name("show-ast-trace")
.hidden()
.arguments("<arguments...>")
.description(
"Renders the document with AST tracing enabled and then shows the debugging output.\n\n",
)
.action(async (_options: unknown, input: string, ...args: string[]) => {
const toolsPath = await ensureTracingToolsCopied();

const dir = dirname(input);
const base = basename(input, ".qmd");
const traceName = join(dir, `${base}-quarto-ast-trace.json`);

const renderOpts = {
cmd: "quarto",
env: {
"QUARTO_TRACE_FILTERS": traceName,
},
args: [
"render",
input,
...args,
"--quiet",
],
};
const _renderResult = await execProcess(renderOpts);
// we don't check for errors here because we want to show the trace even if
// the render fails

moveSync(traceName, join(toolsPath, basename(traceName)));

const _previewResult = await execProcess({
cmd: "quarto",
cwd: toolsPath,
args: [
"preview",
"trace-viewer.qmd",
"-M",
`trace_1:${basename(traceName)}`,
],
});
});
File renamed without changes.
8 changes: 0 additions & 8 deletions tools/trace-viewer/index.html

This file was deleted.

Loading