Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
abeldekat opened this issue Jun 19, 2024 · 4 comments
Open
3 tasks done

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

abeldekat opened this issue Jun 19, 2024 · 4 comments
Labels

Comments

@abeldekat
Copy link

abeldekat commented Jun 19, 2024

Contributing guidelines

Module(s)

mini.pick, mini.extra

Description

lsp_jump.mp4

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.

@abeldekat abeldekat added the bug Something isn't working label Jun 19, 2024
@echasnovski echasnovski added feature-request Feature request mini.extra and removed bug Something isn't working labels Jun 19, 2024
@echasnovski
Copy link
Owner

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
Copy link
Author

@echasnovski,

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

@echasnovski
Copy link
Owner

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
Copy link
Author

I understand. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants