marcoroth/stimulus-lsp

Goto Definition is broken

Closed this issue · 5 comments

I am using neovim, when I try to "Goto Definition", I get the following error:

Error executing vim.schedule lua callback: ...l/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/uri.lua:107: URI must contain a scheme: /usr/local/var/www/sticket/app/javascript/controllers/show_controller.js
stack traceback:
        [C]: in function 'assert'
        ...l/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/uri.lua:107: in function 'uri_to_fname'
        ...l/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/uri.lua:128: in function 'uri_to_bufnr'
        ...lar/neovim/0.9.4/share/nvim/runtime/lua/vim/lsp/util.lua:1127: in function 'jump_to_location'
        ...neovim/0.9.4/share/nvim/runtime/lua/vim/lsp/handlers.lua:412: in function 'handler'
        ...l/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/lsp.lua:1393: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I think neovim is expecting a URI with a scheme, e.g. file://usr/local/var/www/sticket/app/javascript/controllers/show_controller.js instead of /usr/local/var/www/sticket/app/javascript/controllers/show_controller.js

Thanks for reporting this, @Gert-JanPeeters!

I wonder if VSCode would still accept it with the file:// scheme, so we could use the same code for both.

Looking at this line here, I'm wondering why I opted for stripping it 🤔

this.project = new Project(this.settings.projectPath.replace("file://", ""))

I went searching a bit and found a similar issue:

NomicFoundation/hardhat-vscode#355

I think that VSCode can deal with both but Neovim is forcing LSPs to use an URI with a scheme. Not really sure which scheme it has to be used but I am guessing file://.

I guess in that case we should be able to use always use file:// then 👍🏼

I have investigated a bit further.

I tried changing this line:

this.project = new Project(this.settings.projectPath.replace("file://", ""))

to

this.project = new Project(this.settings.projectPath) 

But then things break. For example, stimulus-lsp cannot find the controllers anymore.

However, if I change:

const locations = controllers.map((controller) => Location.create(controller.path, Range.create(0, 0, 0, 0)))

to:

const locations = controllers.map((controller) => Location.create(`file://${controller.path}`, Range.create(0, 0, 0, 0))) 

The Goto definition works in neovim. However, I don't think we should make the change here.

If I am correct then it is stimulus-parser that provides the paths to the locations? Maybe I should make an issue / pull request there to send the controller.path with the right scheme?

Thanks for investigating!

I think we should rather do it here in the repo, since this is more LSP specific. The Stimulus Parser could be used outside of an LSP context, which is why I think it doesn't really make sense to use the file:// scheme in the stimulus-parser project.