nvarner / typst-lsp

A brand-new language server for Typst, plus a VS Code extension
MIT License
1.13k stars 78 forks source link

Cannot import .typ file from outer folder in workspace of VSCode anymore. #255

Open ivaquero opened 10 months ago

ivaquero commented 10 months ago

Issue

Logs

Cannot import .typ file from outer folder in workspace of VSCode anymore after update to 0.9+.

image
[Error - 3:10:35 AM] src/server/lsp.rs:246 { message = could not handle source save; 
err = failed to generate document after compilation; 
uri = file://~/Documents/book-linear-algebra/09-%E5%87%A0%E4%BD%95%E5%8F%98%E6%8D%A2.typ; }
nvarner commented 10 months ago

Were you on 0.7 or earlier before updating to 0.9? If so, I think this is an (admittedly inconvenient) intentional behavior of Typst to keep files from importing other files outside the current package: https://github.com/typst/typst/issues/1664#issuecomment-1622395258

In the LSP, root is set based on your open workspace folders. If you open the parent directory, I think this will work as you expect. Alternatively, make typst-styles a local package. If those fixes don't work, or you were already running 0.8 or 0.9, then this is a bug.

ivaquero commented 10 months ago

I updated typst and typst-lsp at the same time, so I am not sure which this bug is for. My codes worked well before the update.

I guess you are right, it's due to how --root treating the path. I probably have to accept your suggestion though I am reluctant to make my template as a local package because more than 5 folders are using it, and it contains multiple files.

ivaquero commented 10 months ago

I tried to compile using CLI, but it says error: input file must be contained in project root.. It seems this bug is on the typst side.

ivaquero commented 10 months ago

Hello again, @nvarner. Could you please consider adding a --root option in the VSCode Extension?

Myriad-Dreamin commented 10 months ago

@ivaquero https://github.com/nvarner/typst-lsp/blob/fc6af7505cd48e4fe4fefaef9bac73aa64d05369/editors/vscode/package.json#L39-L47 Does this option help?

ivaquero commented 10 months ago

Thank you so much! @Myriad-Dreamin. I misunderstood the rootPath.

ivaquero commented 10 months ago

I tried to set "typst-lsp.rootPath": ".." or "typst-lsp.rootPath": ${HOME}/Documents, but it still doesn't work. Is the rootPath option is in accordance with --root in the CLI? For the CLI, typst compile --root=".." works well.

willismonroe commented 10 months ago

I just tried adding "typst-lsp.rootPath": "/", to my settings.json and it seems not to respect the change.

taooceros commented 10 months ago

Same issue

anesthetice commented 4 months ago

same issue as well, also tried setting my TYPST_ROOT env-var but that doesn't seem to work either