lambdalisue / vim-suda

🥪 An alternative sudo.vim for Vim and Neovim, limited support sudo in Windows
MIT License
713 stars 27 forks source link

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

Closed perrin4869 closed 1 year ago

perrin4869 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.