simrat39 / symbols-outline.nvim

A tree like view for symbols in Neovim using the Language Server Protocol. Supports all your favourite languages.
MIT License
1.85k stars 97 forks source link

Goto location doesn't work when symbol is not in the field of view #220

Open liuyangzys opened 1 year ago

liuyangzys commented 1 year ago

nvim version 0.9.0

when I press to goto the location of a symbol, if the symbols is not in the field of view, the cursor jump to a wrong place

vaklinzi commented 1 year ago

I have the same issue.

mertzt89 commented 1 year ago

I was having the same issue and I think it has to do with an internal race on how the cursor position handling occurs when switching windows.

Adding this to my config to override the default goto_location handling has locally resolved the issue for me. I just don't know if its the right approach to fixing it.

Plugin.opts = {
  keymaps = { -- These keymaps can be a string or a table for multiple keys
    goto_location = {},
  },
}

Plugin.config = function(_, opts)
  require("symbols-outline").setup(opts)

  vim.api.nvim_create_autocmd("FileType", {
    pattern = "Outline",
    callback = function()
      vim.keymap.set("n", "<CR>", function()
        local outline = require("symbols-outline")
        local node = outline._current_node()

        vim.api.nvim_win_set_cursor(outline.state.code_win, { node.line + 1, node.character })

        vim.schedule(function()
          vim.fn.win_gotoid(outline.state.code_win)
        end)
      end, { buffer = true })
    end,
  })
end

The key seems to be deferring win_gotoid just enough.

carzilla commented 9 months ago

Same issue here, if it helps, I'm using the plugin in combination with LazyVim.