Inherits from

TSHasBlock, TSSymbol, HasBlock, Exportable, Symbol, Expression, Usable, Editable, Importable, HasName

Properties


attributes

Retrieves the list of attributes defined in the TypeScript interface.

Args: None

Returns: list[TSAttribute]: A list of the interface’s attributes stored in the code block.

def attributes(self) -> list[TSAttribute]:
    ...

comment

Retrieves the comment group associated with the symbol.

Returns the TSCommentGroup object that contains any comments associated with the symbol. A comment group represents one or more related comments that precede the symbol in the code.

Returns: TSCommentGroup | None: The comment group for the symbol if one exists, None otherwise.

def comment(self) -> TSCommentGroup | None:
    ...

decorators

Returns a list of decorators associated with this symbol.

Retrieves all decorators applied to this symbol by looking at both previous named siblings and decorator fields. This includes both inline decorators and standalone decorator statements.

Returns: list[TSDecorator]: A list of TSDecorator objects representing all decorators applied to this symbol. Returns an empty list if no decorators are found.

def decorators(self) -> list[TSDecorator]:
    ...

dependencies

Returns a list of symbols that this symbol depends on.

Returns a list of symbols (including imports) that this symbol directly depends on. The returned list is sorted by file location for consistent ordering.

Returns: list[Union[Symbol, Import]]: A list of symbols and imports that this symbol directly depends on, sorted by file location.

def dependencies(self) -> list[Union["Symbol", "Import"]]:
    ...

docstring

Retrieves the docstring of a function or class.

Returns any comments immediately preceding this node as a docstring. For nodes that are children of a HasBlock, it returns consecutive comments that end on the line before the node starts. For other nodes, it returns formatted docstring comments.

Returns: TSCommentGroup | None: A CommentGroup representing the docstring if one exists, None otherwise.

def docstring(self) -> TSCommentGroup | None:
    ...

export

Returns the export object that exports this symbol.

Retrieves the export object that is exporting this symbol by looking at incoming EXPORT edges in the CodebaseGraph.

Args: None

Returns: Export | None: The Export object that exports this symbol, or None if this symbol is not exported.

def export(self) -> Export | None:
    ...

exported_name

Retrieves the name under which a symbol is exported from its file.

Returns the name that this symbol is exported as in its file. If the symbol is an export node, returns the node’s name. If the symbol is not exported, returns None.

Returns: str | None: The name the symbol is exported as, or None if the symbol is not exported.

def exported_name(self) -> str | None:
    ...

extended

Returns a SymbolGroup of all extended nodes associated with this element.

Creates a SymbolGroup that provides a common interface for editing all extended nodes, such as decorators, modifiers, and comments associated with the element.

Args: None

Returns: SymbolGroup: A group containing this node and its extended nodes that allows batch modification through a common interface.

def extended(self) -> SymbolGroup:
    ...

extended_nodes

Returns the list of nodes associated with this symbol including extended nodes.

This property returns a list of Editable nodes that includes any wrapping or extended symbols like export, public, or decorators. For example, if the symbol is within an export_statement or lexical_declaration, those nodes will be included in the list.

Args: No arguments.

Returns: list[Editable]: A list of Editable nodes including the symbol’s extended nodes like export statements and decorators.

def extended_nodes(self) -> list[Editable]:
    ...

extended_source

Returns the source text representation of all extended nodes.

Gets the source text of all extended nodes combined. This property allows reading the source text of all extended nodes (e.g. decorators, export statements) associated with this node.

Returns: str: The combined source text of all extended nodes.

def extended_source(self) -> str:
    ...

file

The file object that this Editable instance belongs to.

Retrieves or caches the file object associated with this Editable instance.

Returns: File: The File object containing this Editable instance.

def file(self) -> SourceFile:
    ...

filepath

The file path of the file that this Editable instance belongs to.

Returns a string representing the absolute file path of the File that contains this Editable instance.

Returns: str: The absolute file path.

def filepath(self) -> str:
    ...

