feat(lsp_references): expose include_declaration option (default still true) (#1449)
This commit is contained in:
@@ -1342,10 +1342,12 @@ builtin.lsp_type_definitions({opts}) *builtin.lsp_type_definitions()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{jump_type} (string) how to goto definition if there is only
|
{jump_type} (string) how to goto definition if there is
|
||||||
one, values: "tab", "split", "vsplit",
|
only one, values: "tab", "split",
|
||||||
"never"
|
"vsplit", "never"
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{ignore_filename} (boolean) dont show filenames (default: true)
|
||||||
|
{include_declaration} (boolean) include symbol declaration in the lsp
|
||||||
|
references (default: true)
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_implementations({opts}) *builtin.lsp_implementations()*
|
builtin.lsp_implementations({opts}) *builtin.lsp_implementations()*
|
||||||
|
|||||||
@@ -365,6 +365,7 @@ builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").defi
|
|||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
|
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field ignore_filename boolean: dont show filenames (default: true)
|
||||||
|
---@field include_declaration boolean: include symbol declaration in the lsp references (default: true)
|
||||||
builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions
|
builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions
|
||||||
|
|
||||||
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
|
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ local utils = require "telescope.utils"
|
|||||||
local lsp = {}
|
local lsp = {}
|
||||||
|
|
||||||
lsp.references = function(opts)
|
lsp.references = function(opts)
|
||||||
|
local filepath = vim.api.nvim_buf_get_name(opts.bufnr)
|
||||||
|
local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1]
|
||||||
local params = vim.lsp.util.make_position_params(opts.winnr)
|
local params = vim.lsp.util.make_position_params(opts.winnr)
|
||||||
params.context = { includeDeclaration = true }
|
params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) }
|
||||||
|
|
||||||
vim.lsp.buf_request(opts.bufnr, "textDocument/references", params, function(err, result, ctx, _config)
|
vim.lsp.buf_request(opts.bufnr, "textDocument/references", params, function(err, result, ctx, _config)
|
||||||
if err then
|
if err then
|
||||||
@@ -24,10 +26,11 @@ lsp.references = function(opts)
|
|||||||
|
|
||||||
local locations = {}
|
local locations = {}
|
||||||
if result then
|
if result then
|
||||||
vim.list_extend(
|
local results = vim.lsp.util.locations_to_items(result, vim.lsp.get_client_by_id(ctx.client_id).offset_encoding)
|
||||||
locations,
|
locations = vim.tbl_filter(function(v)
|
||||||
vim.lsp.util.locations_to_items(result, vim.lsp.get_client_by_id(ctx.client_id).offset_encoding) or {}
|
-- Remove current line from result
|
||||||
)
|
return not (v.filename == filepath and v.lnum == lnum)
|
||||||
|
end, results or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(locations) then
|
if vim.tbl_isempty(locations) then
|
||||||
|
|||||||
Reference in New Issue
Block a user