echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.45k stars 171 forks source link

Jump using ctrl-o not correct after navigating with lsp picker #979

Open abeldekat opened 2 weeks ago

abeldekat commented 2 weeks ago

Contributing guidelines

Module(s)

mini.pick, mini.extra

Description

https://github.com/echasnovski/mini.nvim/assets/58370433/c5362c94-b91c-44f9-822b-f0b06b999696

When using lsp definition, I often jump back with ctrl-o. The jump is not correct. I also notice this behavior when using lsp references

Neovim version

0.10

Steps to reproduce


--[[
Use:
  mkdir ~/.config/repro
  cd ~/.config/repro

  touch init.lua
  add the contents of this file to init.lua
  NVIM_APPNAME=repro nvim init.lua 

Remove:
  rm -rf ~/.local/share/repro ~/.local/state/repro ~/.local/cache/repro
  rm -rf ~/.config/repro
--]]

local verify_with_fzf_lua = false -- set to true to use fzf-lua

local function clone(path_to_site)
  local mini_path = path_to_site .. "pack/deps/start/mini.nvim"
  if not vim.loop.fs_stat(mini_path) then
    vim.cmd('echo "Installing `mini.nvim`" | redraw')
    local clone_cmd =
      { "git", "clone", "--filter=blob:none", "https://github.com/echasnovski/mini.nvim", mini_path }
    vim.fn.system(clone_cmd)
    vim.cmd("packadd mini.nvim | helptags ALL")
    vim.cmd('echo "Installed `mini.nvim`" | redraw')
  end
end

local path_to_site = vim.fn.stdpath("data") .. "/site/"
clone(path_to_site)
local MiniDeps = require("mini.deps")
MiniDeps.setup({ path = { package = path_to_site } })
local add, now = MiniDeps.add, MiniDeps.now

vim.g.mapleader = " "
vim.opt.number = true

local function lua_ls_handler()
  require("lspconfig").lua_ls.setup({
    settings = {
      Lua = {
        runtime = { version = "LuaJIT" },
        workspace = {
          checkThirdParty = false,
          library = {
            vim.env.VIMRUNTIME,
            "${3rd}/luv/library",
          },
        },
      },
    },
  })
end

now(function()
  vim.cmd("colorscheme randomhue")

  add("nvim-treesitter/nvim-treesitter")
  ---@diagnostic disable-next-line: missing-fields
  require("nvim-treesitter.configs").setup({
    ensure_installed = { "lua" },
  })

  add("williamboman/mason.nvim")
  require("mason-registry"):on("package:install:success", function()
    vim.defer_fn(function()
      vim.cmd("LspStart")
    end, 100)
  end)
  require("mason").setup()

  add("williamboman/mason-lspconfig.nvim")
  add("neovim/nvim-lspconfig")
  require("mason-lspconfig").setup({
    ensure_installed = { "lua_ls" },
    handlers = {
      lua_ls = lua_ls_handler,
    },
  })

  local cmd_definition = "<cmd>Pick lsp scope='definition'<cr>"
  local cmd_references = "<cmd>Pick lsp scope='references'<cr>"
  if verify_with_fzf_lua then
    cmd_definition = "<cmd>FzfLua lsp_definitions<cr>"
    cmd_references = "<cmd>FzfLua lsp_references<cr>"
  end
  vim.api.nvim_create_autocmd("LspAttach", {
    callback = function(args)
      vim.keymap.set("n", "gd", cmd_definition, { buffer = args.buf, silent = true, desc = "Goto definition" })
      vim.keymap.set("n", "gr", cmd_references, { buffer = args.buf, silent = true, desc = "References" })
    end,
  })

  add("ibhagwan/fzf-lua") -- use by setting verify_with_fzf_lua to true
  require("fzf-lua").setup()
  require("mini.extra").setup()
  require("mini.pick").setup()
end)

Steps using the repro above:

  1. Open neovim: repro init.lua
  2. :30, selecting the line with "clone"
  3. press gd and enter
  4. line 17 is selected
  5. press ctrl-o
  6. cursor jumps to line 1 instead of line 30

Close neovim and change the following:

verify_with_fzf_lua = true

Repeat steps 1 till 6. The cursor correctly jumps to line 30.

Expected behavior

When I jump back after using Pick lsp scope="definition", the jump is correct.

Actual behavior

Jump is incorrect.

echasnovski commented 2 weeks ago

Thanks for the suggestion!

I can reproduce that indeed MiniExtra.pickers.lsp does not add previous position to jumplist. After quick look, I didn't find a quick fix, though. I'll take a closer look.

abeldekat commented 2 weeks ago

@echasnovski,

I noticed that you changed the type of the issue from "bug" into "feature-request". Was my assumption incorrect?

echasnovski commented 2 weeks ago

I think it is reasonable to consider a bug as a deviation from documented and/or assumed during implementation behavior.

In this particular case adding current position to jumplist is neither.

abeldekat commented 2 weeks ago

I understand. Thanks!