summaryrefslogtreecommitdiff
path: root/lua/telescope/builtin/init.lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2020-11-16 21:17:13 +0100
committerGitHub <noreply@github.com>2020-11-16 15:17:13 -0500
commiteaa7011f8499f2c8c473a5beb50100f1cae006cf (patch)
tree6b004689f95f0cf93b476428f3543a29a3483559 /lua/telescope/builtin/init.lua
parent81172630270325947d2c6b3afda5599e34b48499 (diff)
feat: Add tags (#219)
Diffstat (limited to 'lua/telescope/builtin/init.lua')
-rw-r--r--lua/telescope/builtin/init.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index 2336a42..80c1f3f 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -923,4 +923,54 @@ builtin.keymaps = function(opts)
}):find()
end
+builtin.tags = function(opts)
+ opts = opts or {}
+
+ local ctags_file = opts.ctags_file or 'tags'
+
+ if not vim.loop.fs_open(vim.fn.expand(ctags_file), "r", 438) then
+ print('Tags file does not exists. Create one with ctags -R')
+ return
+ end
+
+ local fd = assert(vim.loop.fs_open(vim.fn.expand(ctags_file), "r", 438))
+ local stat = assert(vim.loop.fs_fstat(fd))
+ local data = assert(vim.loop.fs_read(fd, stat.size, 0))
+ assert(vim.loop.fs_close(fd))
+
+ local results = vim.split(data, '\n')
+
+ pickers.new(opts,{
+ prompt = 'Tags',
+ finder = finders.new_table {
+ results = results,
+ entry_maker = make_entry.gen_from_ctags(opts),
+ },
+ previewer = previewers.ctags.new(opts),
+ sorter = conf.generic_sorter(opts),
+ attach_mappings = function(prompt_bufnr)
+ actions._goto_file_selection:enhance {
+ post = function()
+ local selection = actions.get_selected_entry(prompt_bufnr)
+
+ local scode = string.gsub(selection.scode, '[$]$', '')
+ scode = string.gsub(scode, [[\\]], [[\]])
+ scode = string.gsub(scode, [[\/]], [[/]])
+ scode = string.gsub(scode, '[*]', [[\*]])
+
+ vim.cmd('norm! gg')
+ vim.fn.search(scode)
+ vim.cmd('norm! zz')
+ end,
+ }
+ return true
+ end
+ }):find()
+end
+
+builtin.current_buffer_tags = function(opts)
+ opts = opts or {}
+ return builtin.tags(vim.tbl_extend("force", {only_current_file = true, hide_filename = true}, opts))
+end
+
return builtin