trouble.nvim icon indicating copy to clipboard operation
trouble.nvim copied to clipboard

Go to definition no longer working

Open mflova opened this issue 3 years ago • 4 comments

It was working quite well since I noticed that it stopped doing it. When I execute the command TroubleToggle lsp_definitions, I get the following output

Error executing vim.schedule lua callback: ...e/<myusername>/.vim/bundle/trouble.nvim/lua/trouble/util.lua:19: Expected Lua number
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        ...e/<myuser>/.vim/bundle/trouble.nvim/lua/trouble/util.lua:19: in function 'jump_to_item'
        ...e/<myuser>/.vim/bundle/trouble.nvim/lua/trouble/init.lua:66: in function 'cb'
        .../.vim/bundle/trouble.nvim/lua/trouble/providers/init.lua:69: in function 'cb'
        ...a/.vim/bundle/trouble.nvim/lua/trouble/providers/lsp.lua:67: in function 'handler'
        ...a/.vim/bundle/trouble.nvim/lua/trouble/providers/lsp.lua:9: in function 'handler'
        /usr/share/nvim/runtime/lua/vim/lsp.lua:995: in function ''
        vim.lua: in function <vim.lua:0>

Other functions such as the one that finds the references is working. I also checkout to the configuration of my neovim where everything was working fine, but this time I could not get gotodefinition work in my stable commits.

About the function where I get the issue: It is M.jump_to_item(win, precmd, item) in util.lua, more specifically in the line vim.api.nvim_win_set_cursor(win, { item.start.line + 1, item.start.character }). The item objects are well defined and with the correct value (line and column to jump), but winis always nil, what triggers the issue. I did a few experiments setting this one to 0 and it works, but ofc only when the line to jump is contained within my current opened buffer.

I have seen that neovim has been introducing some breaking changes, but I am not sure if this relates to my setup. However, since I could not get it work with the commits that were ok, this is the only thing I can think of.

Neovim info: NVIM v0.7.0-dev

mflova avatar Jan 19 '22 18:01 mflova

Can confirm, facing same issue. I think it happened after I updated nvim from 0.6 stable to 0.7-dev.

calvinchoy avatar Feb 01 '22 18:02 calvinchoy

This is due to a breaking change mentioned in https://github.com/neovim/neovim/issues/14090#issuecomment-1004318147. win cannot be nil any more and it is supposed to be 0 to denote to the current window. Is it a different behavior than what you want?

wookayin avatar Feb 02 '22 02:02 wookayin

This is due to a breaking change mentioned in neovim/neovim#14090 (comment). win cannot be nil any more and it is supposed to be 0 to denote to the current window. Is it a different behavior than what you want?

Adding this condition seems to be working, but I am not sure about what can be considered as a clean solution for a PR

function M.jump_to_item(win, precmd, item)
  -- requiring here, as otherwise we run into a circular dependency
  local View = require("trouble.view")

  View.switch_to(win)
  if precmd then
    vim.cmd(precmd)
  end
  if vim.api.nvim_buf_get_option(item.bufnr, "buflisted") == false then
    vim.cmd("edit #" .. item.bufnr)
  else
    vim.cmd("buffer " .. item.bufnr)
  end
  if win == nil then -- ADDED
    win = 0 -- ADDED
  end -- ADDED
  vim.api.nvim_win_set_cursor(win, { item.start.line + 1, item.start.character })
end

mflova avatar Feb 04 '22 08:02 mflova

Same problem here

lucalaissue avatar Jun 29 '22 08:06 lucalaissue

Here's a dirty hack you can drop in your config before you setup trouble:

local util = require("trouble.util")
local _jump_to_item = util.jump_to_item
util.jump_to_item = function(win, ...)
  return _jump_to_item(win or 0, ...)
end

require("trouble").setup(...)

lettertwo avatar Aug 26 '22 23:08 lettertwo

I think this might be fixed now? #175

lettertwo avatar Sep 16 '22 20:09 lettertwo

Yup, seems to be working fine again.

Met vriendelijke groet,

Calvin On 16 Sep 2022, 22:48 +0200, Eric Eldredge @.***>, wrote:

I think this might be fixed now? #175 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

calvinchoy avatar Sep 16 '22 21:09 calvinchoy