4141--- Get parent class file and parse its definitions
4242--- @param opts table Options for parsing
4343--- @param opts .bufnr ? integer Buffer number , defaults to current buffer (0 )
44+ --- @param opts .show_inherited ? boolean Whether to include inherited members from grandparents , defaults to true
4445--- @return table | nil definitions List of definitions from parent class or nil if error
4546local get_parent_file = async .wrap (function (opts , callback )
4647 opts = opts or {}
4748 opts .bufnr = opts .bufnr or 0
49+ opts .show_inherited = vim .F .if_nil (opts .show_inherited , true )
4850
4951 local filetype = tsparsers .get_buf_lang (opts .bufnr )
5052 local parser = vim .treesitter .get_parser (opts .bufnr , filetype )
@@ -108,7 +110,12 @@ local get_parent_file = async.wrap(function(opts, callback)
108110 -- error already printed in get_file_from_position
109111 callback (nil )
110112 end
111- local defs = M .parse_file ({ filename = filepath , class_name = class_name })
113+ -- Pass the show_inherited option to parse_file for recursive parent parsing
114+ local defs = M .parse_file ({
115+ filename = filepath ,
116+ class_name = class_name ,
117+ show_inherited = opts .show_inherited
118+ })
112119 for _ , value in pairs (defs ) do
113120 if value [" visibility" ] ~= " private" then
114121 table.insert (result , value )
@@ -127,10 +134,12 @@ end, 2)
127134--- @param opts .class_name ? string Name of the class to filter results
128135--- @param opts .filetype ? string Force filetype instead of detecting from extension
129136--- @param opts .query_str ? string Custom query string instead of loading from queries
137+ --- @param opts .show_inherited ? boolean Whether to include inherited members , defaults to true
130138--- @return table | nil results List of symbols found or nil if error
131139M .parse_file = async .wrap (function (opts , callback )
132140 opts = opts or {}
133141 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 )
134143
135144 if opts .filename and opts .bufnr then
136145 utils .notify (" parse_file" , {
@@ -258,19 +267,27 @@ M.parse_file = async.wrap(function(opts, callback)
258267 end
259268 end
260269
261- async .run (function ()
262- local parent_defs = get_parent_file ({ bufnr = opts .bufnr })
263- if not parent_defs then
264- -- error already printed somewhere
265- callback (result )
266- return
267- end
268- for _ , value in pairs (parent_defs ) do
269- table.insert (result , value )
270- end
270+ -- Only include inherited members if show_inherited is true
271+ if opts .show_inherited then
272+ async .run (function ()
273+ local parent_defs = get_parent_file ({
274+ bufnr = opts .bufnr ,
275+ show_inherited = opts .show_inherited
276+ })
277+ if not parent_defs then
278+ -- error already printed somewhere
279+ callback (result )
280+ return
281+ end
282+ for _ , value in pairs (parent_defs ) do
283+ table.insert (result , value )
284+ end
271285
286+ callback (result )
287+ end )
288+ else
272289 callback (result )
273- end )
290+ end
274291end , 2 )
275292
276- return M
293+ return M
0 commit comments