full_name

Returns the full name of the object, including the namespace path.

Returns the complete qualified name of an object, including any parent class or namespace paths. For class methods, this returns the parent class’s full name followed by the method name. For chained attributes (e.g., ‘a.b’), this returns the full chained name.

Args: None

Returns: str | None: The complete qualified name of the object. Returns None if no name is available. For class methods, returns ‘ParentClass.method_name’. For chained attributes, returns the full chain (e.g., ‘a.b’). For simple names, returns just the name.

def full_name(self) -> str | None:
    ...

function_calls

Returns all function calls within the code block and its decorators.

Args: None

Returns: list[FunctionCall]: A sorted list of FunctionCall objects representing all function calls in the code block and its decorators. The list may contain duplicates.

def function_calls(self) -> list[FunctionCall]:
    ...

has_semicolon

Checks whether the current symbol has a semicolon at the end.

This property determines if a semicolon is present at the end of the symbol by checking if the semicolon_node property exists.

Returns: bool: True if the symbol has a semicolon at the end, False otherwise.

def has_semicolon(self) -> bool:
    ...

inline_comment

Property that retrieves the inline comment group associated with the symbol.

Args: None

Returns: TSCommentGroup | None: The inline comment group associated with the symbol if it exists, otherwise None.

def inline_comment(self) -> TSCommentGroup | None:
    ...

is_decorated

Checks if the current symbol has a decorator.

Determines if the symbol has a preceding decorator node.

Returns: bool: True if the symbol has a decorator node as its previous named sibling, False otherwise.

def is_decorated(self) -> bool:
    ...

is_exported

Returns True if the symbol is exported from the file it’s defined in.

This property determines whether the symbol has an associated export object, indicating that the symbol is exported from its defining file.

Returns: bool: True if the symbol has an export object, False otherwise.

def is_exported(self) -> bool:
    ...

is_reexported

Returns True if the symbol is re-exported from a file where it is not defined.

Determines if this symbol is exported from a different file than where it was originally defined. A re-export occurs when a symbol is imported into a file and then exported from that same file.

Returns: bool: True if the symbol is re-exported from a different file than where it was defined, False otherwise.

def is_reexported(self) -> bool:
    ...

jsx_elements

Returns a list of all JSX elements contained within this symbol.

Searches through the extended nodes of the symbol for any JSX elements or self-closing JSX elements and returns them as a list of JSXElement objects.

Args: None

Returns: list[JSXElement[Self]]: A list of JSXElement objects contained within this symbol.

def jsx_elements(self) -> list[JSXElement[Self]]:
    ...

name

Retrieves the name of the object excluding any namespace prefixes.

Returns the “base” name of the object without any namespace or module prefix. For instance, for an object ‘a.b’, this method returns ‘b’.

Returns: str | None: The base name of the object as a string, or None if there is no associated name node.

def name(self) -> str | None:
    ...

parent_class

Find the class this node is contained in

def parent_class(self) -> Class | None:
    ...

parent_function

Find the function this node is contained in

def parent_function(self) -> Function | None:
    ...

parent_statement

Find the statement this node is contained in

def parent_statement(self) -> Statement | None:
    ...

resolved_value

Returns the resolved type of an Expression.

Returns the inferred type of the expression. For example a function call’s resolved value will be it’s definition.

Returns: Union[Expression, list[Expression]]: The resolved expression type(s). Returns a single Expression if there is only one resolved type, or a list of Expressions if there are multiple resolved types. Returns self if the expression is not resolvable or has no resolved types.

def resolved_value(self) -> Expression | list[Expression]:
    ...

semicolon_node

Retrieves the semicolon node associated with a TypeScript symbol.

A semicolon node is a TreeSitter node of type ’;’ that appears immediately after the symbol node.

Returns: Editable | None: The semicolon node wrapped as an Editable if it exists, None otherwise.

def semicolon_node(self) -> Editable | None:
    ...

source

Returns the source code of the symbol.

