diff --git a/lua/core/lsp.lua b/lua/core/lsp.lua index fd03a42..e94b0c8 100644 --- a/lua/core/lsp.lua +++ b/lua/core/lsp.lua @@ -1,17 +1,32 @@ ----@diagnostic disable: param-type-mismatch - local misc = require("core.misc") local map, auto = misc.map, misc.auto local popup_opts, hover_opts, signature_opts, list_opts, location_opts --- TODO: find a way to make the qflist current item be the one closest to the --- cursor whenever we open it local function on_list(opts) vim.fn.setqflist({}, "r", opts) if #opts.items > 1 then vim.cmd.copen() + + -- get to the closest reference to the cursor (likely the one gr or gd was + -- called on) + local closest, distance = 1, false + for i, item in ipairs(opts.items) do + if item.filename and vim.fn.expand("%:p") == item.filename then + local lnum = vim.api.nvim_win_get_cursor(0)[1] + if item.lnum then + local new_distance = math.abs(lnum - item.lnum) + if not distance or new_distance < distance then + distance = new_distance + closest = i + end + end + end + + vim.cmd(".cc! "..closest) + end + else + vim.cmd(".cc! 1") end - vim.cmd(".cc! 1") end -- disable the default keybinds (they're bad)