File#
- class scubatrace.File(path: str, project: Project)#
Bases:
object
A source code file in a project.
- export_cfg_dot(path: str) DiGraph #
Exports the CFG of the file to a DOT file.
- Parameters:
path (str) – The path to save the DOT file.
- function_by_line(line: int) Function | None #
The function that contains the specified line number.
- Parameters:
line (int) – The line number to check.
- Returns:
The function that contains the line, or None if not found.
- Return type:
Function | None
- functions_by_name(name: str) list[Function] #
The functions that have the specified name.
- Parameters:
name (str) – The name of the function to check.
- Returns:
A list of functions that have the specified name.
- Return type:
list[Function]
- query(query: str, node: Node | None = None) list[Statement] #
Executes a tree-sitter query to find statements in the file.
- Parameters:
query (str) – The tree-sitter query to execute.
node (Node | None) – The tree-sitter node to query. If None, uses the root node of the file.
- Returns:
A list of statements that match the query.
- Return type:
list[Statement]
- query_identifier(query: str, node: Node | None = None) Identifier | None #
Executes a tree-sitter oneshot query to find an identifier in the file.
- Parameters:
query (str) – The tree-sitter oneshot query to execute.
- Returns:
The first identifier that matches the query, or None if no match is found.
- Return type:
Identifier | None
- query_identifiers(query: str, node: Node | None = None) list[Identifier] #
Executes a tree-sitter query to find identifiers in the file.
- Parameters:
identifier (str) – The identifier to search for.
node (Node | None) – The tree-sitter node to query. If None, uses the root node of the file.
- Returns:
A list of identifiers that contain the specified identifier.
- Return type:
list[Identifier]
- query_oneshot(query: str) Statement | None #
Executes a tree-sitter oneshot query to find statements in the file.
- Parameters:
query (str) – The tree-sitter oneshot query to execute.
- Returns:
The first statement that matches the query, or None if no match is found.
- Return type:
Statement | None
- statements_by_field_name(field_name: str) list[Statement] #
The statements that have the specified tree-sitter field name.
- Parameters:
field_name (str) – The tree-sitter field name to check.
- Returns:
A list of statements that have the specified field name.
- Return type:
list[Statement]
- statements_by_line(line: int) list[Statement] #
The statements that are located on the specified line number.
- Parameters:
line (int) – The line number to check.
- Returns:
A list of statements that are located on the specified line.
- Return type:
list[Statement]
- property abspath: str#
The absolute path of the file.
- property identifiers: list[Identifier]#
identifiers in the file.
- property imports: list[File]#
A list of
File
that are imported by this file.For example, in Python, this would include files imported using the import statement. In C/C++, this would include files included using the #include directive.
- property is_external: bool#
Checks if the file is external (not part of the project).
- property lines: list[str]#
A list of the lines in the file.
- property name: str#
The name of the file without the directory path.
- property node: Node#
The tree-sitter root node for the file.
- property node_type: str#
The type of the tree-sitter root node.
- property parser#
The parser associated with the current project.
- property relpath: str#
The relative path of the file with respect to the project directory.
- property text: str#
The content of the file.
- property uri: str#
The URI of the file.
- property variables: list[Identifier]#
variables in the file.