From c19eae901cb6e03dc44c68f768133c885ce5bafc Mon Sep 17 00:00:00 2001 From: fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> Date: Tue, 12 Oct 2021 18:48:55 +0200 Subject: [PATCH] feat: filtering for dynamic workspace symbols (#1336) * enable `symbols` filtering opt for builtin.dynamic_workspace_symbols --- doc/telescope.txt | 13 ++++++++----- lua/telescope/builtin/init.lua | 1 + lua/telescope/builtin/lsp.lua | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 4cc6fbb..14a63e5 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1401,11 +1401,14 @@ builtin.lsp_dynamic_workspace_symbols({opts})*builtin.lsp_dynamic_workspace_symb {opts} (table) options to pass to the picker Options: ~ - {ignore_filename} (boolean) dont show filenames (default: false) - {show_line} (boolean) if true, shows the content of the line - the symbol is found on (default: false) - {symbol_highlights} (table) string -> string. Matches symbol with - hl_group + {ignore_filename} (boolean) dont show filenames (default: + false) + {show_line} (boolean) if true, shows the content of the + line the symbol is found on + (default: false) + {symbols} (string|table) filter results by symbol kind(s) + {symbol_highlights} (table) string -> string. Matches symbol + with hl_group builtin.lsp_document_diagnostics({opts}) *builtin.lsp_document_diagnostics()* diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 343c1a0..dd7ac48 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -428,6 +428,7 @@ builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.lsp" ---@param opts table: options to pass to the picker ---@field ignore_filename boolean: dont show filenames (default: false) ---@field show_line boolean: if true, shows the content of the line the symbol is found on (default: false) +---@field symbols string|table: filter results by symbol kind(s) ---@field symbol_highlights table: string -> string. Matches symbol with hl_group builtin.lsp_dynamic_workspace_symbols = require_on_exported_call("telescope.builtin.lsp").dynamic_workspace_symbols diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 3ac8e01..1f74cb9 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -381,7 +381,7 @@ lsp.workspace_symbols = function(opts) }):find() end -local function get_workspace_symbols_requester(bufnr) +local function get_workspace_symbols_requester(bufnr, opts) local cancel = function() end return function(prompt) @@ -400,6 +400,9 @@ local function get_workspace_symbols_requester(bufnr) assert(not err, err) local locations = vim.lsp.util.symbols_to_items(results_lsp or {}, bufnr) or {} + if not vim.tbl_isempty(locations) then + locations = utils.filter_symbols(locations, opts) or {} + end return locations end end @@ -411,7 +414,7 @@ lsp.dynamic_workspace_symbols = function(opts) prompt_title = "LSP Dynamic Workspace Symbols", finder = finders.new_dynamic { entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), - fn = get_workspace_symbols_requester(curr_bufnr), + fn = get_workspace_symbols_requester(curr_bufnr, opts), }, previewer = conf.qflist_previewer(opts), sorter = conf.generic_sorter(opts),