brainfucksec / neovim-lua

Neovim KISS configuration with Lua
GNU General Public License v3.0
826 stars 116 forks source link

Can't go to reference #4

Closed testfailagain closed 2 years ago

testfailagain commented 2 years ago

Hi,

I have one problem, I don't know if this is a feature that I should have with your default config, but I think it should so, my problem is the next. I'm going to try go to reference, I use 'gr' and it shows me all the references (great), but If I go to a specific line and press enter, it doesn't do anything, and I used other configurations where this actions send you to the file.

Any idea about what is happening?

brainfucksec commented 2 years ago

Hi @testfailagain :help gr give me this:

gr{char}        Replace the virtual characters under the cursor with
            {char}.  This replaces in screen space, not file
            space.  See |gR| and |Virtual-Replace-mode| for more
            details.  As with |r| a count may be given.
            {char} can be entered like with |r|

And :help gR:

gR          Enter Virtual Replace mode: Each character you type
            replaces existing characters in screen space.  So a
            <Tab> may replace several characters at once.
            Repeat the entered text [count]-1 times.  See
            |Virtual-Replace-mode| for more details.

Maybe you mean "go to definition"?

https://vim.fandom.com/wiki/Go_to_definition_using_g

Anyway if the command is not changed in the keymaps.lua file (in the case of my configuration) the default one is always used.

testfailagain commented 2 years ago

from your config: in https://github.com/brainfucksec/neovim-lua/blob/main/nvim/lua/plugins/nvim-lspconfig.lua line 52: buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)

Maybe :help gr shows you de default action, but it seems been replaced by lspconfig.

anyway, the important point is this, when I 'show references', it split at the bottom with the files where the method/class/function is used, but I can't press enter and go to them. (and I know it's possilbe because I used it)

brainfucksec commented 2 years ago

This is the default config of nvim-lspconfig, see:

https://github.com/neovim/nvim-lspconfig#suggested-configuration

testfailagain commented 2 years ago

I know, but normally it works as I described, and maybe you know why in your config it isn't, I don't know why, maybe it's some other config, maybe it's another plugin (I doubt it), or other thing that I can't imagine.

But ok, if you don't know maybe can think on it for a future improvement because it's very usefull. (normally it's a required feature).

Thanks for your help

brainfucksec commented 2 years ago

I will look for information on this, in case I find a solution I will comment here.

brainfucksec commented 2 years ago

For use the LSP document_highlight feature the colorscheme must support highlight groups defined, in my config the OneDark colorcheme support it, I have inserted the instruction in the nvim-lspconfig.lua file:

-- Highlighting references
if client.resolved_capabilities.document_highlight then
  vim.api.nvim_exec(
  [[
    augroup lsp_document_highlight
      autocmd! * <buffer>
      autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
      autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
    augroup END
  ]], false)
end

Example:

2022-03-13_451x186

See: Neovim automatic highlighting references with LSP and :h document_highlight.

The colorscheme must have these defined highlights:

hi LspReferenceText 
hi LspReferenceRead
hi LspReferenceWrite