Skip to content

Commit

Permalink
feat: telescope show_nesting opt can be a filetype map
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Oct 1, 2022
1 parent 888b672 commit c5436fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,11 @@ require('telescope').setup({
extensions = {
aerial = {
-- Display symbols as <root>.<parent>.<symbol>
show_nesting = true
show_nesting = {
['_'] = false, -- This key will be the default
json = true, -- You can set the option for specific filetypes
yaml = true,
}
}
}
})
Expand Down
18 changes: 16 additions & 2 deletions lua/telescope/_extensions/aerial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ local pickers = require("telescope.pickers")
local telescope = require("telescope")

local ext_config = {
show_nesting = true,
show_nesting = {
["_"] = false,
json = true,
yaml = true,
},
}

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)
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
local show_nesting = ext_config.show_nesting[filetype]
if show_nesting == nil then
show_nesting = ext_config.show_nesting["_"]
end
local backend = backends.get()

if not backend then
Expand Down Expand Up @@ -49,7 +58,7 @@ local function aerial_picker(opts)

local function make_entry(item)
local name = item.name
if ext_config.show_nesting then
if show_nesting then
local cur = item.parent
while cur do
name = string.format("%s.%s", cur.name, name)
Expand Down Expand Up @@ -89,6 +98,11 @@ end
return telescope.register_extension({
setup = function(user_config)
ext_config = vim.tbl_extend("force", ext_config, user_config or {})
if type(ext_config.show_nesting) ~= "table" then
ext_config.show_nesting = {
["_"] = ext_config.show_nesting,
}
end
end,
exports = {
aerial = aerial_picker,
Expand Down

0 comments on commit c5436fd

Please sign in to comment.