Address #9: Add a telescope extension

This commit is contained in:
Steven Arcangeli 2021-07-15 12:44:17 -07:00
parent 7cbad0a547
commit 57cece296c
2 changed files with 90 additions and 0 deletions

View file

@ -228,6 +228,19 @@ Key | Command
`zR` | Expand all nodes in the tree
`zx`/`zX` | Sync code folding to the tree (useful if they get out of sync)
## Fuzzy Finding
There is a telescope extension for fuzzy finding and jumping to symbols. It
functions similarly to the builtin `lsp_document_symbols` picker, the main
difference being that the aerial only includes the types of symbols in the
`filter_kind` configuration option. Load the extension with:
```lua
require('telescope').load_extension('aerial')
```
You can then begin fuzzy finding with `:Telescope aerial`
## Highlight
There are highlight groups created for each `SymbolKind`. There will be one for

View file

@ -0,0 +1,77 @@
local backend = require("aerial.backend")
local config = require("aerial.config")
local data = require("aerial.data")
local conf = require("telescope.config").values
local entry_display = require("telescope.pickers.entry_display")
local finders = require("telescope.finders")
local pickers = require("telescope.pickers")
local telescope = require("telescope")
local function aerial_picker(opts)
opts = opts or {}
local bufnr = vim.api.nvim_get_current_buf()
local filename = vim.api.nvim_buf_get_name(0)
if not backend.is_supported() then
backend.log_support_err()
return
elseif not data:has_symbols(0) then
backend.fetch_symbols_sync(opts.timeout)
end
local displayer = entry_display.create({
separator = " ",
items = {
{ width = 4 },
{ width = 30 },
{ remaining = true },
},
})
local function make_display(entry)
local item = entry.value
local icon = config.get_icon(item.kind)
local text = vim.api.nvim_buf_get_lines(bufnr, item.lnum - 1, item.lnum, false)[1] or ""
text = vim.trim(text)
local columns = {
{ icon, "Aerial" .. item.kind .. "Icon" },
{ item.name, "Aerial" .. item.kind },
text,
}
return displayer(columns)
end
local function make_entry(item)
return {
value = item,
display = make_display,
ordinal = item.name .. " " .. string.lower(item.kind),
lnum = item.lnum,
col = item.col + 1,
filename = filename,
}
end
local results = {}
if data:has_symbols(0) then
data[0]:visit(function(item)
table.insert(results, item)
end)
end
pickers.new(opts, {
prompt_title = "Document Symbols",
finder = finders.new_table({
results = results,
entry_maker = make_entry,
}),
sorter = conf.generic_sorter(opts),
previewer = conf.qflist_previewer(opts),
}):find()
end
return telescope.register_extension({
exports = {
aerial = aerial_picker,
},
})