@@ -101,6 +101,7 @@ def find_references(
101101 source_file : Path ,
102102 include_definition : bool = False ,
103103 max_files : int = 1000 ,
104+ class_name : str | None = None ,
104105 ) -> list [Reference ]:
105106 """Find all references to a function across the project.
106107
@@ -109,6 +110,7 @@ def find_references(
109110 source_file: Path to the file where the function is defined.
110111 include_definition: Whether to include the function definition itself.
111112 max_files: Maximum number of files to search (prevents runaway searches).
113+ class_name: For class methods, the name of the containing class.
112114
113115 Returns:
114116 List of Reference objects describing each call site.
@@ -126,7 +128,7 @@ def find_references(
126128 return references
127129
128130 analyzer = get_analyzer_for_file (source_file )
129- exported = self ._analyze_exports (function_name , source_file , source_code , analyzer )
131+ exported = self ._analyze_exports (function_name , source_file , source_code , analyzer , class_name )
130132
131133 if not exported :
132134 logger .debug ("Function %s is not exported from %s" , function_name , source_file )
@@ -250,21 +252,29 @@ def find_references(
250252 return unique_refs
251253
252254 def _analyze_exports (
253- self , function_name : str , file_path : Path , source_code : str , analyzer : TreeSitterAnalyzer
255+ self ,
256+ function_name : str ,
257+ file_path : Path ,
258+ source_code : str ,
259+ analyzer : TreeSitterAnalyzer ,
260+ class_name : str | None = None ,
254261 ) -> ExportedFunction | None :
255262 """Analyze how a function is exported from its file.
256263
264+ For class methods, also checks if the containing class is exported.
265+
257266 Args:
258267 function_name: Name of the function to check.
259268 file_path: Path to the source file.
260269 source_code: Source code content.
261270 analyzer: TreeSitterAnalyzer instance.
271+ class_name: For class methods, the name of the containing class.
262272
263273 Returns:
264274 ExportedFunction if the function is exported, None otherwise.
265275
266276 """
267- is_exported , export_name = analyzer .is_function_exported (source_code , function_name )
277+ is_exported , export_name = analyzer .is_function_exported (source_code , function_name , class_name )
268278
269279 if not is_exported :
270280 return None
@@ -825,6 +835,7 @@ def find_references(
825835 source_file : Path ,
826836 project_root : Path | None = None ,
827837 max_files : int = 1000 ,
838+ class_name : str | None = None ,
828839) -> list [Reference ]:
829840 """Convenience function to find all references to a function.
830841
@@ -835,6 +846,7 @@ def find_references(
835846 source_file: Path to the file where the function is defined.
836847 project_root: Root directory of the project. If None, uses source_file's parent.
837848 max_files: Maximum number of files to search.
849+ class_name: For class methods, the name of the containing class.
838850
839851 Returns:
840852 List of Reference objects describing each call site.
@@ -858,4 +870,4 @@ def find_references(
858870 project_root = source_file .parent
859871
860872 finder = ReferenceFinder (project_root )
861- return finder .find_references (function_name , source_file , max_files = max_files )
873+ return finder .find_references (function_name , source_file , max_files = max_files , class_name = class_name )
0 commit comments