Skip to content

Commit 6b97ea3

Browse files
committed
Extension default config working
1 parent a5fe434 commit 6b97ea3

3 files changed

Lines changed: 29 additions & 18 deletions

File tree

lua/clapi/finder.lua

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local conf = require("telescope.config").values
1+
local telescope_config = require("telescope.config").values
22
local finders = require("telescope.finders")
33
local pickers = require("telescope.pickers")
44
local make_entry = require("clapi.make_entry")
@@ -20,13 +20,6 @@ M.builtin = function(opts)
2020
opts.bufnr = opts.bufnr or 0
2121
opts.path_display = { "hidden" }
2222

23-
-- Get extension configuration
24-
local telescope_config = require("telescope.config").values
25-
local ext_config = telescope_config.extensions and telescope_config.extensions.clapi or {}
26-
27-
-- Set show_inherited default value (true if not specified)
28-
opts.show_inherited = vim.F.if_nil(opts.show_inherited, ext_config.show_inherited, true)
29-
3023
async.run(function()
3124
local results = parser.parse_file(opts)
3225
if not results then
@@ -41,10 +34,10 @@ M.builtin = function(opts)
4134
results = results,
4235
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts),
4336
}),
44-
previewer = conf.qflist_previewer(opts),
45-
sorter = conf.prefilter_sorter({
37+
previewer = telescope_config.qflist_previewer(opts),
38+
sorter = telescope_config.prefilter_sorter({
4639
tag = "symbol_type",
47-
sorter = conf.generic_sorter(opts),
40+
sorter = telescope_config.generic_sorter(opts),
4841
}),
4942
push_cursor_on_edit = true,
5043
push_tagstack_on_edit = true,

lua/clapi/parser/init.lua

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ end
4646
local get_parent_file = async.wrap(function(opts, callback)
4747
opts = opts or {}
4848
opts.bufnr = opts.bufnr or 0
49-
opts.show_inherited = vim.F.if_nil(opts.show_inherited, true)
49+
-- Use explicit check for boolean values since vim.F.if_nil doesn't handle false properly
50+
if opts.show_inherited ~= nil then
51+
-- Keep the provided value (could be true or false)
52+
opts.show_inherited = opts.show_inherited
53+
else
54+
-- Default to true if not specified
55+
opts.show_inherited = true
56+
end
5057

5158
local filetype = tsparsers.get_buf_lang(opts.bufnr)
5259
local parser = vim.treesitter.get_parser(opts.bufnr, filetype)
@@ -114,7 +121,7 @@ local get_parent_file = async.wrap(function(opts, callback)
114121
local defs = M.parse_file({
115122
filename = filepath,
116123
class_name = class_name,
117-
show_inherited = opts.show_inherited
124+
show_inherited = opts.show_inherited,
118125
})
119126
for _, value in pairs(defs) do
120127
if value["visibility"] ~= "private" then
@@ -139,7 +146,6 @@ end, 2)
139146
M.parse_file = async.wrap(function(opts, callback)
140147
opts = opts or {}
141148
opts.class_name = opts.class_name and string.format("%s::", opts.class_name) or ""
142-
opts.show_inherited = vim.F.if_nil(opts.show_inherited, true)
143149

144150
if opts.filename and opts.bufnr then
145151
utils.notify("parse_file", {
@@ -270,9 +276,9 @@ M.parse_file = async.wrap(function(opts, callback)
270276
-- Only include inherited members if show_inherited is true
271277
if opts.show_inherited then
272278
async.run(function()
273-
local parent_defs = get_parent_file({
279+
local parent_defs = get_parent_file({
274280
bufnr = opts.bufnr,
275-
show_inherited = opts.show_inherited
281+
show_inherited = opts.show_inherited,
276282
})
277283
if not parent_defs then
278284
-- error already printed somewhere
@@ -290,4 +296,5 @@ M.parse_file = async.wrap(function(opts, callback)
290296
end
291297
end, 2)
292298

293-
return M
299+
return M
300+

lua/telescope/_extensions/clapi.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22
-- local x = require("clapi").builtin
33
local telescope = require("telescope")
44

5+
local default_config = {
6+
show_inherited = true,
7+
}
8+
59
return telescope.register_extension({
10+
setup = function(ext_config)
11+
default_config = vim.tbl_deep_extend("force", default_config, ext_config or {})
12+
end,
613
exports = {
7-
clapi = require("clapi").builtin, -- More complex builtin
14+
clapi = function()
15+
-- We copy the config to avoid polluting the extension default config between executions
16+
local config = vim.deepcopy(default_config)
17+
return require("clapi").builtin(config)
18+
end,
819
},
920
})

0 commit comments

Comments
 (0)