Skip to content

Commit cee1b1a

Browse files
committed
Included visibility parameter
1 parent 25ddda4 commit cee1b1a

5 files changed

Lines changed: 40 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim)
4747
-- Configurations for the clapi picker
4848
clapi = {
4949
show_inherited = true, -- Set to false to only show members defined in the current class
50-
default_visibility = "public", -- Filter by default visibility (public, protected, private)
50+
visibility = "public", -- Filter by default visibility (public, protected, private)
5151
},
5252
},
5353
}
@@ -97,7 +97,7 @@ require('telescope').setup {
9797

9898
-- Default visibility filter (default: nil - show all)
9999
-- Can be "public", "protected", "private", or nil
100-
default_visibility = nil,
100+
visibility = nil,
101101

102102
-- Additional display customization options
103103
display = {

doc/clapi.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,16 @@ The clapi picker accepts the following options:
101101
- `entry_maker`: Custom entry maker function
102102
- `show_inherited`: Whether to show inherited members from parent classes,
103103
traits, and interfaces (defaults to true)
104+
- `visibility`: Filter members by visibility: "public", "protected", "private",
105+
or nil to show all (defaults to nil)
104106

105107
Example configuration: >lua
106108
require('telescope').setup {
107109
extensions = {
108110
clapi = {
109111
-- Default configuration options
110112
show_inherited = true, -- Set to false to only show members defined in the current class
113+
visibility = "public", -- Only show public members (nil shows all)
111114
},
112115
},
113116
}
@@ -134,6 +137,8 @@ Parameters:
134137
- `show_inherited` (boolean, optional): Show inherited members from parent classes,
135138
traits, and interfaces. Defaults to true. Set to false to only show members
136139
defined in the current class.
140+
- `visibility` (string, optional): Filter by visibility. Can be "public",
141+
"protected", "private", or nil to show all. Defaults to nil.
137142

138143
Returns: nil
139144

@@ -157,7 +162,8 @@ Advanced usage with custom options: >lua
157162
-- Open the API picker with specific options
158163
require('clapi').builtin({
159164
path_display = { "smart" },
160-
show_inherited = false -- Only show members defined in the current class
165+
show_inherited = false, -- Only show members defined in the current class
166+
visibility = "public" -- Only show public members
161167
})
162168
<
163169

lua/clapi/finder.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ local M = {}
1414
---@param opts.path_display? table|string How to display paths
1515
---@param opts.entry_maker? function Custom entry maker function
1616
---@param opts.show_inherited? boolean Show inherited members, defaults to true
17+
---@param opts.visibility? string Filter by visibility (public, protected, private), defaults to nil (all)
1718
---@return nil
1819
M.builtin = function(opts)
20+
-- vim.print(opts)
1921
opts = opts or {}
2022
opts.bufnr = opts.bufnr or 0
2123
opts.path_display = { "hidden" }

lua/clapi/parser/init.lua

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ end
4242
---@param opts table Options for parsing
4343
---@param opts.bufnr? integer Buffer number, defaults to current buffer (0)
4444
---@param opts.show_inherited? boolean Whether to include inherited members from grandparents, defaults to true
45+
---@param opts.visibility? string Filter by visibility (public, protected, private), defaults to nil (all)
4546
---@return table|nil definitions List of definitions from parent class or nil if error
4647
local get_parent_file = async.wrap(function(opts, callback)
4748
opts = opts or {}
@@ -114,16 +115,20 @@ local get_parent_file = async.wrap(function(opts, callback)
114115
callback(nil)
115116
return
116117
end
117-
vim.print("fp", filepath)
118118
-- Pass the show_inherited option to parse_file for recursive parent parsing
119119
local defs = M.parse_file({
120120
filename = filepath,
121121
class_name = class_name,
122122
show_inherited = opts.show_inherited,
123+
visibility = opts.visibility,
123124
})
124125
for _, value in pairs(defs or {}) do
126+
-- Private members from parent classes are inaccessible
125127
if value["visibility"] ~= "private" then
126-
table.insert(result, value)
128+
-- Apply visibility filter if specified
129+
if not opts.visibility or value.visibility == opts.visibility then
130+
table.insert(result, value)
131+
end
127132
end
128133
end
129134
end
@@ -140,6 +145,7 @@ end, 2)
140145
---@param opts.filetype? string Force filetype instead of detecting from extension
141146
---@param opts.query_str? string Custom query string instead of loading from queries
142147
---@param opts.show_inherited? boolean Whether to include inherited members, defaults to true
148+
---@param opts.visibility? string Filter by visibility (public, protected, private), defaults to nil (all)
143149
---@return table|nil results List of symbols found or nil if error
144150
M.parse_file = async.wrap(function(opts, callback)
145151
opts = opts or {}
@@ -266,13 +272,22 @@ M.parse_file = async.wrap(function(opts, callback)
266272

267273
if capture_name == "method_name" then
268274
local method = parser.parse_method(node, start_col, start_row, opts)
269-
table.insert(result, method)
275+
-- Apply visibility filter if specified
276+
if not opts.visibility or method.visibility == opts.visibility then
277+
table.insert(result, method)
278+
end
270279
elseif capture_name == "prop_name" then
271280
local property = parser.parse_property(node, start_col, start_row, opts)
272-
table.insert(result, property)
281+
-- Apply visibility filter if specified
282+
if not opts.visibility or property.visibility == opts.visibility then
283+
table.insert(result, property)
284+
end
273285
elseif capture_name == "const_name" then
274286
local const = parser.parse_constant(node, start_col, start_row, opts)
275-
table.insert(result, const)
287+
-- Apply visibility filter if specified
288+
if not opts.visibility or const.visibility == opts.visibility then
289+
table.insert(result, const)
290+
end
276291
end
277292
end
278293

@@ -282,14 +297,19 @@ M.parse_file = async.wrap(function(opts, callback)
282297
local parent_defs = get_parent_file({
283298
bufnr = opts.bufnr,
284299
show_inherited = opts.show_inherited,
300+
-- Pass visibility to parent search as well
301+
visibility = opts.visibility,
285302
})
286303
if not parent_defs then
287304
-- error already printed somewhere
288305
callback(result)
289306
return
290307
end
291308
for _, value in pairs(parent_defs) do
292-
table.insert(result, value)
309+
-- Apply visibility filter if specified
310+
if not opts.visibility or value.visibility == opts.visibility then
311+
table.insert(result, value)
312+
end
293313
end
294314

295315
callback(result)

lua/telescope/_extensions/clapi.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ local telescope = require("telescope")
44

55
local default_config = {
66
show_inherited = true,
7+
visibility = nil, -- Default to showing all visibilities (public, protected, private)
78
}
89

910
return telescope.register_extension({
1011
setup = function(ext_config)
1112
default_config = vim.tbl_deep_extend("force", default_config, ext_config or {})
1213
end,
1314
exports = {
14-
clapi = function()
15+
clapi = function(opts)
1516
-- We copy the config to avoid polluting the extension default config between executions
1617
local config = vim.deepcopy(default_config)
18+
config = vim.tbl_deep_extend("force", config, opts or {})
1719
return require("clapi").builtin(config)
1820
end,
1921
},

0 commit comments

Comments
 (0)