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

neovim lsp jump to definition throws error on readonly files when using suda_smart_edit #54

Closed
perrin4869 opened this issue Nov 16, 2022 · 3 comments

Comments

@perrin4869
Copy link

This has been a long-standing issue of mine, which I finally got around to troubleshooting
I've been using suda_smart_edit = 1 because it is extremely useful when editing system files
However, I noticed when doing scala development, whenever I would use vim.lsp.buf.definition to a dependency file, I would get an error (this happens on neovim 0.8.1, but also happens on every neovim version I can remember):

"~/myproject/.metals/readonly/dependencies/play_2.13-2.8.18-sources.jar/play/api/mvc/Action.scala" 511L, 18648B
Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/uri.lua:86: Invalid buffer id: 26
stack traceback:
        [C]: in function 'nvim_buf_get_name'
        /usr/share/nvim/runtime/lua/vim/uri.lua:86: in function 'uri_from_bufnr'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:254: in function 'get_lines'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:320: in function 'get_line'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:335: in function 'get_line_byte_from_position'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1096: in function 'jump_to_location'
        /usr/share/nvim/runtime/lua/vim/lsp/handlers.lua:359: in function 'handler'
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue

Running buffers returns:

:buffers
  1  h   "api/app/myproject/controllers/MyController.scala" line 353
 27 %a   "suda:///home/perrin4869/myproject/.metals/readonly/dependencies/play_2.13-2.8.18-sources.jar/play/api/mvc/Action.scala" line 1
Press ENTER or type command to continue

Since I noticed the buffer was renamed to suda:///, I tried disabling the plugin, and the problem was solved.
You can probably reproduce this by doing vim.lsp.buf.definition which would result in opening a readonly file on any lsp server, this is not specific to scala (but probably common in scala due to metals creating readonly dependency files).
I really don't have much of a clue how this could be solved, but I thought I'd report it

@lambdalisue
Copy link
Owner

Thanks for the report. Well, I'm not sure but it seems Neovim accidentally enables LSP features on a virtual file (suda://...) even Neovim cannot handle it. So it's a kinda Neovim's runtime issue I guess.

@perrin4869
Copy link
Author

Yeah feel free to close this if you don't consider this a suda issue.
But to be fair, lsp should be enabled in that virtual file, even if it's not writable you can jump to definition, etc

@lambdalisue
Copy link
Owner

But to be fair, lsp should be enabled in that virtual file, even if it's not writable you can jump to definition, etc

Yes but only when Neovim's LSP itself supports a virtual file handling I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants