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
4647local 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
144150M .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 )
0 commit comments