Gets the source code of the symbol from its extended representation, which includes any comments, docstrings, access identifiers, or decorators.

Returns: str: The complete source code of the symbol including any extended nodes.

def source(self) -> str:
    ...

variable_usages

Returns Editables for all TreeSitter node instances of variable usages within this node’s scope.

This method finds all variable identifier nodes in the TreeSitter AST, excluding:

  • Function names in function calls
  • Import names in import statements
  • Property access identifiers (except the base object)
  • Keyword argument names (in Python and TypeScript)

This is useful for variable renaming and usage analysis within a scope.

Returns: list[Editable]: A list of Editable nodes representing variable usages. Each Editable corresponds to a TreeSitter node instance where the variable is referenced.

def variable_usages(self) -> list[Editable]:
    ...

Attributes


code_block

The code block that contains the interface’s body.

code_block: TCodeBlock

parent_interfaces

All the interfaces that this interface extends.

parent_interfaces: Parents[TType, Self] | None

Methods


add_comment

Adds a new comment to the symbol.

Appends a comment to an existing comment group or creates a new comment group if none exists.

Args: comment (str): The comment text to be added. auto_format (bool): Whether to automatically format the text into a comment style. Defaults to True. clean_format (bool): Whether to clean the format of the comment before inserting. Defaults to True. comment_type (TSCommentType): Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH.

Returns: None

Raises: None

def add_comment(self, comment: str, auto_format: bool = True, clean_format: bool = True, comment_type: TSCommentType = TSCommentType.DOUBLE_SLASH) -> None:
    ...

add_decorator

Adds a decorator to a function or method.

Adds a new decorator to the symbol’s definition. The decorator is inserted before the first non-comment extended node with proper indentation.

Args: new_decorator (str): The decorator to add. Should be a complete decorator string including the ’@’ symbol. skip_if_exists (bool, optional): If True, will not add the decorator if it already exists. Defaults to False.

Returns: bool: True if the decorator was added, False if skipped due to existing decorator.

def add_decorator(self, new_decorator: str, skip_if_exists: bool = False) -> bool:
    ...

add_keyword

Insert a keyword in the appropriate place before this symbol if it doesn’t already exist.

This method adds a keyword (e.g., ‘public’, ‘async’, ‘static’) in the syntactically appropriate position relative to other keywords. If the keyword already exists, no action is taken.

Args: keyword (str): The keyword to be inserted. Must be a valid keyword in the language context.

Raises: AssertionError: If the provided keyword is not in the language’s valid keywords list.

def add_keyword(self, keyword: str):
    ...

ancestors

Find all ancestors of the node of the given type. Does not return itself

def ancestors(self, type: type[T]) -> list[T]:
    ...

edit

Replace the source of this node with new_src.

Edits the source code of this node by replacing it with the provided new source code. If specified, the indentation of the new source can be adjusted to match the current text’s indentation.

Args: new_src (str): The new source code to replace the current source with. fix_indentation (bool): If True, adjusts the indentation of new_src to match the current text’s indentation. Defaults to False. priority (int): The priority of this edit. Higher priority edits take precedence. Defaults to 0. dedupe (bool): If True, prevents duplicate edits. Defaults to True.

Returns: None

def edit(self, new_src: str, fix_indentation: bool = False, priority: int = 0, dedupe: bool = True) -> None:
    ...

extends

Returns True if the interface implements the given parent interface.

def extends(self, parent_interface: str | Interface, max_depth: int | None = None) -> bool:
    ...

find

Find and return matching nodes or substrings within an Editable instance.

This method searches through the extended_nodes of the Editable instance and returns all nodes or substrings that match the given search criteria.

Args: strings_to_match (Union[list[str], str]): One or more strings to search for. exact (bool): If True, only return nodes whose source exactly matches one of the strings_to_match. If False, return nodes that contain any of the strings_to_match as substrings. Defaults to False.

Returns: list[Editable]: A list of Editable instances that match the search criteria.

def find(self, strings_to_match: list[str] | str, *, exact: bool = False) -> list[Editable]:
    ...

