How can I make label references work across multiple files with Neovim + tinymist?

I have a Typst document split into multiple files. For example:

chapter.typ
main.typ

In chapter.typ, I have a link that points to a label defined in main.typ. Here’s the contents of both:

// chapter.typ
#link(<label1>)[Click me]
#pagebreak()
// main.typ
#include("chapter.typ")
#lorem(30)
<label1>Now you're here.

The problem is that tinymist marks the link with the diagnostic error ‘label <label1> does not exist in the document’ in Neovim.

Is it possible to tell tinymist to be aware of both files when handling links with labels and supress the error?

I’ve found a solution here:

:lua vim.lsp.buf.execute_command({ command = 'tinymist.pinMain', arguments = { vim.api.nvim_buf_get_name(0) } })

This does make the error go away, although ‘unpinning’ the main file with :lua vim.lsp.buf.execute_command({ command = 'tinymist.pinMain', arguments = { nil } }) just prints out this error:

-32602: expect Option<PathBuf> at args[0]

It may not be ideal, but it’s better than nothing.


Update: I’ve just tried again, and I can’t reliably make it work using the command I pasted earlier, not even on the same minimal examples.

After some trial and error, I managed to make the error go away by restarting the language server from Neovim. (Even auto completion of the label worked.) However, when I quit Neovim and opened the files again, the error is back.

I have no idea what happened, but pinning the buffer works again (using Tinymist 0.12.16 and Neovim v0.10.3 on Arch Linux).

I can’t edit my reply anymore, so I’m just going to mark it as the solution the way it is.

Hi, I’m experiencing the same issue as Maxigaz, but I’m using VSCode, so the solution provided doesn’t work for me. Does anyone have any suggestions for resolving this in VSCode?

Alternatively, a more generalized solution that works across different editors would be even better.

I’m also struggling to understand how the “each file is its own module” philosophy applies to cross-referencing between modules and using bibliography references when writing a multi-file document. Could someone clarify this?

I don’t use VSCode, but I did come across this suggestion while doing research.

And just like Neovim, VSCode also has its own notes for tinymist here.

1 Like