typst-lsp icon indicating copy to clipboard operation
typst-lsp copied to clipboard

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

Open ivaquero opened this issue 1 year ago • 10 comments

  • Component:
    • VSCode Extension
  • Extension version: 0.9.4
  • LSP version: 0.9.4
  • OS version and name: macOS 13.5 Ventura
  • I am on the latest stable version of the extension/LSP.
  • I have searched the issues of this repo and believe that this is not a duplicate.

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; }

ivaquero avatar Aug 19 '23 19:08 ivaquero

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.

nvarner avatar Aug 19 '23 19:08 nvarner

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 avatar Aug 19 '23 19:08 ivaquero

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 avatar Aug 19 '23 20:08 ivaquero

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

ivaquero avatar Aug 19 '23 20:08 ivaquero

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

Myriad-Dreamin avatar Aug 20 '23 07:08 Myriad-Dreamin

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

ivaquero avatar Aug 20 '23 09:08 ivaquero

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.

ivaquero avatar Aug 20 '23 10:08 ivaquero

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

willismonroe avatar Aug 21 '23 16:08 willismonroe

Same issue

taooceros avatar Sep 03 '23 13:09 taooceros

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

anesthetice avatar Feb 22 '24 13:02 anesthetice