find_string_literals

Returns a list of string literals within this node’s source that match any of the given strings.

Args: strings_to_match (list[str]): A list of strings to search for in string literals. fuzzy_match (bool): If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False.

Returns: list[Editable]: A list of Editable objects representing the matching string literals.

def find_string_literals(self, strings_to_match: list[str], fuzzy_match: bool = False) -> list[Editable]:
    ...

flag

Adds a visual flag comment to the end of this Editable’s source text.

Flags this Editable by appending a comment with emoji flags at the end of its source text. This is useful for visually highlighting specific nodes in the source code during development and debugging.

Returns: None

def flag(self, **kwargs: Unpack[FlagKwargs]) -> CodeFlag[Self]:
    ...

get_attribute

Returns the attribute with the given name, if it exists.

Otherwise, returns None.

def get_attribute(self, name: str) -> TAttribute | None:
    ...

get_component

Returns a specific JSX element from within this symbol’s JSX elements.

Searches through all JSX elements in this symbol’s code block and returns the first one that matches the given component name.

Args: component_name (str): The name of the JSX component to find.

Returns: JSXElement[Self] | None: The matching JSX element if found, None otherwise.

def get_component(self, component_name: str) -> JSXElement[Self] | None:
    ...

get_import_string

Generates the appropriate import string for a symbol.

Constructs and returns an import statement string based on the provided parameters, formatting it according to TypeScript import syntax rules.

Args: alias (str | None, optional): The alias to use for the imported symbol. Defaults to None. module (str | None, optional): The module to import from. If None, uses the file’s import module name. Defaults to None. import_type (ImportType, optional): The type of import to generate (e.g., WILDCARD). Defaults to ImportType.UNKNOWN. is_type_import (bool, optional): Whether this is a type-only import. Defaults to False.

Returns: str: A formatted import statement string.

def get_import_string(self, alias: str | None = None, module: str | None = None, import_type: ImportType = ImportType.UNKNOWN, is_type_import: bool = False) -> str:
    ...

get_name

Returns the Name node of the object.

Retrieves the name node of the object which can be used for modification operations.

Returns: Name | ChainedAttribute | None: The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name.

def get_name(self) -> Name | ChainedAttribute | None:
    ...

get_variable_usages

Returns Editables for all TreeSitter nodes corresponding to instances of variable usage that matches the given variable name.

Retrieves a list of variable usages that match a specified name, with an option for fuzzy matching. By default, excludes property identifiers and argument keywords.

Args: var_name (str): The variable name to search for. fuzzy_match (bool): If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False.

Returns: list[Editable]: List of Editable objects representing variable usage nodes matching the given name.

def get_variable_usages(self, var_name: str, fuzzy_match: bool = False) -> list[Editable]:
    ...

implementations

Returns all classes and interfaces that implement a given interface.

Note: This method can be called as both a property or a method. If used as a property, it is equivalent to invoking it without arguments.

def implementations(self, max_depth: int | None = None) -> list[Interface | Class]:
    ...

insert_after

Inserts code after this node.

Args: new_src (str): The source code to insert after this node. fix_indentation (bool, optional): Whether to adjust the indentation of new_src to match the current node. Defaults to False. newline (bool, optional): Whether to add a newline before the new_src. Defaults to True. priority (int, optional): Priority of the insertion transaction. Defaults to 0. dedupe (bool, optional): Whether to deduplicate identical transactions. Defaults to True.

Returns: None

def insert_after(self, new_src: str, fix_indentation: bool = False, newline: bool = True, priority: int = 0, dedupe: bool = True) -> None:
    ...

insert_before

Inserts text before the current symbol node in the Abstract Syntax Tree.

Handles insertion of new source code before a symbol, with special handling for extended nodes like comments and decorators. The insertion can be done either before the symbol itself or before its extended nodes.

