summaryrefslogtreecommitdiff
path: root/lua/telescope/utils.lua
diff options
context:
space:
mode:
authortami5 <kkharji@protonmail.com>2022-03-11 16:41:48 +0300
committerGitHub <noreply@github.com>2022-03-11 14:41:48 +0100
commitddb9e56160914261ca6af9f75ce2afb5d28961e2 (patch)
treee29fa7f91aed83fdb537d3a00e565529f61f38eb /lua/telescope/utils.lua
parentc5bf83dc614b14c6926b738a54c6d059de974f75 (diff)
feat(lsp): ignore_symbols option (#1745)
Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
Diffstat (limited to 'lua/telescope/utils.lua')
-rw-r--r--lua/telescope/utils.lua80
1 files changed, 44 insertions, 36 deletions
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua
index bce2c2c..9626121 100644
--- a/lua/telescope/utils.lua
+++ b/lua/telescope/utils.lua
@@ -91,44 +91,46 @@ utils.quickfix_items_to_entries = function(locations)
end
utils.filter_symbols = function(results, opts)
- if opts.symbols == nil then
+ local has_ignore = opts.ignore_symbols ~= nil
+ local has_symbols = opts.symbols ~= nil
+ local filtered_symbols
+
+ if has_symbols and has_ignore then
+ error "Either opts.symbols or opts.ignore_symbols, can't process opposing options at the same time!"
+ return
+ elseif not (has_ignore or has_symbols) then
return results
- end
- local valid_symbols = vim.tbl_map(string.lower, vim.lsp.protocol.SymbolKind)
-
- local filtered_symbols = {}
- if type(opts.symbols) == "string" then
- opts.symbols = string.lower(opts.symbols)
- if vim.tbl_contains(valid_symbols, opts.symbols) then
- for _, result in ipairs(results) do
- if string.lower(result.kind) == opts.symbols then
- table.insert(filtered_symbols, result)
- end
- end
- else
- print(string.format("%s is not a valid symbol per `vim.lsp.protocol.SymbolKind`", opts.symbols))
+ elseif has_ignore then
+ if type(opts.ignore_symbols) == "string" then
+ opts.ignore_symbols = { opts.ignore_symbols }
end
- elseif type(opts.symbols) == "table" then
- opts.symbols = vim.tbl_map(string.lower, opts.symbols)
- local mismatched_symbols = {}
- for _, symbol in ipairs(opts.symbols) do
- if vim.tbl_contains(valid_symbols, symbol) then
- for _, result in ipairs(results) do
- if string.lower(result.kind) == symbol then
- table.insert(filtered_symbols, result)
- end
- end
- else
- table.insert(mismatched_symbols, symbol)
- mismatched_symbols = table.concat(mismatched_symbols, ", ")
- print(string.format("%s are not valid symbols per `vim.lsp.protocol.SymbolKind`", mismatched_symbols))
- end
+ if type(opts.ignore_symbols) ~= "table" then
+ print "Please pass ignore_symbols as either a string or a list of strings"
+ return
end
- else
- print "Please pass filtering symbols as either a string or a list of strings"
- return
+
+ opts.ignore_symbols = vim.tbl_map(string.lower, opts.ignore_symbols)
+ filtered_symbols = vim.tbl_filter(function(item)
+ return not vim.tbl_contains(opts.ignore_symbols, string.lower(item.kind))
+ end, results)
+ elseif has_symbols then
+ if type(opts.symbols) == "string" then
+ opts.symbols = { opts.symbols }
+ end
+ if type(opts.symbols) ~= "table" then
+ print "Please pass filtering symbols as either a string or a list of strings"
+ return
+ end
+
+ opts.symbols = vim.tbl_map(string.lower, opts.symbols)
+ filtered_symbols = vim.tbl_filter(function(item)
+ return vim.tbl_contains(opts.symbols, string.lower(item.kind))
+ end, results)
end
+ -- TODO(conni2461): If you understand this correctly then we sort the results table based on the bufnr
+ -- If you ask me this should be its own function, that happens after the filtering part and should be
+ -- called in the lsp function directly
local current_buf = vim.api.nvim_get_current_buf()
if not vim.tbl_isempty(filtered_symbols) then
-- filter adequately for workspace symbols
@@ -153,9 +155,15 @@ utils.filter_symbols = function(results, opts)
end)
return filtered_symbols
end
- -- only account for string|table as function otherwise already printed message and returned nil
- local symbols = type(opts.symbols) == "string" and opts.symbols or table.concat(opts.symbols, ", ")
- print(string.format("%s symbol(s) were not part of the query results", symbols))
+
+ -- print message that filtered_symbols is now empty
+ if has_symbols then
+ local symbols = table.concat(opts.symbols, ", ")
+ print(string.format("%s symbol(s) were not part of the query results", symbols))
+ elseif has_ignore then
+ local symbols = table.concat(opts.ignore_symbols, ", ")
+ print(string.format("%s ignore_symbol(s) have removed everything from the query result", symbols))
+ end
end
utils.path_smart = (function()