folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.24k stars 178 forks source link

bug: Cursor position outside buffer #329

Closed 0x67cq closed 4 months ago

0x67cq commented 11 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.0

Operating system/version

MacOS 13.4.1

Describe the bug

function() require("trouble").open("lsp_references"), then press print below erro stack

E5108: Error executing lua ....local/share/nvim/lazy/trouble.nvim/lua/trouble/util.lua:28: Cursor position outside buffer stack traceback: [C]: in function 'nvim_win_set_cursor' ....local/share/nvim/lazy/trouble.nvim/lua/trouble/util.lua:28: in function 'jump_to_item' ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:477: in function 'jump' ....local/share/nvim/lazy/trouble.nvim/lua/trouble/init.lua:197: in function 'action' [string ":lua"]:1: in main chunk

this is error stack. and I try to print some log. look like this:

    print("bufnr", item.bufnr, "win", win, "item.start.line", item.start.line, "character", item.start.character)
    vim.api.nvim_set_current_buf(item.bufnr)
    vim.api.nvim_win_set_cursor(win or 0, { item.start.line + 1, item.start.character })

    bufnr 4 win 1000 item.start.line 98 character 11

    print(opts.win, opts.item, opts.precmd)
    print(self.parent)
    util.jump_to_item(opts.win or self.parent, opts.precmd, item)

    nil nil vsplit
    1000

then I add one line such as:

    print("bufnr", item.bufnr, "win", win, "item.start.line", item.start.line, "character", item.start.character)
    local win = vim.api.nvim_get_current_win()
    print("bufnr", item.bufnr, "win", win, "item.start.line", item.start.line, "character", item.start.character)
    vim.api.nvim_set_current_buf(item.bufnr)

    nil nil vsplit
    1000
    bufnr 4 win 1000 item.start.line 98 character 11
    bufnr 4 win 1003 item.start.line 98 character 11

and it work. I'm a beginner in nvim plugin. I can't descript it. but I think it's because self.parent windows ID not equal current_win and can't usr vim.api.nvim_win_set_cursor to jump. like view.lua's View object's parent in func jump hasn't assignment.

Steps To Reproduce

  1. vim.keymap.set("n", "gr", function() require("trouble").open("lsp_references") end)
  2. golang project and call this func
  3. print error stack

Expected Behavior

when I use trouble open lsp_references, and press c-v, it will open a vsp window and show references

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/trouble.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
folke commented 4 months ago

Development on the main branch is EOL.

Trouble has been rewritten and will be merged in main soon.

This issue/feature either no longer exists or has been implemented on dev.

For more info, see https://github.com/folke/trouble.nvim/tree/dev