fix(lsp.reference): only filter the current line of the current filname (#3154)

* fix(lsp.reference): Only filter the current line of the current filname

fix(lsp.reference): Only filter the current line of the current filname when include_current_line=false

* fix(lsp.reference): Only filter the current line of the current filname

* run stylua

---------

Co-authored-by: James Trew <j.trew10@gmail.com>
This commit is contained in:
Lonzo_ghf
2024-06-08 10:32:45 +08:00
committed by GitHub
parent dfa230be84
commit 3a743491e5

View File

@@ -141,7 +141,7 @@ local apply_action_handler = function(action, items, opts)
if action == "textDocument/references" and not opts.include_current_line then if action == "textDocument/references" and not opts.include_current_line then
local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1] local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1]
items = vim.tbl_filter(function(v) items = vim.tbl_filter(function(v)
return not (v.filename and v.lnum == lnum) return not (v.filename == opts.curr_filepath and v.lnum == lnum)
end, items) end, items)
end end
@@ -154,8 +154,8 @@ end
---@param opts table ---@param opts table
local function list_or_jump(action, title, params, opts) local function list_or_jump(action, title, params, opts)
opts.reuse_win = vim.F.if_nil(opts.reuse_win, false) opts.reuse_win = vim.F.if_nil(opts.reuse_win, false)
opts.curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr)
local curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr)
vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _) vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _)
if err then if err then
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message) vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message)
@@ -182,7 +182,7 @@ local function list_or_jump(action, title, params, opts)
if #items == 1 and opts.jump_type ~= "never" then if #items == 1 and opts.jump_type ~= "never" then
local item = items[1] local item = items[1]
if curr_filepath ~= item.filename then if opts.curr_filepath ~= item.filename then
local cmd local cmd
if opts.jump_type == "tab" then if opts.jump_type == "tab" then
cmd = "tabedit" cmd = "tabedit"