Myriad-Dreamin / tinymist

Tinymist [ˈtaɪni mɪst] is an integrated language service for Typst [taɪpst].
https://myriad-dreamin.github.io/tinymist
Apache License 2.0
696 stars 30 forks source link

Easier Neovim setup for multiple file projects #720

Open ddogfoodd opened 3 days ago

ddogfoodd commented 3 days ago

Motivation When using tinymist in neovim on a typst project with multiple files and directories, it doesn't seem to work properly. Even after following: https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/neovim/README.md#working-with-multiple-file-projects

Description I am using tinymist in neovim and am working on a typst project which has multiple files, where the main typst file and the bib file are in the root dir, other typst files and assets have their own subdirs. I have followed https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/neovim/README.md#working-with-multiple-file-projects and added the given command to the after/ftplugin/typst.lua config file, yet it doesn't seem to work fully i.e. references of other files and bib file are not recognized.

When I open the main file, I can get autocompletion suggestions for bib items, however as soon as I open another file from a subdir in a new buffer, the bib items are not recognized anymore. Even when I close the newly opened buffer and return to the buffer of the main file where they previously worked, they stop working.

It would be great if there was a more reliable and easy way to setup tinymist for projects that have multiple files and subdirectories in neovim.

Examples/Questions

Myriad-Dreamin commented 3 days ago

Note: You cannot close the neovim editor after pinning the document, because lsp will lose the pin state (in memory) once editor is closed.

In vscode, we don't use the pin commands explicitly and the document is pinned/unpinned automatically when starting/stopping a preview. I guess somebody can help write lua script for neovim to achieve similar effect.

ddogfoodd commented 3 days ago

But switching to another buffer in a new neovim tab should not lose the pin state, no?

Myriad-Dreamin commented 3 days ago

This depends on how neovim uses language server. If neovim starts new server instances for new tabs, the pinning command doesn't work well when switching tabs. But I'm not using neovim in my daily life, so I cannot judge it.

Btw, the pinning state can be checked and debugged in the lsp log.

ddogfoodd commented 3 days ago

Thanks, I will further investigate.

ddogfoodd commented 3 days ago

This depends on how neovim uses language server. If neovim starts new server instances for new tabs, the pinning command doesn't work well when switching tabs. But I'm not using neovim in my daily life, so I cannot judge it.

This seems to be the case for me.

A workaround (albeit annoying) is to run the pin function on lsp attach using a hardcoded path to the main typst file.

-- pin the main file
vim.lsp.buf.execute_command({ command = 'tinymist.pinMain', arguments = { 'path/to/main.typ' } })

This at least works for me but requires to change the neovim config (the hardcoded path) when working on a different project, which is pretty annoying.

Myriad-Dreamin commented 3 days ago

To hard pin documents, there was a proposal for project level configuration. But we were not satisfying with introducing tinymist specific configuration in a typst.toml file. https://github.com/Myriad-Dreamin/tinymist/issues/530