diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2020-12-10 09:22:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-10 09:22:46 +0100 |
| commit | df6b762b317fa11202e1a55671842fe13909de75 (patch) | |
| tree | 819f66721b3e92055c5d079957c5377c8e3368dc /lua | |
| parent | a12d38bac308ce2a7346aef48003325077fdb48a (diff) | |
Feat: symbols json picker (#303)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/telescope/actions/init.lua | 6 | ||||
| -rw-r--r-- | lua/telescope/builtin/init.lua | 1 | ||||
| -rw-r--r-- | lua/telescope/builtin/internal.lua | 49 |
3 files changed, 56 insertions, 0 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index aaeffab..b0dcc26 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -230,6 +230,12 @@ actions.run_builtin = function(prompt_bufnr) require('telescope.builtin')[entry.text]() end +actions.insert_symbol = function(prompt_bufnr) + local selection = actions.get_selected_entry() + actions.close(prompt_bufnr) + vim.api.nvim_put({selection.value[1]}, '', true, true) +end + -- TODO: Think about how to do this. actions.insert_value = function(prompt_bufnr) local entry = actions.get_selected_entry(prompt_bufnr) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index c9dd1fd..14e99a6 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -36,6 +36,7 @@ builtin.git_status = require('telescope.builtin.git').status builtin.builtin = require('telescope.builtin.internal').builtin builtin.planets = require('telescope.builtin.internal').planets +builtin.symbols = require('telescope.builtin.internal').symbols builtin.commands = require('telescope.builtin.internal').commands builtin.quickfix = require('telescope.builtin.internal').quickfix builtin.loclist = require('telescope.builtin.internal').loclist diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 0b2b626..00868bb 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -86,6 +86,55 @@ internal.planets = function(opts) }:find() end +internal.symbols = function(opts) + local files = vim.api.nvim_get_runtime_file('data/telescope-sources/*.json', true) + if table.getn(files) == 0 then + print("No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim " .. + "for some prebuild symbols or how to create you own symbol source.") + return + end + + local sources = {} + if opts.sources then + for _, v in ipairs(files) do + for _, s in ipairs(opts.sources) do + if v:find(s) then + table.insert(sources, v) + end + end + end + else + sources = files + end + + local results = {} + for _, source in ipairs(sources) do + local data = vim.fn.json_decode(path.read_file(source)) + for _, entry in ipairs(data) do + table.insert(results, entry) + end + end + + pickers.new(opts, { + prompt_title = 'Symbols', + finder = finders.new_table { + results = results, + entry_maker = function(entry) + return { + value = entry, + ordinal = entry[1] .. ' ' .. entry[2], + display = entry[1] .. ' ' .. entry[2], + } + end + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(_) + actions.goto_file_selection_edit:replace(actions.insert_symbol) + return true + end + }):find() +end + internal.commands = function(opts) pickers.new(opts, { prompt_title = 'Commands', |
