tinymist icon indicating copy to clipboard operation
tinymist copied to clipboard

`tinymist preview` ignores `TYPST_ROOT` environment variable

Open jfly opened this issue 4 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Platform

x64 Linux (linux-x64, Most Common)

Editor

CLI (Command Line Interface)

Editor Version

N/A, I'm just using the cli

Describe the bug

tinymist preview does not honor the TYPST_ROOT environment variable.

I believe the relevant code is here: https://github.com/Myriad-Dreamin/tinymist/blob/v0.14.0/crates/tinymist-world/src/args.rs#L70-L72, you can see that it does not check the environment.

I'm not sure how this relates to this code, which does check for the TYPST_ROOT environment variable.

Regardless, I can fix this issue with the following patch:

diff --git a/crates/tinymist-world/src/args.rs b/crates/tinymist-world/src/args.rs
index 02377fe5..1af6cb12 100644
--- a/crates/tinymist-world/src/args.rs
+++ b/crates/tinymist-world/src/args.rs
@@ -68,7 +68,7 @@ pub struct CompileOnceArgs {
     pub input: Option<String>,
 
     /// Configure the project root (for absolute paths).
-    #[clap(long = "root", value_name = "DIR")]
+    #[clap(long = "root", value_name = "DIR", env = "TYPST_ROOT")]
     pub root: Option<PathBuf>,
 
     /// Specify the font related arguments.

Server Logs

N/A, just using the CLI

Browser Logs

N/A, just using the CLI

Additional context

No response

jfly avatar Nov 19 '25 16:11 jfly

This is intended because passing root via env is viewed as an anti-pattern.

Myriad-Dreamin avatar Nov 19 '25 18:11 Myriad-Dreamin

per some previous discussion, tinymist-cli could respect TYPST_ROOT to align with typst-cli, but lsp will deliberately ignore it, while I still say "passing root via env is viewed as an anti-pattern", https://github.com/Myriad-Dreamin/tinymist/pull/1521

Myriad-Dreamin avatar Nov 19 '25 18:11 Myriad-Dreamin

Ah, sorry, I hadn't seen #1521. A couple questions:

  1. What do you mean when you say "lsp will deliberately ignore it"? I tried the diff above locally and things work: both previews and other LSP behavior work.
  2. What is the non anti-pattern way to configure typst with an alternate root? I'd like this to be a per-project thing rather than a systemwide thing.

jfly avatar Nov 19 '25 18:11 jfly