summaryrefslogtreecommitdiff
path: root/lua/telescope/actions/init.lua
diff options
context:
space:
mode:
authorfdschmidt93 <39233597+fdschmidt93@users.noreply.github.com>2021-03-09 21:04:21 +0100
committerGitHub <noreply@github.com>2021-03-09 21:04:21 +0100
commit559bf36e73dc827cff7edd7b726c7a0d73493829 (patch)
tree385cda8c343eee0e90437bf9a62c0363a1df8b4c /lua/telescope/actions/init.lua
parentff428c91879d7d5ffa22d950cd53b5eeff3553dc (diff)
feat: add completion to pre-filtering (#626)
Works by pressing `<C-l>` in insert mode. Supported are all builtins that have prefiltering. Means: - lsp_workspace_symbols - lsp_workspace_diagnostics - lsp_document_symbols - lsp_document_diagnostics
Diffstat (limited to 'lua/telescope/actions/init.lua')
-rw-r--r--lua/telescope/actions/init.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index d0bd27c..5741554 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -420,6 +420,49 @@ actions.smart_send_to_qflist = function(prompt_bufnr)
end
end
+actions.complete_tag = function(prompt_bufnr)
+ local current_picker = action_state.get_current_picker(prompt_bufnr)
+ local tags = current_picker.sorter.tags
+ local delimiter = current_picker.sorter._delimiter
+
+ if not tags then
+ print('No tag pre-filtering set for this picker')
+ return
+ end
+
+ -- format tags to match filter_function
+ local prefilter_tags = {}
+ for tag, _ in pairs(tags) do
+ table.insert(prefilter_tags, string.format('%s%s%s ', delimiter, tag:lower(), delimiter))
+ end
+
+ local line = action_state.get_current_line()
+ local filtered_tags = {}
+ -- retrigger completion with already selected tag anew
+ -- trim and add space since we can match [[:pattern: ]] with or without space at the end
+ if vim.tbl_contains(prefilter_tags, vim.trim(line) .. " ") then
+ filtered_tags = prefilter_tags
+ else
+ -- match tag by substring
+ for _, tag in pairs(prefilter_tags) do
+ local start, _ = tag:find(line)
+ if start then
+ table.insert(filtered_tags, tag)
+ end
+ end
+ end
+
+ if vim.tbl_isempty(filtered_tags) then
+ print('No matches found')
+ return
+ end
+
+ -- incremental completion by substituting string starting from col - #line byte offset
+ local col = vim.api.nvim_win_get_cursor(0)[2] + 1
+ vim.fn.complete(col - #line, filtered_tags)
+
+end
+
--- Open the quickfix list
actions.open_qflist = function(_)
vim.cmd [[copen]]