diff options
| author | Brian Ryall <bryall@users.noreply.github.com> | 2020-09-06 22:48:36 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-06 22:48:36 -0400 |
| commit | b065423013c35112f00154b575900482738ec7ef (patch) | |
| tree | ee6e83b40b6e67d95b71fcd8c96cb5ad3868daf4 /lua/telescope/builtin.lua | |
| parent | 0185d9b6b0fb2b00317ddec870cc6d2ac923a4ad (diff) | |
added treesitter builtin (#31)
* added treesitter builtim
* fixed treesitter pr comments
* fix the buffer previewer to keep lnum visable
Diffstat (limited to 'lua/telescope/builtin.lua')
| -rw-r--r-- | lua/telescope/builtin.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua index 8cf6906..4eae327 100644 --- a/lua/telescope/builtin.lua +++ b/lua/telescope/builtin.lua @@ -370,4 +370,60 @@ builtin.buffers = function(opts) }):find() end +local function prepare_match(entry, kind) + local entries = {} + + if entry.node then + entry["kind"] = kind + table.insert(entries, entry) + else + for name, item in pairs(entry) do + vim.list_extend(entries, prepare_match(item, name)) + end + end + + return entries +end + +builtin.treesitter = function(opts) + opts = opts or {} + + local has_nvim_treesitter, nvim_treesitter = pcall(require, 'nvim-treesitter') + if not has_nvim_treesitter then + print('You need to install nvim-treesitter') + return + end + + local parsers = require('nvim-treesitter.parsers') + if not parsers.has_parser() then + print('No parser for the current buffer') + return + end + + local ts_locals = require('nvim-treesitter.locals') + local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() + + local results = {} + for _, definitions in ipairs(ts_locals.get_definitions(bufnr)) do + local entries = prepare_match(definitions) + for _, entry in ipairs(entries) do + table.insert(results, entry) + end + end + + if vim.tbl_isempty(results) then + return + end + + pickers.new(opts, { + prompt = 'Treesitter Symbols', + finder = finders.new_table { + results = results, + entry_maker = make_entry.gen_from_treesitter(opts) + }, + previewer = previewers.vim_buffer.new(opts), + sorter = sorters.get_norcalli_sorter(), + }):find() +end + return builtin |
