rmagatti / goto-preview

A small Neovim plugin for previewing definitions using floating windows.
Apache License 2.0
834 stars 27 forks source link

Cursor position outside buffer #4

Closed rmagatti closed 3 years ago

rmagatti commented 3 years ago

@rmagatti done a bit of debugging with quite a minimal init.lua and it seems the underlying error I'm seeing is Error executing vim.schedule lua callback: ...site/pack/packer/start/goto-preview/lua/goto-preview.lua:79: Cursor position outside buffer. Seems setting the cursor is what is failing but I'm not sure why

Originally posted by @akinsho in https://github.com/rmagatti/goto-preview/issues/1#issuecomment-856262378

rmagatti commented 3 years ago

One way I could see this happening is if either the response from the lsp is ending up somewhere weird OR the buffer hasn't loaded the target file yet and is trying to set the cursor position in an empty buffer. 🤔

I can guard against it but things just won't work either way if the buffer isn't opening when it should.

akinsho commented 3 years ago

Minimal init.lua that reproduces this for me using. nvim -u minimal.lua --noplugin

vim.cmd("packadd goto-preview")
vim.cmd("packadd nvim-lspconfig")

require("lspconfig").sumneko_lua.setup {
 cmd = ...
 -- other stuff
}

require("goto-preview").setup {
  default_mappings = true
}

-- vim.o.hidden = true

Does this cause any issue for you, wondering if it's the files I'm using or the config, I actually use nvim-lspinstall so my minimal init.lua is a bit different since I use that plugin to load the lsp, but it shouldn't matter I don't think

rmagatti commented 3 years ago

@akinsho reproduced it with a tweaked version of your min example (just fixing the lsp stuff for my config).

rmagatti commented 3 years ago

So the result target of the lsp for me is file:///Users/ronnie/Projects/goto-preview/lua/goto-preview.lua.

In my regular config, if I do :e file:///Users/ronnie/Projects/goto-preview/lua/goto-preview.lua the file opens up fine. Now if I do the same command in the barebones minimal config, it opens an empty buffer.

I'm guessing you're missing some option that allows Vim to be able to use the file protocol notation? I'm not aware of something like that off the top of my head but that explains why the cursor issue happens, as indeed it's just an empty buffer so it can't set the cursor to a position that doesn't exist in the buffer.

akinsho commented 3 years ago

@rmagatti I don't think vim has native functionality to open uris there are quite a few helper functions added just to bridge that gap for the uris that the lsp returns, things like vim.uri_to_bufnr. Do you maybe have a plugin or setting in your config that allows you to open these?

rmagatti commented 3 years ago

So yeah I just realized that too 🙃 not entirely sure which one is the "culprit". Odd wording for something that's helping but yeah haha

I can definitely do some fixing here so the plugin handles those better, just wasn't aware it wasn't builtin I guess 🙈

rmagatti commented 3 years ago

@akinsho 🙏 lmk if this works for you? It works for me in the min config test.

akinsho commented 3 years ago

@rmagatti that did the trick, thanks for the fix 👍🏾