Feat: symbols json picker (#303)
This commit is contained in:
@@ -391,6 +391,7 @@ Built-in function ready to be bound to any key you like :smile:.
|
||||
| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checkouts it out on enter. |
|
||||
| `builtin.git_branches` | Lists all branches with log preview and checkout action. |
|
||||
| `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multiselection still WIP) |
|
||||
| `builtin.symbols` | Lists symbols inside a file `data/telescope-sources/*.json` found in your rtp. More info and symbol sources can be found [here](https://github.com/nvim-telescope/telescope-symbols.nvim) |
|
||||
| .................................. | Your next awesome finder function here :D |
|
||||
|
||||
#### Built-in Previewers
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user