Args: new_src (str): The source code text to insert. fix_indentation (bool): Whether to adjust the indentation of new_src to match current text. Defaults to False. newline (bool): Whether to add a newline after insertion. Defaults to True. priority (int): Priority of this edit operation. Higher priority edits are applied first. Defaults to 0. dedupe (bool): Whether to remove duplicate insertions. Defaults to True. extended (bool): Whether to insert before extended nodes like comments and decorators. Defaults to True.

Returns: None

def insert_before(self, new_src: str, fix_indentation: bool = False, newline: bool = True, priority: int = 0, dedupe: bool = True, extended: bool = True) -> None:
    ...

is_wrapped_in

Check if this node is contained another node of the given class

def is_wrapped_in(self, cls: type[Expression]) -> bool:
    ...

move_to_file

Moves the given symbol to a new file and updates its imports and references.

This method moves a symbol to a new file and updates all references to that symbol throughout the codebase. The way imports are handled can be controlled via the strategy parameter.

Args: file (SourceFile): The destination file to move the symbol to. include_dependencies (bool): If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True. strategy (str): The strategy to use for updating imports. Can be either ‘add_back_edge’ or ‘update_all_imports’. Defaults to ‘update_all_imports’.

  • ‘add_back_edge’: Moves the symbol and adds an import in the original file
  • ‘update_all_imports’: Updates all imports and usages of the symbol to reference the new file

Returns: None

Raises: AssertionError: If an invalid strategy is provided.

def move_to_file(self, file: SourceFile, include_dependencies: bool = True, strategy: str = "update_all_imports") -> None:
    ...

parent_of_type

Find the first ancestor of the node of the given type. Does not return itself

def parent_of_type(self, type: type[T]) -> T | None:
    ...

reduce_condition

Reduces an editable to the following condition

def reduce_condition(self, bool_condition: bool, node: Editable | None = None) -> None:
    ...

remove

Deletes this Node and its related extended nodes (e.g. decorators, comments).

Removes the current node and its extended nodes (e.g. decorators, comments) from the codebase. After removing the node, it handles cleanup of any surrounding formatting based on the context.

Args: delete_formatting (bool): Whether to delete surrounding whitespace and formatting. Defaults to True. priority (int): Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0. dedupe (bool): Whether to deduplicate removal transactions at the same location. Defaults to True.

Returns: None

def remove(self, delete_formatting: bool = True, priority: int = 0, dedupe: bool = True) -> None:
    ...

rename

Renames the symbol and all its references in the codebase.

Renames a symbol to a new name and updates all references to that symbol throughout the codebase, including imports and call sites.

Args: new_name (str): The new name for the symbol. priority (int): Priority of the edit operation. Defaults to 0.

Returns: tuple[NodeId, NodeId]: A tuple containing the file node ID and the new node ID of the renamed symbol.

def rename(self, new_name: str, priority: int = 0):
    ...

replace

Search and replace occurrences of text within this node’s source and its extended nodes.

This method performs string replacement similar to Python’s string.replace(), with support for regex patterns. It operates on both the main node and any extended nodes (e.g. decorators, exports).

Args: old (str): The text or pattern to search for. new (str): The text to replace matches with. count (int, optional): Maximum number of replacements to make. Defaults to -1 (replace all). is_regex (bool, optional): Whether to treat ‘old’ as a regex pattern. Defaults to False. priority (int, optional): Priority of the replacement operation. Defaults to 0.

Returns: int: The total number of replacements made.

Raises: ValueError: If there are multiple occurrences of the substring in a node’s source.

def replace(self, old: str, new: str, count: int = -1, is_regex: bool = False, priority: int = 0) -> int:
    ...

Returns a list of all regex match of regex_pattern, similar to python’s re.search().

Searches for matches of a regular expression pattern within the text of this node and its extended nodes.

Args: regex_pattern (str): The regular expression pattern to search for. include_strings (bool): When False, excludes the contents of string literals from the search. Defaults to True. include_comments (bool): When False, excludes the contents of comments from the search. Defaults to True.

Returns: list[Editable]: A list of Editable objects corresponding to the matches found.

