Skip to content

Commit

Permalink
feat: show hierarchy of symbols in telescope picker
Browse files Browse the repository at this point in the history
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
    }
  }
})
```
  • Loading branch information
stevearc committed Jun 5, 2022
1 parent 142819d commit a30aa79
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions lua/telescope/_extensions/aerial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down

0 comments on commit a30aa79

Please sign in to comment.