feat: show hierarchy of symbols in telescope picker

This is now enabled by default, but can be disabled by setting the
extension `show_nesting` option to false.

```lua
require('telescope').setup({
  extensions = {
    aerial = {
      show_nesting = false
    }
  }
})
```
This commit is contained in:
Steven Arcangeli 2022-06-04 18:06:33 -07:00
parent 142819d7f4
commit a30aa79916
2 changed files with 32 additions and 3 deletions

View file

@ -468,7 +468,7 @@ The default bindings are set in
[bindings.lua](https://github.com/stevearc/aerial.nvim/blob/master/lua/aerial/bindings.lua#L4),
which you can use as a reference if you want to set your own bindings.
| Key | Command |
| Key | Command |
| --------------- | -------------------------------------------------------------- |
| `?`/`g?` | Show default keymaps |
| `<CR>` | Jump to the symbol under the cursor |
@ -512,6 +512,19 @@ If you want the command to autocomplete, you can load the extension first:
require('telescope').load_extension('aerial')
```
The extension can be customized with the following options:
```lua
require('telescope').setup({
extensions = {
aerial = {
-- Display symbols as <root>.<parent>.<symbol>
show_nesting = true
}
}
})
```
### fzf
If you have [fzf](https://github.com/junegunn/fzf.vim) installed you can trigger

View file

@ -8,6 +8,10 @@ local finders = require("telescope.finders")
local pickers = require("telescope.pickers")
local telescope = require("telescope")
local ext_config = {
show_nesting = true,
}
local function aerial_picker(opts)
opts = opts or {}
local bufnr = vim.api.nvim_get_current_buf()
@ -37,17 +41,26 @@ local function aerial_picker(opts)
text = vim.trim(text)
local columns = {
{ icon, "Aerial" .. item.kind .. "Icon" },
{ item.name, "Aerial" .. item.kind },
{ entry.name, "Aerial" .. item.kind },
text,
}
return displayer(columns)
end
local function make_entry(item)
local name = item.name
if ext_config.show_nesting then
local cur = item.parent
while cur do
name = string.format("%s.%s", cur.name, name)
cur = cur.parent
end
end
return {
value = item,
display = make_display,
ordinal = item.name .. " " .. string.lower(item.kind),
name = name,
ordinal = name .. " " .. string.lower(item.kind),
lnum = item.lnum,
col = item.col + 1,
filename = filename,
@ -72,6 +85,9 @@ local function aerial_picker(opts)
end
return telescope.register_extension({
setup = function(user_config)
ext_config = vim.tbl_extend("force", ext_config, user_config or {})
end,
exports = {
aerial = aerial_picker,
},