def search(self, regex_pattern: str, include_strings: bool = True, include_comments: bool = True) -> list[Editable]:
    ...

set_comment

Sets a comment to the symbol.

Adds or updates a comment for a code symbol. If a comment already exists, it will be edited. If no comment exists, a new comment group will be created.

Args: comment (str): The comment text to be added. auto_format (bool, optional): Whether to automatically format the text into a comment syntax. Defaults to True. clean_format (bool, optional): Whether to clean the format of the comment before inserting. Defaults to True. comment_type (TSCommentType, optional): The style of comment to add. Defaults to TSCommentType.DOUBLE_SLASH.

Returns: None

Raises: None

def set_comment(self, comment: str, auto_format: bool = True, clean_format: bool = True, comment_type: TSCommentType = TSCommentType.DOUBLE_SLASH) -> None:
    ...

set_docstring

Sets or updates a docstring for a code element.

Adds a new docstring if none exists, or updates the existing docstring. Handles formatting and placement of the docstring according to the specified parameters.

Args: docstring (str): The docstring text to be added or updated. auto_format (bool, optional): Whether to automatically format the text into a docstring format. Defaults to True. clean_format (bool, optional): Whether to clean existing formatting from the docstring before inserting. Defaults to True. leading_star (bool, optional): Whether to add leading ”*” to each line of the comment block. Defaults to True. force_multiline (bool, optional): Whether to force single line comments to be multi-line. Defaults to False.

Returns: None

def set_docstring(self, docstring: str, auto_format: bool = True, clean_format: bool = True, leading_star: bool = True, force_multiline: bool = False) -> None:
    ...

set_inline_comment

Sets an inline comment to the symbol.

Sets or replaces an inline comment for a symbol at its current position. If an inline comment already exists, it is replaced with the new comment. If no inline comment exists, a new one will be created adjacent to the symbol.

Args: comment (str): The inline comment text to be added. auto_format (bool, optional): Whether to automatically format the text as a comment. Defaults to True. clean_format (bool, optional): Whether to clean the comment format before inserting. Defaults to True. node (TSNode | None, optional): The specific node to attach the comment to. Defaults to None.

Returns: None

Raises: None

def set_inline_comment(self, comment: str, auto_format: bool = True, clean_format: bool = True, node: TSNode | None = None) -> None:
    ...

set_name

Sets the name of a code element.

Modifies the name of the object’s underlying name node. Works with both simple names and chained attributes (e.g., ‘a.b’).

Args: name (str): The new name to set for the object.

Returns: None

def set_name(self, name: str) -> None:
    ...

symbol_usages

Returns a list of symbols that use the exportable object or import it. Returns symbols that use this exportable object, including imports that import this exportable object. By default, returns all usages. This shows where this symbol is imported, but not where it is subsequently used.

Args: usage_types: The types of usages to search for. Defaults to any.

  • DIRECT: Direct uses of the symbol
  • CHAINED: Uses through method/attribute chains
  • INDIRECT: Uses through renamed imports
  • ALIASED: Uses through aliases

Returns: list[Import | Symbol | Export]: A list of symbols that use this exportable object, including imports that import it.

Note: This method can be called as both a property or a method. If used as a property, it is equivalent to invoking it without arguments.

def symbol_usages(self, usage_types: UsageType | None = None) -> list[Import | Symbol | Export]:
    ...

usages

Returns a list of usages of the exportable object.

Retrieves a list of all locations where the exportable object is used in the codebase. By default, returns all usages, such as imports or references within the same file.

Args: usage_types: Specifies which types of usages to include in the results. Default is any usages. (graph_sitter.core.dataclasses.usage.UsageType)

Returns: list[Usage]: A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse.

Raises: ValueError: If no usage types are specified or if only ALIASED and DIRECT types are specified together.

Note: This method can be called as both a property or a method. If used as a property, it is equivalent to invoking it without arguments.

def usages(self, usage_types: UsageType | None = None) -> list[Usage]:
    ...

Was this page helpful?