@@ -99,6 +99,9 @@ def File(path: str, project: Project) -> File:
9999
100100 @property
101101 def language (self ) -> type [lang .Language ]:
102+ """
103+ The language type associated with the current project.
104+ """
102105 return self .project .language
103106
104107 @property
@@ -111,46 +114,28 @@ def name(self) -> str:
111114 @property
112115 def abspath (self ) -> str :
113116 """
114- Returns the absolute path of the file.
115-
116- Returns:
117- str: The absolute path of the file.
117+ The absolute path of the file.
118118 """
119119 return os .path .abspath (self ._path )
120120
121121 @property
122122 def relpath (self ) -> str :
123123 """
124- Returns the relative path of the file with respect to the project directory.
125-
126- The method removes the project directory path from the file's absolute path,
127- leaving only the relative path.
128-
129- Returns:
130- str: The relative path of the file.
124+ The relative path of the file with respect to the project directory.
131125 """
132126 return self ._path .replace (self .project .path + "/" , "" )
133127
134128 @property
135129 def uri (self ) -> str :
136130 """
137- Returns the URI of the file.
138-
139- The URI is constructed by replacing the project path with "file://" and
140- ensuring it is properly formatted for use in a URI context.
141-
142- Returns:
143- str: The URI of the file.
131+ The URI of the file.
144132 """
145133 return f"file://{ self .abspath .replace (os .path .sep , '/' )} "
146134
147135 @property
148136 def text (self ) -> str :
149137 """
150- Reads the content of the file at the given path and returns it as a string.
151-
152- Returns:
153- str: The content of the file.
138+ The content of the file.
154139 """
155140 with open (
156141 self ._path ,
@@ -170,10 +155,7 @@ def text(self) -> str:
170155 @property
171156 def lines (self ) -> list [str ]:
172157 """
173- Reads the content of the file and returns it as a list of lines.
174-
175- Returns:
176- list[str]: The content of the file split into lines.
158+ A list of the lines in the file.
177159 """
178160 return self .text .splitlines ()
179161
@@ -189,18 +171,34 @@ def signature(self) -> str:
189171
190172 @property
191173 def parser (self ):
174+ """
175+ The parser associated with the current project.
176+ """
192177 return self .project .parser
193178
194179 @cached_property
195180 def node (self ) -> Node :
181+ """
182+ The tree-sitter root node for the file.
183+ """
196184 return self .parser .parse (self .text )
197185
198186 @cached_property
199187 @abstractmethod
200- def imports (self ) -> list [File ]: ...
188+ def imports (self ) -> list [File ]:
189+ """
190+ A list of :class:`File` that are imported by this file.
191+
192+ For example, in Python, this would include files imported using the `import` statement.
193+ In C/C++, this would include files included using the `#include` directive.
194+ """
195+ ...
201196
202197 @cached_property
203198 def functions (self ) -> list [Function ]:
199+ """
200+ All functions in the file.
201+ """
204202 func_node = self .parser .query_all (self .text , self .language .query_function )
205203 return [Function .Function (node , file = self ) for node in func_node ]
206204
@@ -211,30 +209,38 @@ def classes(self) -> list[Class]: ...
211209 @cached_property
212210 @abstractmethod
213211 def statements (self ) -> list [Statement ]:
212+ """
213+ All statements of functions in the file.
214+ """
214215 stats = []
215216 for func in self .functions :
216217 stats .extend (func .statements )
217218 return stats
218219
219220 @cached_property
220- @abstractmethod
221221 def identifiers (self ) -> list [Identifier ]:
222+ """
223+ All identifiers of functions in the file.
224+ """
222225 identifiers = []
223226 for stmt in self .statements :
224227 identifiers .extend (stmt .identifiers )
225228 return identifiers
226229
227230 @cached_property
228- @abstractmethod
229- def variables (self ) -> list [Identifier ]: ...
231+ def variables (self ) -> list [Identifier ]:
232+ """
233+ All variables of functions in the file.
234+ """
235+ variables = []
236+ for stmt in self .statements :
237+ variables .extend (stmt .variables )
238+ return variables
230239
231240 @property
232241 def is_external (self ) -> bool :
233242 """
234243 Checks if the file is external (not part of the project).
235-
236- Returns:
237- bool: True if the file is external, False otherwise.
238244 """
239245 return not self .abspath .startswith (self .project .abspath )
240246
@@ -271,12 +277,30 @@ def lsp(self) -> SyncLanguageServer:
271277 return lsp
272278
273279 def function_by_line (self , line : int ) -> Function | None :
280+ """
281+ Returns the function that contains the specified line number.
282+
283+ Args:
284+ line (int): The line number to check.
285+
286+ Returns:
287+ Function | None: The function that contains the line, or None if not found.
288+ """
274289 for func in self .functions :
275290 if func .start_line <= line <= func .end_line :
276291 return func
277292 return None
278293
279294 def statements_by_line (self , line : int ) -> list [Statement ]:
295+ """
296+ Returns the statements that are located on the specified line number.
297+
298+ Args:
299+ line (int): The line number to check.
300+
301+ Returns:
302+ list[Statement]: A list of statements that are located on the specified line.
303+ """
280304 if line < 1 or line > len (self .lines ):
281305 return []
282306 func = self .function_by_line (line )
0 commit comments