Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP: INFO read as ERROR, and edited files are excluded #439

Open
thomasaarholt opened this issue Jul 25, 2023 · 6 comments
Open

LSP: INFO read as ERROR, and edited files are excluded #439

thomasaarholt opened this issue Jul 25, 2023 · 6 comments
Labels
bug Something isn't working Help needed lsp

Comments

@thomasaarholt
Copy link

thomasaarholt commented Jul 25, 2023

I've just installed taplo using cargo install taplo-cli --locked --features lsp. taplo is found on PATH.
I want to use helix editor with the LSP. hx --health toml reports that it finds the taplo binary in .cargo/bin/taplo.

But trying to edit any new or existing .toml file results in a "this document is excluded error", which is also reported in #320. Additionally, it seems that info messages are being interpreted by helix as error messages. This does not happen for e.g. the pyright LSP for python.

Here's an asciicast video showing the steps:
asciicast

Full log:

2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"initialize\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/documentSymbol\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/foldingRange\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/formatting\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/completion\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/hover\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/documentLink\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/semanticTokens/full\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/prepareRename\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/rename\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"initialized\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didOpen\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didChange\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"workspace/didChangeConfiguration\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didSave\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didClose\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"workspace/didChangeWorkspaceFolders\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/convertToJson\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/convertToToml\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/listSchemas\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/associatedSchema\"\n"
2023-07-25T16:51:18.920 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"taplo/associateSchema\"\n"
2023-07-25T16:51:18.921 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: LSP server listening transport=\"stdio\"\n"
2023-07-25T16:51:18.921 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_open: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:24.600 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:24.601 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:completion: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:25.543 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:25.544 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:completion: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:26.538 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:26.675 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:26.839 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:27.018 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:27.128 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:27.212 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:27.309 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"
2023-07-25T16:51:27.402 helix_lsp::transport [ERROR] taplo err <- " WARN taplo:document_change: using detached workspace document_url=file:///Users/thomas/Documents/test.toml\n"

@ia0
Copy link
Collaborator

ia0 commented Aug 8, 2023

Thanks for the bug report!

This would need more investigation, but my current understanding would be:

  1. Helix does not set the workspaceFolders initialization parameter. This explains the warnings.
  2. Taplo does not support detached workspace files (probably due to mismatch in paths, but that's a guess). This would explain your "file excluded" error.

Fixing any of those 2 issues would probably fix your error.

@ia0 ia0 added bug Something isn't working Help needed lsp labels Aug 8, 2023
@mystilleef
Copy link

I had this issue in Neovim.

The solution depends on how your editor determines the root folder of your project.

My solution was to add .taplo.toml to the list of files that determines the root folder in my lsp config file.

And then add a .taplo.toml file where the toml file I am editing is located.

The other solution might be to edit your toml file in a versioned folder. By default, most editors consider a versioned folder the workspace or root folder.

@chrisvander
Copy link

Why would Taplo need to be run in a workspace? I assume basic LSP tasks in a TOML file can be accomplished with default configuration on the file alone.

@ia0
Copy link
Collaborator

ia0 commented Sep 17, 2023

Why would Taplo need to be run in a workspace?

I'm not sure (not familiar enough with LSP) so only speculating. Only a single instance of Taplo is needed to handle multiple projects (which I guess is what is sometimes called multi-root), which I think are called workspace in LSP vocabulary (I think project is Emacs vocabulary). Compare this with rust-analyzer which needs one instance per project/workspace. But note that Taplo only emits warnings for this issue, so it's probably not required.

I think the bug is somewhere else but a consequence of using detached workspace, which is probably a path that is not heavily tested. And the bug is probably something about path matching failing because the prefix differs although it is semantically the same.

@GitMurf
Copy link

GitMurf commented Sep 19, 2024

FYI here is how to solve the problem in Neovim: https://www.reddit.com/r/neovim/comments/1fkprp5/how_to_properly_setup_lspconfig_for_toml_files/

The key is that by default, Taplo looks for a git repository so if you are not within one, you will get the this document has been excluded response. Hope this helps!

@dbarnett
Copy link

This issue and helix-editor/helix#4436 look very related.

From what I can piece together...

  1. helix does pass workspaceFolders when there's a project workspace but not when you edit a standalone toml file (such as a file under ~/.config/)
  2. without workspaceFolders taplo also tries to do its own detection of a workspace root, which @GitMurf's config seems to work around by basically telling taplo's own detection to fall back to treating any dir as a workspace root
  3. without either of those detecting a root, taplo uses some detached workspace mode, which seems not just "not heavily tested" but pretty badly broken

BTW @thomasaarholt consider splitting/renaming this issue. I had trouble parsing "LSP: INFO read as ERROR, and edited files are excluded" and it seems to describe two completely different issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Help needed lsp
Projects
None yet
Development

No branches or pull requests

6 participants