diff --git a/.gitignore b/.gitignore index 489e43a1e..2a2fa330b 100644 --- a/.gitignore +++ b/.gitignore @@ -67,8 +67,3 @@ codegen-sdk/typings/** coverage.json tests/verified_codemods/codemod_data/repo_commits.json -# =====[ Docs ]===== -# These are auto-generated -docs/api-reference/core/* -docs/api-reference/python/* -docs/api-reference/typescript/* diff --git a/docs/api-reference/core/Argument.mdx b/docs/api-reference/core/Argument.mdx new file mode 100644 index 000000000..cb44cc09c --- /dev/null +++ b/docs/api-reference/core/Argument.mdx @@ -0,0 +1,513 @@ +--- +title: "Argument" +sidebarTitle: "Argument" +icon: "" +description: "Represents an argument passed into a FunctionCall." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of function calls present in the value of this argument." /> + +### index + +int } description="Returns the zero-based index of this argument within its parent function call." /> + +### is_named + +bool } description="Determines if an argument is being passed as a named keyword argument." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### type + +str } description="Gets the `Tree-sitter` type of the argument's value node." /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_keyword +Converts an unnamed argument to a named argument by adding a keyword. + + + +str } + description="The keyword name to be added to the argument." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Argument ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Assignment.mdx b/docs/api-reference/core/Assignment.mdx new file mode 100644 index 000000000..bad557cd3 --- /dev/null +++ b/docs/api-reference/core/Assignment.mdx @@ -0,0 +1,669 @@ +--- +title: "Assignment" +sidebarTitle: "Assignment" +icon: "" +description: "Represents an assignment for a single variable within an assignment statement. + +Attributes: +left: The left side of the assignment +right: The right side of the assignment + +Example: +```typescript +var z +var z = 5 +``` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Typeable](/api-reference/core/Typeable), [Symbol](/api-reference/core/Symbol), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### comment + +CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="Returns the index of the assignment statement in its parent's code block." /> + +### inline_comment + +CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> + +### is_local_variable + +bool } description="Determines if an assignment represents a local variable in the current scope." /> + +### is_typed + +bool } description="Indicates if a node has an explicit type annotation." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type + +Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a comment to the symbol. + + + +str } + description="The comment text to add." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Assignment ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### local_usages +Retrieves all usages of the assigned variable within its code block scope. + + + +list[ Editable [ Statement ]] } description="A sorted list of statement nodes where the variable is used."/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies an assignment expression by reducing it based on a boolean condition and updating all the usages. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to set." + defaultValue="" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The text of the inline comment to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_type_annotation +Adds or updates a type annotation for the current assignment. + + + +str } + description="The type annotation to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of an assignment expression. + + + +str } + description="The source code string representing the new value to be assigned." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/AssignmentStatement.mdx b/docs/api-reference/core/AssignmentStatement.mdx new file mode 100644 index 000000000..2ec3629d0 --- /dev/null +++ b/docs/api-reference/core/AssignmentStatement.mdx @@ -0,0 +1,471 @@ +--- +title: "AssignmentStatement" +sidebarTitle: "AssignmentStatement" +icon: "" +description: "A class that represents an assignment statement in a codebase, such as `x = 1`, `a, b = 1, 2`, `const {a: b} = myFunc(),`, etc. + +This includes potentially multiple Assignments via `statement.assignments`, which represent each assignment of a value to a variable within this statement. + +For example, assigning to a destructured object, or assigning multiple values to multiple variables in a single statement. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### assignments + +list[ Assignment ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### left + +Expression [ Assignment ] } description=" +" /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ AssignmentStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ Assignment ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ AssignmentStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Attribute.mdx b/docs/api-reference/core/Attribute.mdx new file mode 100644 index 000000000..7ea2fdab2 --- /dev/null +++ b/docs/api-reference/core/Attribute.mdx @@ -0,0 +1,550 @@ +--- +title: "Attribute" +sidebarTitle: "Attribute" +icon: "" +description: "Abstract representation of an attribute on a class definition." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Usable](/api-reference/core/Usable), [AssignmentStatement](/api-reference/core/AssignmentStatement), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### assignment + +Assignment } description=" +" /> + +### assignments + +list[ Assignment ] } description=" +" /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_optional + +bool } description="Returns whether the attribute is optional." /> + +### is_private + +bool } description="Indicates whether the attribute is private." /> + +### left + +Expression [ Assignment ] } description=" +" /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ Attribute ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ Assignment ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Attribute ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of a node's assignment. + + + +str } + description="The new value to set for the assignment." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/AwaitExpression.mdx b/docs/api-reference/core/AwaitExpression.mdx new file mode 100644 index 000000000..fa204d8da --- /dev/null +++ b/docs/api-reference/core/AwaitExpression.mdx @@ -0,0 +1,442 @@ +--- +title: "AwaitExpression" +sidebarTitle: "AwaitExpression" +icon: "" +description: "An awaited expression, only found in asynchronous contexts, e.g. await(foo(bar))" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the await expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ AwaitExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### resolve +Resolves the wrapper expression and returns the first concrete expression. + + + +Expression } description=""/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/BinaryExpression.mdx b/docs/api-reference/core/BinaryExpression.mdx new file mode 100644 index 000000000..d5dbaa2c0 --- /dev/null +++ b/docs/api-reference/core/BinaryExpression.mdx @@ -0,0 +1,440 @@ +--- +title: "BinaryExpression" +sidebarTitle: "BinaryExpression" +icon: "" +description: "Represents binary expressions, e.g. all of +,-,*,/, as well as booleaneoperations (and, or) etc." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### elements + +list[ Expression [ BinaryExpression ]] } description="Returns all elements in a binary expression chain." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### left + +Expression [ ComparisonExpression ] | None } description=" +" /> + +### node_type + +NodeType } description=" +" /> + +### operators + +list[ ExpressionGroup [ Expression [ BinaryExpression ], BinaryExpression ]] } description="Returns a list of operators in a chain of binary operations." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ ComparisonExpression ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ BinaryExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a binary expression by reducing it based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/BlockStatement.mdx b/docs/api-reference/core/BlockStatement.mdx new file mode 100644 index 000000000..1825fa89c --- /dev/null +++ b/docs/api-reference/core/BlockStatement.mdx @@ -0,0 +1,487 @@ +--- +title: "BlockStatement" +sidebarTitle: "BlockStatement" +icon: "" +description: "Statement which contains a block." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ BlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ BlockStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + + diff --git a/docs/api-reference/core/Boolean.mdx b/docs/api-reference/core/Boolean.mdx new file mode 100644 index 000000000..723ae009b --- /dev/null +++ b/docs/api-reference/core/Boolean.mdx @@ -0,0 +1,416 @@ +--- +title: "Boolean" +sidebarTitle: "Boolean" +icon: "" +description: "A boolean value eg. + +True, False +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Boolean ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Callable.mdx b/docs/api-reference/core/Callable.mdx new file mode 100644 index 000000000..463085a3b --- /dev/null +++ b/docs/api-reference/core/Callable.mdx @@ -0,0 +1,551 @@ +--- +title: "Callable" +sidebarTitle: "Callable" +icon: "" +description: "Any symbol that can be invoked with arguments eg. + +Function, Class, Decorator, ExternalModule +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parameters + +SymbolGroup [ Parameter , Callable ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Callable ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/CatchStatement.mdx b/docs/api-reference/core/CatchStatement.mdx new file mode 100644 index 000000000..29499bd5b --- /dev/null +++ b/docs/api-reference/core/CatchStatement.mdx @@ -0,0 +1,496 @@ +--- +title: "CatchStatement" +sidebarTitle: "CatchStatement" +icon: "" +description: "Abstract representation catch clause. + +Attributes: +code_block: The code block that may trigger an exception +condition: The condition which triggers this clause +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### condition + +Expression [ PyCatchStatement ] | None } description="The condition which triggers this clause" /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ CatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ CatchStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + + diff --git a/docs/api-reference/core/ChainedAttribute.mdx b/docs/api-reference/core/ChainedAttribute.mdx new file mode 100644 index 000000000..d431a17aa --- /dev/null +++ b/docs/api-reference/core/ChainedAttribute.mdx @@ -0,0 +1,429 @@ +--- +title: "ChainedAttribute" +sidebarTitle: "ChainedAttribute" +icon: "" +description: "An attribute of an object. (IE a method on a class, a function from a module, etc) + +Examples: +A.method() +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### attribute + +Attribute } description="Gets the attribute being accessed in a chained attribute expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str } description="Returns the full name of the attribute, including the object expression." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### object + +Object } description="Returns the object that contains the attribute being looked up." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ChainedAttribute ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Class.mdx b/docs/api-reference/core/Class.mdx new file mode 100644 index 000000000..f3eeda9f3 --- /dev/null +++ b/docs/api-reference/core/Class.mdx @@ -0,0 +1,972 @@ +--- +title: "Class" +sidebarTitle: "Class" +icon: "" +description: "Abstract representation of a Class definition." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Symbol](/api-reference/core/Symbol), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### comment + +CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> + +### constructor + +Function | None } description="Returns the constructor method for this class." /> + +### constructor_keyword + + } description=" +" /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### inline_comment + +CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### is_subclass + +bool } description="Indicates whether the current class is a subclass of another class." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_classes + +list[ Class ] } description="Retrieves the nested classes defined within this class." /> + +### node_type + +NodeType } description=" +" /> + +### parameters + +SymbolGroup [ Parameter , Class ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_class_names + +list[ Name | ChainedAttribute ] } description="Returns a list of the parent class names that this class inherits from." /> + +### parent_classes + +Parents[ Type , PyClass ] | None } description=" +" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_attribute +Adds an attribute to a class from another class. + + + +Attribute } + description="The attribute to add to the class." + defaultValue="" +/> +bool, optional } + description="Whether to include the attribute's dependencies. If True, adds any necessary imports to the class's file. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### add_attribute_from_source +Adds an attribute to a class from raw source code, placing it in a specific location + + + +str } + description="The source code of the attribute to be added." + defaultValue="" +/> + + + +None } description=""/> + + +### add_comment +Adds a comment to the symbol. + + + +str } + description="The comment text to add." + defaultValue="" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_source +Add a block of source code to the bottom of a class definition. + + + +str } + description="The source code to be added to the class definition. The code should be properly formatted" + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### attributes +Retrieves all attributes from this Class including those from its superclasses up to a + + + +int | None } + description="The maximum depth of superclass traversal. None means no limit, 0 means only this class." + defaultValue="0" +/> +bool } + description="Whether to include private attributes. Defaults to True." + defaultValue="True" +/> + + + +list[ Attribute ] } description="A list of unique attributes from this class and its superclasses. If an attribute is defined in multiple classes, the first definition encountered is used."/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Class ] } description=""/> + + +### get_attribute +Returns a specific attribute by name. + + + +str } + description="The name of the attribute to search for." + defaultValue="" +/> + + + +Attribute | None } description="The matching attribute if found, None otherwise. If multiple attributes with the same name exist in the inheritance hierarchy, returns the first one found."/> + + +### get_method +Returns a specific method by name from the class or any of its superclasses. + + + +str } + description="The name of the method to find." + defaultValue="" +/> + + + +Function | None } description="The method if found, None otherwise."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_nested_class +Returns a nested class by name from the current class. + + + +str } + description="The name of the nested class to find." + defaultValue="" +/> + + + +Class | None } description="The nested class if found, None otherwise."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_parent_class +Returns the parent class node with the specified name. + + + +str } + description="The name of the parent class to find." + defaultValue="" +/> + + + +Editable | None } description="The matching parent class node, or None if no match is found."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_subclass_of +Checks if the class inherits from a specified parent class. + + + +str | Class } + description="The parent class to check for. Can be specified either as a class name string or Class object." + defaultValue="" +/> +int | None } + description="Maximum inheritance depth to search. None means no limit." + defaultValue="None" +/> + + + +bool } description="True if this class inherits from the parent class, False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### methods +Retrieves all methods that exist on this Class, including methods from superclasses, with + + + +int | None, optional } + description="Include parent classes up to max_depth. None means no limit, 0 means only current class. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to include private methods. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include magic methods. Defaults to False." + defaultValue="True" +/> + + + +list[ Function ] | MultiLineCollection [ Function , Class ] } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to set." + defaultValue="" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The text of the inline comment to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### subclasses +Returns all classes which subclass this class. + + + +int | None, optional } + description="Maximum inheritance depth to search. If None, searches all depths. Defaults to None." + defaultValue="None" +/> + + + +list[ Class ] } description="A list of Class objects that inherit from this class."/> + + +### superclasses +Returns a list of all classes that this class extends, up to max_depth. + + + +int | None } + description="The maximum depth to traverse up the inheritance tree. If None, traverses the entire tree." + defaultValue="None" +/> + + + +list[ Class | ExternalModule | Interface] } description="A list of all superclass symbols in MRO order, up to max_depth. Returns an empty list if the class has no parent classes."/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/CodeBlock.mdx b/docs/api-reference/core/CodeBlock.mdx new file mode 100644 index 000000000..2cafd7d86 --- /dev/null +++ b/docs/api-reference/core/CodeBlock.mdx @@ -0,0 +1,589 @@ +--- +title: "CodeBlock" +sidebarTitle: "CodeBlock" +icon: "" +description: "Container class for a list of code Statements that share an indentation level, e.g. a +function body or class body. + +Enables various types of queries and operations on the code block. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### assignment_statements + +list[ AssignmentStatement [ CodeBlock , Assignment ]] } description="Returns list of top level assignment statements in the code block." /> + +### assignments + +list[ Assignment [ Editable , CodeBlock ]] } description="Returns all assignments in the code block across all nesting levels." /> + +### attributes + +list[ Attribute [ Editable , CodeBlock ]] } description="Returns a list of top level class attribute statements in the code block." /> + +### comments + +list[ Comment [ Editable , CodeBlock ]] } description="Gets list of top level comments in the code block." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls in the code block." /> + +### if_blocks + +list[ IfBlockStatement [ CodeBlock ]] } description="Returns a list of top level if statements in the code block." /> + +### level + +int } description=" +" /> + +### local_var_assignments + +list[ Assignment [ Editable , CodeBlock ]] } description="Returns all local variable assignment in the code block, for all nest levels." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_block + +CodeBlock | None } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_statements + +list[ ReturnStatement [ CodeBlock ]] } description="Gets all return statements at the top level of the code block." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statements + +MultiLineCollection [ Statement , CodeBlock ] } description="Gets a view of the top-level statements in the code block." /> + +### symbol_statements + +list[ SymbolStatement ] } description="Returns list of top level symbol statements in the code block." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ CodeBlock ] } description=""/> + + +### get_assignments +Returns a list of assignments with the specified variable name. + + + +str } + description="The name of the variable to find assignments for." + defaultValue="" +/> + + + +list[ Assignment [ Editable , CodeBlock ]] } description="A list of Assignment objects that match the variable name."/> + + +### get_attributes +Returns attributes from the code block, with the option to include or exclude private + + + +bool } + description="Whether to include private attributes in the returned list. If True, returns both private and" + defaultValue="" +/> + + + +list[ Attribute [ Editable , CodeBlock ]] } description="A list of attribute statements matching the privacy criteria."/> + + +### get_comment +Gets the first comment statement containing a specific text string. + + + +str } + description="The text string to search for within comment statements." + defaultValue="" +/> + + + +Comment [ Editable , CodeBlock ] | None } description="The first comment statement containing the search text, or None if no matching comment is found."/> + + +### get_local_var_assignment +Returns the first code statement that assigns a local variable with the specified name. + + + +str } + description="The name of the local variable to search for." + defaultValue="" +/> + + + +Assignment [ Editable , CodeBlock ] | None } description="The first matching local variable assignment, or None if no match is found."/> + + +### get_local_var_assignments +Returns all instances of local variable assignments that match the specified variable + + + +str } + description="The name of the local variable to search for." + defaultValue="" +/> +bool, optional } + description="If True, matches variables whose names contain var_name." + defaultValue="False" +/> + + + +list[ Assignment [ Editable , CodeBlock ]] } description="List of Assignment objects representing local variable assignments that match the specified name criteria."/> + + +### get_statements +Returns all statements of a given type up to the specified block level. + + + +StatementType | None } + description="The type of statements to return. If None, returns all statement types." + defaultValue="None" +/> +int | None } + description="The maximum block depth level to search. If None, searches all levels." + defaultValue="None" +/> + + + +list[ Statement [ CodeBlock ]] } description=""/> + + +### get_variable_usages +Returns all instances of variable usages in a code block. + + + +str } + description="The name of the variable to search for." + defaultValue="" +/> +bool } + description="When True, matches on variable names that contain var_name. When False (default), only matches exact variable names." + defaultValue="False" +/> + + + +list[ Editable [ CodeBlock ]] } description="A sorted list of variable usage instances as Editable objects."/> + + +### indent +Adjusts the indentation level of the entire code block. + + + +int } + description="The number of indentation levels to adjust. Positive values indent right, negative values indent left." + defaultValue="" +/> + + + +None } description=""/> + + +### insert_before +Inserts new source code at the top of the code block. + + + +str } + description="The source code to insert at the top of the code block." + defaultValue="" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename_variable_usages +Renames all instances of variable usages in the code block. + + + +str } + description="The current name of the variable to rename." + defaultValue="" +/> +str } + description="The new name to give the variable." + defaultValue="" +/> +bool } + description="When True, matches variables containing old_var_name. When False, only exact matches. Defaults to False." + defaultValue="False" +/> + + + +None } description="This method mutates the code block in place."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### unwrap +Extracts a code block from its parent wrapper container by removing the wrapping + + + +None } description=""/> + + +### wrap +Wraps a code block with a statement and indents it. + + + +str } + description="The source code to insert before the block." + defaultValue="" +/> +str } + description="The source code to insert after the block. Defaults to an empty string." + defaultValue="""" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Codebase.mdx b/docs/api-reference/core/Codebase.mdx new file mode 100644 index 000000000..c7da89413 --- /dev/null +++ b/docs/api-reference/core/Codebase.mdx @@ -0,0 +1,567 @@ +--- +title: "Codebase" +sidebarTitle: "Codebase" +icon: "" +description: "This class provides the main entrypoint for most programs to analyzing and manipulating codebases. + +It provides a high-level interface to interact with the codebase graph, and provides methods to access and manipulate files, directories, symbols, and other entities in the codebase. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### classes + +list[ Class ] } description="List of all Classes in the codebase." /> + +### console + +Console } description=" +" /> + +### current_commit + +GitCommit | None } description="Returns the current Git commit that is checked out in the repository." /> + +### default_branch + +str } description="The default branch of this repository." /> + +### directories + +list[ Directory ] } description="List all directories in the codebase." /> + +### external_modules + +list[ ExternalModule ] } description="Returns a list of all external modules in the codebase." /> + +### functions + +list[ Function ] } description="List of all Functions in the codebase." /> + +### global_vars + +list[ Assignment ] } description="List of all GlobalVars in the codebase." /> + +### imports + +list[ Import ] } description="Returns a list of all Import nodes in the codebase." /> + +### interfaces + +list[TInterface] } description="Retrieves all interfaces in the codebase." /> + +### language + +ProgrammingLanguage } description="The programming language of the repository." /> + +### name + +str } description="The name of the repository." /> + +### repo_path + +Path } description=" +" /> + +### symbols + +list[ Symbol ] } description="List of all top-level Symbols (Classes, Functions, etc.) in the codebase. Excludes Class" /> + +### types + +list[ TypeAlias ] } description="List of all Types in the codebase (Typescript only)." /> + +### viz + +VisualizationManager } description=" +" /> + + +## Methods + +### ai +Generates a response from the AI based on the provided prompt, target, and context. + + + +str } + description="The text prompt to send to the AI." + defaultValue="" +/> +Editable | None } + description="An optional editable object (like a function, class, etc.) that provides the main focus for the AI's response." + defaultValue="None" +/> +Editable | list[ Editable ] | dict[str, Editable | list[ Editable ]] | None } + description="Additional context to help inform the AI's response." + defaultValue="None" +/> +str } + description="The AI model to use for generating the response. Defaults to "gpt-4o"." + defaultValue=""gpt-4o"" +/> + + + +str } description="The generated response from the AI."/> + + +### checkout +Checks out a git branch or commit and syncs the codebase graph to the new state. + + + +str | GitCommit | None } + description="Hash or GitCommit object to checkout. Cannot be used with branch." + defaultValue="None" +/> +str | None } + description="Name of branch to checkout. Cannot be used with commit." + defaultValue="None" +/> +bool } + description="If True, creates the branch if it doesn't exist. Defaults to False." + defaultValue="False" +/> +bool } + description="If True, attempts to pull from remote when checking out branch. Defaults to False." + defaultValue="False" +/> + + + +CheckoutResult } description="The result of the checkout operation."/> + + +### commit +Commits all staged changes to the codebase graph and synchronizes the graph with the filesystem if specified. + + + +bool } + description="Whether to synchronize the graph after committing changes. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### create_directory +Creates a directory at the specified path. + + + +str } + description="The path where the directory should be created." + defaultValue="" +/> +bool } + description="If True, don't raise an error if the directory already exists. Defaults to False." + defaultValue="False" +/> +bool } + description="If True, create any necessary parent directories. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### create_file +Creates a new file in the codebase with specified content. + + + +str } + description="The path where the file should be created." + defaultValue="" +/> +str } + description="The content of the file to be created. Defaults to empty string." + defaultValue="""" +/> +bool } + description="Whether to sync the graph after creating the file. Defaults to True." + defaultValue="True" +/> + + + +File } description="The newly created file object."/> + + +### files +A list property that returns all files in the codebase. + + + +list[ SourceFile ] | list[ File ] } description="A sorted list of source files in the codebase."/> + + +### find_by_span +Finds editable objects that overlap with the given source code span. + + + +Span } + description="The span object containing the filepath and byte range to search within." + defaultValue="" +/> + + + +list[ Editable ] } description="A list of Editable objects that overlap with the given span."/> + + +### get_class +Returns a class that matches the given name. + + + +str } + description="The name of the class to find." + defaultValue="" +/> +bool } + description="If True, return None when class is not found instead of raising ValueError. Defaults to False." + defaultValue="False" +/> + + + +Class | None } description="The class with the given name, or None if optional=True and class not found."/> + + +### get_directory +Returns Directory by `dir_path`, or full path to the directory from codebase root. + + + +str } + description="The path to the directory to retrieve." + defaultValue="" +/> +bool } + description="If True, return None when directory is not found. If False, raise ValueError." + defaultValue="False" +/> + + + +Directory | None } description="The Directory object if found, None if optional=True and directory not found."/> + + +### get_file +Retrieves a file from the codebase by its filepath. + + + +str } + description="The path to the file, relative to the codebase root." + defaultValue="" +/> +bool } + description="If True, return None if file not found. If False, raise ValueError." + defaultValue="False" +/> +bool } + description="If True, ignore case when checking for file existence. Defaults to False." + defaultValue="False" +/> + + + +SourceFile | None } description="The source file if found, None if optional=True and file not found."/> + + +### get_function +Retrieves a function from the codebase by its name. + + + +str } + description="The name of the function to retrieve." + defaultValue="" +/> +bool } + description="If True, returns None when function is not found instead of raising ValueError." + defaultValue="False" +/> + + + +Function | None } description="The matching function if found. If optional=True and no match is found, returns None."/> + + +### get_relative_path +Calculates a relative path from one file to another, removing the extension from the target file. + + + +str } + description="The file path from which the relative path will be computed." + defaultValue="" +/> +str } + description="The file path (whose extension will be removed) to which the relative path will be computed." + defaultValue="" +/> + + + +str } description="The relative path from `from_file` to `to_file` (with the extension removed from `to_file`)."/> + + +### get_symbol +Returns a Symbol by name from the codebase. + + + +str } + description="The name of the symbol to find." + defaultValue="" +/> +bool } + description="If True, returns None when symbol is not found. If False, raises ValueError. Defaults to False." + defaultValue="False" +/> + + + +Symbol | None } description="The matched Symbol if found, None if not found and optional=True."/> + + +### get_symbols +Retrieves all symbols in the codebase that match the given symbol name. + + + +str } + description="The name of the symbols to retrieve." + defaultValue="" +/> + + + +list[ Symbol ] } description="A list of Symbol objects that match the given name, sorted alphabetically."/> + + +### git_commit +Commits all staged changes to the codebase and git. + + + +str } + description="The commit message" + defaultValue="" +/> +bool } + description="Whether to verify the commit before committing. Defaults to False." + defaultValue="False" +/> + + + +GitCommit | None } description="The commit object if changes were committed, None otherwise."/> + + +### has_directory +Returns a boolean indicating if a directory exists in the codebase. + + + +str } + description="The path to the directory to check for, relative to the codebase root." + defaultValue="" +/> + + + +bool } description="True if the directory exists in the codebase, False otherwise."/> + + +### has_file +Determines if a file exists in the codebase. + + + +str } + description="The filepath to check for existence." + defaultValue="" +/> +bool } + description="If True, ignore case when checking for file existence. Defaults to False." + defaultValue="False" +/> + + + +bool } description="True if the file exists in the codebase, False otherwise."/> + + +### has_symbol +Returns whether a symbol exists in the codebase. + + + +str } + description="The name of the symbol to look for." + defaultValue="" +/> + + + +bool } description="True if a symbol with the given name exists in the codebase, False otherwise."/> + + +### reset +Resets the codebase by + + + +None } description=""/> + + +### set_ai_key +Sets the OpenAI key for the current Codebase instance. + + + +None } description=""/> + + +### set_session_options +Sets the Session options for the current codebase. + + + +None } description=""/> + + +### should_fix +Returns True if the flag should be fixed based on the current mode and active group. + + + +CodeFlag } + description="The code flag to check." + defaultValue="" +/> + + + +bool } description="True if the flag should be fixed, False if it should be ignored. Returns False in find mode. Returns True if no active group is set. Returns True if the flag's hash exists in the active group hashes."/> + + +### visualize +Visualizes a NetworkX graph or Plotly figure. + + + +Graph | go.Figure } + description="A NetworkX graph or Plotly figure to visualize" + defaultValue="" +/> +Editable | str | int | None } + description="The root node to visualize around. When specified, the visualization will be centered on this node. Defaults to None." + defaultValue="None" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Comment.mdx b/docs/api-reference/core/Comment.mdx new file mode 100644 index 000000000..175f08094 --- /dev/null +++ b/docs/api-reference/core/Comment.mdx @@ -0,0 +1,451 @@ +--- +title: "Comment" +sidebarTitle: "Comment" +icon: "" +description: "Abstract representation of comment statements." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns a list of nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ Comment ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### text + +str } description="Returns the text content of the comment." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### edit_text +Replace the text of a comment with new text. + + + +str } + description="The new text content to replace the existing comment text." + defaultValue="" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Comment ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/CommentGroup.mdx b/docs/api-reference/core/CommentGroup.mdx new file mode 100644 index 000000000..e2686bc2e --- /dev/null +++ b/docs/api-reference/core/CommentGroup.mdx @@ -0,0 +1,436 @@ +--- +title: "CommentGroup" +sidebarTitle: "CommentGroup" +icon: "" +description: "A group of comments that form a larger comment block." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Returns the concatenated source code of all symbols in the group." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### text + +str } description="Return the text content of all comments in the comment block." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new text. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool, optional } + description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Prevents duplicate edits at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### edit_text +Replace the text content of a comment group with new text. + + + +str } + description="The new text content to replace the existing comment text." + defaultValue="" +/> + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ CommentGroup ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes this node and its related extended nodes from the codebase. + + + +bool, optional } + description="Whether to delete related extended nodes like decorators and comments. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level of the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/core/ComparisonExpression.mdx b/docs/api-reference/core/ComparisonExpression.mdx new file mode 100644 index 000000000..8e7f4de93 --- /dev/null +++ b/docs/api-reference/core/ComparisonExpression.mdx @@ -0,0 +1,443 @@ +--- +title: "ComparisonExpression" +sidebarTitle: "ComparisonExpression" +icon: "" +description: "Any comparison expression in the code. + +Includes all set of `<`, `<=`, `>`, `>=`, `==`, `!=` etc. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[BinaryExpression](/api-reference/core/BinaryExpression), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### elements + +list[ Expression [ ComparisonExpression ]] } description="Returns a list of expressions for named child nodes." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### left + +Expression [ ComparisonExpression ] | None } description=" +" /> + +### node_type + +NodeType } description=" +" /> + +### operators + +list[ ExpressionGroup [ Expression [ ComparisonExpression ], ComparisonExpression ]] } description="Returns a list of operator expressions in a comparison expression." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ ComparisonExpression ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ComparisonExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a binary expression by reducing it based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Decorator.mdx b/docs/api-reference/core/Decorator.mdx new file mode 100644 index 000000000..e1c1ccce8 --- /dev/null +++ b/docs/api-reference/core/Decorator.mdx @@ -0,0 +1,467 @@ +--- +title: "Decorator" +sidebarTitle: "Decorator" +icon: "" +description: "Abstract representation of a Decorator." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### call + +FunctionCall | None } description="Returns any function call made by this decorator." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Decorator ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Dict.mdx b/docs/api-reference/core/Dict.mdx new file mode 100644 index 000000000..f3c7e2367 --- /dev/null +++ b/docs/api-reference/core/Dict.mdx @@ -0,0 +1,421 @@ +--- +title: "Dict" +sidebarTitle: "Dict" +icon: "" +description: "Represents a dict (object) literal the source code. + +You can use standard Python operations to operate on this dict (i.e. `len`, `del`, `set`, `get`, etc) +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### unpack + +Unpack [ TSObjectType ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Dict ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Directory.mdx b/docs/api-reference/core/Directory.mdx new file mode 100644 index 000000000..95b7e07e0 --- /dev/null +++ b/docs/api-reference/core/Directory.mdx @@ -0,0 +1,196 @@ +--- +title: "Directory" +sidebarTitle: "Directory" +icon: "" +description: "Directory representation for codebase. +GraphSitter abstraction of a file directory that can be used to look for files and symbols within a specific directory. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### classes + +list[ Class ] } description="Get a recursive list of all classes in the directory and its subdirectories." /> + +### dirpath + +str } description=" +" /> + +### files + +list[ File ] } description="Get a recursive list of all files in the directory and its subdirectories." /> + +### functions + +list[ Function ] } description="Get a recursive list of all functions in the directory and its subdirectories." /> + +### global_vars + +list[ Assignment ] } description="Get a recursive list of all global variables in the directory and its subdirectories." /> + +### import_statements + +list[ ImportStatement ] } description="Get a recursive list of all import statements in the directory and its subdirectories." /> + +### items + +dict[str, File | Directory ] } description=" +" /> + +### name + +str } description="Get the base name of the directory's path." /> + +### parent + +Directory | None } description=" +" /> + +### path + +Path } description=" +" /> + +### subdirectories + +list[ Directory ] } description="Get a recursive list of all subdirectories in the directory and its subdirectories." /> + +### symbols + +list[ Symbol ] } description="Get a recursive list of all symbols in the directory and its subdirectories." /> + + +## Methods + +### add_file +Add a file to the directory. + + + +None } description=""/> + + +### add_subdirectory +Add a subdirectory to the directory. + + + +None } description=""/> + + +### get_class +Get a class by name in the directory and its subdirectories. + + + +Class | None } description=""/> + + +### get_file +Get a file by its name relative to the directory. + + + +File | None } description=""/> + + +### get_function +Get a function by name in the directory and its subdirectories. + + + +Function | None } description=""/> + + +### get_global_var +Get a global variable by name in the directory and its subdirectories. + + + +Assignment | None } description=""/> + + +### get_import_statement +Get an import statement by name in the directory and its subdirectories. + + + +ImportStatement | None } description=""/> + + +### get_subdirectory +Get a subdirectory by its path relative to the directory. + + + +Directory | None } description=""/> + + +### get_symbol +Get a symbol by name in the directory and its subdirectories. + + + +Symbol | None } description=""/> + + +### remove_file +Remove a file from the directory. + + + +None } description=""/> + + +### remove_file_by_path +Remove a file from the directory by its path. + + + +None } description=""/> + + +### remove_subdirectory +Remove a subdirectory from the directory. + + + +None } description=""/> + + +### remove_subdirectory_by_path +Remove a subdirectory from the directory by its path. + + + +None } description=""/> + + +### rename +Rename the directory. + + + +None } description=""/> + + +### update_filepath +Update the filepath of the directory. + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Editable.mdx b/docs/api-reference/core/Editable.mdx new file mode 100644 index 000000000..6ac78ed8c --- /dev/null +++ b/docs/api-reference/core/Editable.mdx @@ -0,0 +1,411 @@ +--- +title: "Editable" +sidebarTitle: "Editable" +icon: "" +description: "An editable instance is an abstract text representation of any text in a file. + +The editable APIs enables text search and edit within the given Editable wrapper around any +group of text in a file. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Editable ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Export.mdx b/docs/api-reference/core/Export.mdx new file mode 100644 index 000000000..013c1609b --- /dev/null +++ b/docs/api-reference/core/Export.mdx @@ -0,0 +1,572 @@ +--- +title: "Export" +sidebarTitle: "Export" +icon: "" +description: "Represents a single symbol being exported." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Exportable](/api-reference/core/Exportable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### export_statement + +ExportStatement } description=" +" /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### exported_symbol + +Exportable | None } description="Returns the symbol, file, or import being exported from this export object." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_symbol + +Exportable | None } description="Returns the resolved symbol for an export." /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Export ] } description=""/> + + +### get_import_string +Returns the import string for a symbol. + + + +str | None } + description="Optional alias for the symbol." + defaultValue="None" +/> +str | None } + description="Optional module name to import from." + defaultValue="None" +/> +ImportType } + description="Type of import to generate." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Indicates if it's a type-only import." + defaultValue="False" +/> + + + +str } description="The formatted import string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_aliased +Determines if the Export object is aliased. + + + +bool } description="True if the exported symbol has a different name than the name it is exported as, False otherwise."/> + + +### is_module_export +Determines if the export is a module-level export. + + + +bool } description="True if the export is a module-level export, False otherwise."/> + + +### is_named_export +Determines if the export is named or default. + + + +bool } description="True if the export is named, False if it is default."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/ExportStatement.mdx b/docs/api-reference/core/ExportStatement.mdx new file mode 100644 index 000000000..262f65ebf --- /dev/null +++ b/docs/api-reference/core/ExportStatement.mdx @@ -0,0 +1,443 @@ +--- +title: "ExportStatement" +sidebarTitle: "ExportStatement" +icon: "" +description: "Abstract representation of a single export statement that appears in a file. One export +statement can export multiple symbols from a single source. + +Attributes: +exports: A list of the individual exports this statement represents +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### exports + +Collection[ Export , ExportStatement ] } description="A list of the individual exports this statement represents" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ ExportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### reexports + +list[ TSExport ] } description="Retrieves a list of re-exported symbols from this export statement." /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ExportStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Exportable.mdx b/docs/api-reference/core/Exportable.mdx new file mode 100644 index 000000000..aee70b2de --- /dev/null +++ b/docs/api-reference/core/Exportable.mdx @@ -0,0 +1,537 @@ +--- +title: "Exportable" +sidebarTitle: "Exportable" +icon: "" +description: "An interface for any node object that can be exported +eg. Class, class name, top-level functions, imports +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Exportable ] } description=""/> + + +### get_import_string +Returns the import string for a symbol. + + + +str | None } + description="Optional alias for the symbol." + defaultValue="None" +/> +str | None } + description="Optional module name to import from." + defaultValue="None" +/> +ImportType } + description="Type of import to generate." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Indicates if it's a type-only import." + defaultValue="False" +/> + + + +str } description="The formatted import string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/Expression.mdx b/docs/api-reference/core/Expression.mdx new file mode 100644 index 000000000..c42f84869 --- /dev/null +++ b/docs/api-reference/core/Expression.mdx @@ -0,0 +1,413 @@ +--- +title: "Expression" +sidebarTitle: "Expression" +icon: "" +description: "Represents an arbitrary Expression, such as List, Dict, Binary Expression, String." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Expression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/ExpressionGroup.mdx b/docs/api-reference/core/ExpressionGroup.mdx new file mode 100644 index 000000000..d6eb44caf --- /dev/null +++ b/docs/api-reference/core/ExpressionGroup.mdx @@ -0,0 +1,419 @@ +--- +title: "ExpressionGroup" +sidebarTitle: "ExpressionGroup" +icon: "" +description: "Group of contiguous set of expressions." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### expressions + +list[ Expression ] } description="Returns all expressions in the group." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the expression group." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Returns the source code of the symbol group." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new text. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool, optional } + description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Prevents duplicate edits at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ExpressionGroup ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes this node and its related extended nodes from the codebase. + + + +bool, optional } + description="Whether to delete related extended nodes like decorators and comments. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level of the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/core/ExpressionStatement.mdx b/docs/api-reference/core/ExpressionStatement.mdx new file mode 100644 index 000000000..97fd1197a --- /dev/null +++ b/docs/api-reference/core/ExpressionStatement.mdx @@ -0,0 +1,474 @@ +--- +title: "ExpressionStatement" +sidebarTitle: "ExpressionStatement" +icon: "" +description: "Abstract representation of any expression statements that resolves to an expression. In some +languages without a statement delimiter, expression statement and the enclosed expression looks +the same in text. + +For example, in Python: +```python +x = 1 +``` +The above code is an expression statement, but its expression value is an assignment. + +In Typescript: +```typescript +x = 1; +``` +The above code is also an expression statement, but its expression value is an assignment excluding the semicolon. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Get all function calls contained within this expression statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ ExpressionStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ExpressionStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### resolve +Resolves the wrapper expression and returns the first concrete expression. + + + +Expression } description=""/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/ExternalModule.mdx b/docs/api-reference/core/ExternalModule.mdx new file mode 100644 index 000000000..870d76a45 --- /dev/null +++ b/docs/api-reference/core/ExternalModule.mdx @@ -0,0 +1,605 @@ +--- +title: "ExternalModule" +sidebarTitle: "ExternalModule" +icon: "" +description: "Represents an external module, like `datetime`, that can be referenced. + +These are only added to the graph during import resolution and will not exist in a local file's +subgraph. This is because we don't know what an import is referencing or resolves to until we +see the full codebase. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Callable](/api-reference/core/Callable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +None } description="File property for ExternalModule class." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="Returns the filepath of the module." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.EXTERNAL] } description=" +" /> + +### parameters + +list[ Parameter ] } description="Returns list of named parameters from an external function symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ExternalModule ] } description=""/> + + +### from_import +Creates an ExternalModule instance from an Import instance. + + + +Import } + description="An Import instance containing the module information." + defaultValue="" +/> + + + +ExternalModule } description="A new ExternalModule instance representing the external module."/> + + +### get_import_string +Returns the import string used to import this module. + + + +str | None, optional } + description="An alternative name for the imported module." + defaultValue="None" +/> +str | None, optional } + description="The module from which to import." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate. Defaults to ImportType.UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type import. Defaults to False." + defaultValue="False" +/> + + + +str } description="The import string that can be used to import this module."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/File.mdx b/docs/api-reference/core/File.mdx new file mode 100644 index 000000000..05200ef76 --- /dev/null +++ b/docs/api-reference/core/File.mdx @@ -0,0 +1,481 @@ +--- +title: "File" +sidebarTitle: "File" +icon: "" +description: "Represents a generic file. + +Could represent a source file or a non-code file such as a markdown file or image file. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Editable](/api-reference/core/Editable) + +## Attributes + +### content + +str } description="Returns the content of the file as a UTF-8 encoded string." /> + +### directory + +Directory | None } description="Returns the directory that contains this file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### extension + +str } description="Returns the file extension." /> + +### file + +File } description="A property that returns the file object for non-source files." /> + +### file_node_id + +NodeId } description=" +" /> + +### file_path + +str } description=" +" /> + +### filepath + +str } description="Retrieves the file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### is_binary + +bool } description="Indicates whether the file contains binary data." /> + +### name + +str } description=" +" /> + +### node_type + +Literal[NodeType.FILE] } description=" +" /> + +### owners + +set[str] } description="Returns the CODEOWNERS of the file." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### path + +Path } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### start_byte + +int } description="Returns the starting byte position of a file in its content." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ File ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### parse +Parses the file representation into the graph. + + + +CodebaseGraph } + description="The codebase graph that the file belongs to." + defaultValue="" +/> + + + +None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes the file from the file system and graph. + + + +None } description=""/> + + +### rename +Renames the file to the specified name, preserving the file extension. + + + +str } + description="The new name for the file. If the new name includes the file extension, it will be used as-is." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### update_filepath +Updates the file path and inbound imports of a file. + + + +str } + description="The new file path to rename the file to." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/ForLoopStatement.mdx b/docs/api-reference/core/ForLoopStatement.mdx new file mode 100644 index 000000000..2bbbd2e61 --- /dev/null +++ b/docs/api-reference/core/ForLoopStatement.mdx @@ -0,0 +1,500 @@ +--- +title: "ForLoopStatement" +sidebarTitle: "ForLoopStatement" +icon: "" +description: "Abstract representation of the for loop. + +Attributes: +code_block: The code block that is executed in each iteration of the loop +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [BlockStatement](/api-reference/core/BlockStatement), [Expression](/api-reference/core/Expression), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### item + +Expression [ ForLoopStatement ] | None } description=" +" /> + +### iterable + +Expression [ ForLoopStatement ] } description=" +" /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ ForLoopStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ForLoopStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + + diff --git a/docs/api-reference/core/Function.mdx b/docs/api-reference/core/Function.mdx new file mode 100644 index 000000000..a8ef1a015 --- /dev/null +++ b/docs/api-reference/core/Function.mdx @@ -0,0 +1,848 @@ +--- +title: "Function" +sidebarTitle: "Function" +icon: "" +description: "Abstract representation of a Function. + +Attributes: +return_type: the return type annotation of the function +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [Callable](/api-reference/core/Callable), [Symbol](/api-reference/core/Symbol), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### comment + +CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the function and its parameters." /> + +### function_signature + +str } description="Returns the signature of the function as a string." /> + +### inferred_return_type + +str | None } description="Gets the inferred type of the function from the language's native language engine / compiler." /> + +### inline_comment + +CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> + +### is_async + +bool } description="Returns True if the function is asynchronous." /> + +### is_constructor + +bool } description="Determines if the current function is a constructor method." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### is_magic + +bool } description="Returns True if function is a magic method." /> + +### is_method + +bool } description="Returns whether the function is a method of a class." /> + +### is_overload + +bool } description="Indicates whether the function is an overloaded function in a multi-function definition." /> + +### is_private + +bool } description="Determines if a function has a private access modifier." /> + +### is_property + +bool } description="Returns whether this function is a property." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_functions + +list[ Function ] } description="Returns a list of nested functions defined within this function's code block." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parameters + +SymbolGroup [ Parameter , Function ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_statements + +list[ ReturnStatement ] } description="Returns a list of all return statements within this function's body." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a comment to the symbol. + + + +str } + description="The comment text to add." + defaultValue="" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_statements +Adds statements to the end of a function body. + + + +str } + description="The lines of code to be added at the end of the function body." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### asyncify +Modifies the function to be asynchronous. + + + +None } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Function ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### prepend_statements +Prepends the provided code to the beginning of the function body. + + + +str } + description="The code to be prepended to the function body." + defaultValue="" +/> + + + +None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename_local_variable +Renames a local variable and all its usages within a function body. + + + +str } + description="The current name of the local variable to be renamed." + defaultValue="" +/> +str } + description="The new name to give to the local variable." + defaultValue="" +/> +bool, optional } + description="If True, matches variable names that contain old_var_name. Defaults to False." + defaultValue="False" +/> + + + +None } description="The method modifies the AST in place."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to set." + defaultValue="" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The text of the inline comment to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_return_type +Sets the return type annotation for the function. + + + +str } + description="The new return type annotation to be set. Use an empty string to remove" + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/FunctionCall.mdx b/docs/api-reference/core/FunctionCall.mdx new file mode 100644 index 000000000..854317887 --- /dev/null +++ b/docs/api-reference/core/FunctionCall.mdx @@ -0,0 +1,613 @@ +--- +title: "FunctionCall" +sidebarTitle: "FunctionCall" +icon: "" +description: "Abstract representation of a function invocation, e.g. in Python: +``` +def f(): +g() # FunctionCall +``` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### args + +Collection[ Argument , FunctionCall ] } description="Returns a list of arguments passed into the function invocation." /> + +### base + +Editable | None } description="Returns the base object of this function call chain." /> + +### call_chain + +list[ FunctionCall ] } description="Returns a list of all function calls in this function call chain, including this call. Does not include calls made after this one." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this function call." /> + +### function_definition + +Callable | None } description="Returns the resolved function definition that is being called." /> + +### function_definitions + +list[ Callable ] } description="Returns a list of callable objects that could potentially be the target of this function" /> + +### is_awaited + +bool } description="Determine if this function call is ultimately awaited in the TypeScript AST." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Retrieves the parent function of the current function call." /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### predecessor + +FunctionCall [ Editable ] | None } description="Returns the previous function call in a function call chain." /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Gets the source code representation of this FunctionCall." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### asyncify +Converts the function call to an async function call by wrapping it with 'await'. + + + +None } description=""/> + + +### convert_args_to_kwargs +Converts positional arguments in a function call to keyword arguments. + + + +int } + description="Number of leading positional arguments to exclude from conversion. Defaults to 0." + defaultValue="0" +/> + + + +None } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ FunctionCall ] } description=""/> + + +### from_usage +Creates a FunctionCall object from an Editable instance that represents a function call. + + + +Editable [ Editable ] } + description="The Editable node that potentially represents a function call." + defaultValue="" +/> +Editable | None } + description="The parent node for the new FunctionCall. If None, uses the parent from the input node." + defaultValue="None" +/> + + + +FunctionCall | None } description="A new FunctionCall object if the input node represents a function call, None otherwise."/> + + +### get_arg_by_index +Returns the Argument with the given index from the function call's argument list. + + + +int } + description="The index of the argument to retrieve." + defaultValue="" +/> + + + +Argument | None } description="The Argument object at the specified index, or None if the index is out of bounds."/> + + +### get_arg_by_parameter_name +Returns an argument by its parameter name. + + + +str } + description="The name of the parameter to search for." + defaultValue="" +/> + + + +Argument | None } description="The matching argument if found, None otherwise."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes a node and optionally its related extended nodes. + + + +bool, optional } + description="Whether to delete associated formatting nodes. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level for the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical removals. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_kwarg +Set a keyword argument in a function call. + + + +str } + description="The name of the parameter/argument to set." + defaultValue="" +/> +str } + description="The value to set the argument to." + defaultValue="" +/> +bool, optional } + description="If True, creates a new keyword argument if it doesn't exist. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="If True, modifies the value of existing argument. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/GenericType.mdx b/docs/api-reference/core/GenericType.mdx new file mode 100644 index 000000000..30439cd58 --- /dev/null +++ b/docs/api-reference/core/GenericType.mdx @@ -0,0 +1,467 @@ +--- +title: "GenericType" +sidebarTitle: "GenericType" +icon: "" +description: "Abstract representation of the generic types of the programming language." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parameters + +Collection[ Type , GenericType ] } description="Retrieves the generic type parameters associated with this type." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ GenericType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/HasBlock.mdx b/docs/api-reference/core/HasBlock.mdx new file mode 100644 index 000000000..8601a23cc --- /dev/null +++ b/docs/api-reference/core/HasBlock.mdx @@ -0,0 +1,469 @@ +--- +title: "HasBlock" +sidebarTitle: "HasBlock" +icon: "" +description: "An interface for any code object that has a block of code, e.g. a function, class, etc." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ HasBlock ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + + diff --git a/docs/api-reference/core/HasName.mdx b/docs/api-reference/core/HasName.mdx new file mode 100644 index 000000000..ba4f9a3f4 --- /dev/null +++ b/docs/api-reference/core/HasName.mdx @@ -0,0 +1,72 @@ +--- +title: "HasName" +sidebarTitle: "HasName" +icon: "" +description: "An interface for any node object that has a name." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + + +## Methods + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/HasValue.mdx b/docs/api-reference/core/HasValue.mdx new file mode 100644 index 000000000..b101beee4 --- /dev/null +++ b/docs/api-reference/core/HasValue.mdx @@ -0,0 +1,43 @@ +--- +title: "HasValue" +sidebarTitle: "HasValue" +icon: "" +description: "An interface for any node object that has a value." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### value + +Expression | None } description="Gets the value node of the object." /> + + +## Methods + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/IfBlockStatement.mdx b/docs/api-reference/core/IfBlockStatement.mdx new file mode 100644 index 000000000..0a23cc15b --- /dev/null +++ b/docs/api-reference/core/IfBlockStatement.mdx @@ -0,0 +1,488 @@ +--- +title: "IfBlockStatement" +sidebarTitle: "IfBlockStatement" +icon: "" +description: "Abstract representation of the if/elif/else if/else statement block. +For example, if there is a code block like: +if condition1: +block1 +elif condition2: +block2 +else: +block3 +This class represents the entire block, including the conditions and nested code blocks. + +Attributes: +condition: The condition expression for the if block. None if the block is an else block. +consequence_block: The code block that is executed if the condition is True. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### alternative_blocks + +list[ IfBlockStatement ] } description="Returns a list of alternative if/elif/else blocks for the current block." /> + +### condition + +Expression [ PyIfBlockStatement ] | None } description="The condition expression for the if block. None if the block is an else block." /> + +### consequence_block + +CodeBlock } description="The code block that is executed if the condition is True." /> + +### else_statement + +IfBlockStatement | None } description="Returns the else block within the if-statement." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the if block statement and its alternative blocks." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_elif_statement + +bool } description="Indicates whether the current block is an elif block." /> + +### is_else_statement + +bool } description="Indicates if the current block is an else block in an if/else statement chain." /> + +### is_if_statement + +bool } description="Returns whether the current block is an if block." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested code blocks within an if/elif/else statement block." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ IfBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### elif_statements +Returns all elif blocks within the if block. + + + +list[ IfBlockStatement ] } description="A list of elif block statements. Empty list if no elif blocks exist."/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ IfBlockStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a conditional block by reducing its condition to a boolean value. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Import.mdx b/docs/api-reference/core/Import.mdx new file mode 100644 index 000000000..5a8bc9e5b --- /dev/null +++ b/docs/api-reference/core/Import.mdx @@ -0,0 +1,651 @@ +--- +title: "Import" +sidebarTitle: "Import" +icon: "" +description: "Represents a single symbol being imported. + +For example, this is one `Import` in Python (and similar applies to Typescript, etc.): +``` +from a.b import c +``` + +This is two separate `Import` in Python: +``` +from a.b import c, d # one import for each `c` and `d` +``` +Attributes: +symbol_name: The name of the symbol being imported. For instance import a as b has a symbol_name of a. +import_statement: the ImportStatement that this import belongs to +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### alias + +Editable | None } description=" +" /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### from_file + +SourceFile | None } description="Returns the SourceFile that an Import is importing from." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### import_specifier + +Editable } description="Returns the specific editable text representation of the import identifier within the" /> + +### import_statement + +ImportStatement } description="the ImportStatement that this import belongs to" /> + +### import_type + +ImportType } description=" +" /> + +### imported_exports + +list[ Exportable ] } description="Returns the enumerated list of symbols imported from a module import." /> + +### imported_symbol + +Symbol | ExternalModule | SourceFile | Import | None } description="Returns the symbol directly being imported, including an indirect import and an External" /> + +### module + +Editable | None } description=" +" /> + +### name + +str | None } description="Returns the name or alias of the symbol being imported." /> + +### namespace + +str | None } description="Returns the namespace prefix that must be used with dot notation to reference the" /> + +### node_type + +Literal[NodeType.IMPORT] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_symbol + +Symbol | ExternalModule | SourceFile | None } description="Returns the symbol, source file, or external module that this import ultimately resolves" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### symbol_name + +Editable | None } description="The name of the symbol being imported. For instance import a as b has a symbol_name of a." /> + +### to_file + +SourceFile } description="SourceFile that this import resides in." /> + +### to_file_id + +NodeId } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Import ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_aliased_import +Returns True if this import is aliased. + + + +bool } description="True if the import has an alias different from its original name, False otherwise."/> + + +### is_module_import +Returns True if this import is importing an entire module/file. + + + +bool } description="True if this import represents a module/file import, False if it represents a symbol import."/> + + +### is_reexport +Returns true if the Import object is also an Export object. + + + +bool } description="True if the import is re-exported, False otherwise."/> + + +### is_symbol_import +Returns True if this import is importing a symbol rather than a module. + + + +bool } description="True if this import is a symbol import, False if it is a module import."/> + + +### is_wildcard_import +Returns True if the import symbol is a wildcard import. + + + +bool } description="True if this is a wildcard import, False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Remove this import from the import statement. + + + +bool, optional } + description="Whether to delete any associated formatting. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of the operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate imports. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Renames the import symbol and updates all its usages throughout the codebase. + + + +str } + description="The new name to give the imported symbol." + defaultValue="" +/> +int, optional } + description="Priority of the rename operation. Defaults to 0." + defaultValue="0" +/> + + + +tuple[NodeId, NodeId] } description="A tuple containing (file_node_id, new_import_node_id)."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_import_module +Sets the module of an import. + + + +str } + description="The new module path to import from." + defaultValue="" +/> + + + +None } description=""/> + + +### set_import_symbol_alias +Sets alias or name of an import at the declaration level. + + + +str } + description="The new name to use for the imported symbol." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/ImportStatement.mdx b/docs/api-reference/core/ImportStatement.mdx new file mode 100644 index 000000000..04a0aeb79 --- /dev/null +++ b/docs/api-reference/core/ImportStatement.mdx @@ -0,0 +1,439 @@ +--- +title: "ImportStatement" +sidebarTitle: "ImportStatement" +icon: "" +description: "Abstract representation of a single import statement that appears in a file. One import +statement can import multiple symbols from a single source. + +Attributes: +imports: A collection of the individual imports this statement represents +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### imports + +Collection[ Import , PyImportStatement ] } description="A collection of the individual imports this statement represents" /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ ImportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ImportStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Importable.mdx b/docs/api-reference/core/Importable.mdx new file mode 100644 index 000000000..2a7cdede5 --- /dev/null +++ b/docs/api-reference/core/Importable.mdx @@ -0,0 +1,470 @@ +--- +title: "Importable" +sidebarTitle: "Importable" +icon: "" +description: "An interface for any node object that can import (or reference) an exportable symbol eg. All nodes that are on the graph must inherit from here + +Class, function, imports, exports, etc. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Importable ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/List.mdx b/docs/api-reference/core/List.mdx new file mode 100644 index 000000000..d48835a07 --- /dev/null +++ b/docs/api-reference/core/List.mdx @@ -0,0 +1,397 @@ +--- +title: "List" +sidebarTitle: "List" +icon: "" +description: "A list object. + +You can use standard operations to operate on this list (IE len, del, append, insert, etc) +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [SymbolGroup](/api-reference/core/SymbolGroup) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Get the source code content of the node." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Edit the source for this Collection instance. + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ List ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### index +Return the index of the first occurrence of value. + + + +int } description=""/> + + +### insert +Adds `value` to the container that this node represents + + + +None } description=""/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes an element from a Collection. + + + +Editable | None } + description="The element to remove from the Collection. If None, delegates to parent class." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/MessageType.mdx b/docs/api-reference/core/MessageType.mdx new file mode 100644 index 000000000..a5322265b --- /dev/null +++ b/docs/api-reference/core/MessageType.mdx @@ -0,0 +1,38 @@ +--- +title: "MessageType" +sidebarTitle: "MessageType" +icon: "" +description: "Destination of the message + +Attributes: +CODEGEN: Rendered in the diff preview +GITHUB: Posted as a comment on the PR +SLACK: Sent over slack +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### CODEGEN + + } description="Rendered in the diff preview" /> + +### GITHUB + + } description="Posted as a comment on the PR" /> + +### SLACK + + } description="Sent over slack" /> + + + diff --git a/docs/api-reference/core/MultiExpression.mdx b/docs/api-reference/core/MultiExpression.mdx new file mode 100644 index 000000000..eda546db7 --- /dev/null +++ b/docs/api-reference/core/MultiExpression.mdx @@ -0,0 +1,418 @@ +--- +title: "MultiExpression" +sidebarTitle: "MultiExpression" +icon: "" +description: "Represents an group of Expressions, such as List, Dict, Binary Expression, String." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### expressions + +list[ Expression ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ MultiExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/MultiLineCollection.mdx b/docs/api-reference/core/MultiLineCollection.mdx new file mode 100644 index 000000000..35b1b2d6e --- /dev/null +++ b/docs/api-reference/core/MultiLineCollection.mdx @@ -0,0 +1,396 @@ +--- +title: "MultiLineCollection" +sidebarTitle: "MultiLineCollection" +icon: "" +description: "A list containing multi-line objects. + +Example: A list of function definitions, class definitions +You can use standard operations to operate on this list (IE len, del, append, insert, etc) +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Get the source code content of the node." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Edit the source for this Collection instance. + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ MultiLineCollection ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### index +Return the index of the first occurrence of value. + + + +int } description=""/> + + +### insert +Adds `value` to the container that this node represents + + + +None } description=""/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes an element from a Collection. + + + +Editable | None } + description="The element to remove from the Collection. If None, delegates to parent class." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/core/Name.mdx b/docs/api-reference/core/Name.mdx new file mode 100644 index 000000000..97e64d936 --- /dev/null +++ b/docs/api-reference/core/Name.mdx @@ -0,0 +1,417 @@ +--- +title: "Name" +sidebarTitle: "Name" +icon: "" +description: "Editable attribute on any given code objects that has a name. + +For example, function, classes, global variable, interfaces, attributes, parameters are all +composed of a name. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Name ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/NamedType.mdx b/docs/api-reference/core/NamedType.mdx new file mode 100644 index 000000000..b6112129d --- /dev/null +++ b/docs/api-reference/core/NamedType.mdx @@ -0,0 +1,463 @@ +--- +title: "NamedType" +sidebarTitle: "NamedType" +icon: "" +description: "An abstract representation of a named type." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ NamedType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/NoneType.mdx b/docs/api-reference/core/NoneType.mdx new file mode 100644 index 000000000..3535d333f --- /dev/null +++ b/docs/api-reference/core/NoneType.mdx @@ -0,0 +1,413 @@ +--- +title: "NoneType" +sidebarTitle: "NoneType" +icon: "" +description: "Represents a None or Null object." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ NoneType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Number.mdx b/docs/api-reference/core/Number.mdx new file mode 100644 index 000000000..431e2647e --- /dev/null +++ b/docs/api-reference/core/Number.mdx @@ -0,0 +1,416 @@ +--- +title: "Number" +sidebarTitle: "Number" +icon: "" +description: "A number value. + +eg. 1, 2.0, 3.14 +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Number ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Pair.mdx b/docs/api-reference/core/Pair.mdx new file mode 100644 index 000000000..703ea6f70 --- /dev/null +++ b/docs/api-reference/core/Pair.mdx @@ -0,0 +1,439 @@ +--- +title: "Pair" +sidebarTitle: "Pair" +icon: "" +description: "An abstract representation of a key, value pair belonging to a `Dict`" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### key + +Expression } description=" +" /> + +### name + +str } description="Returns the source text of the key expression in the pair." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Pair ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Parameter.mdx b/docs/api-reference/core/Parameter.mdx new file mode 100644 index 000000000..c75dd09f3 --- /dev/null +++ b/docs/api-reference/core/Parameter.mdx @@ -0,0 +1,569 @@ +--- +title: "Parameter" +sidebarTitle: "Parameter" +icon: "" +description: "Abstract representation of a parameter in a Function definition." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Typeable](/api-reference/core/Typeable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### default + +str | None } description="Returns the default value of a parameter if one exists." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="Returns the 0-based index of this parameter within its parent function's parameter list." /> + +### is_optional + +bool } description="Returns whether the parameter is optional in its function definition." /> + +### is_typed + +bool } description="Indicates if a node has an explicit type annotation." /> + +### is_variadic + +bool } description="Returns whether the parameter is a variadic parameter." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### type + +Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Parameter ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes the parameter from the function definition and all its call sites. + + + +bool, optional } + description="Whether to delete formatting around the parameter. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level for the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Renames a parameter in a function definition and updates all related references. + + + +str } + description="The new name for the parameter." + defaultValue="" +/> +int, optional } + description="The priority of the edit operation. Defaults to 0." + defaultValue="0" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_type_annotation +Sets the type annotation for this parameter. + + + +str } + description="The type annotation to set for the parameter." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/ParenthesizedExpression.mdx b/docs/api-reference/core/ParenthesizedExpression.mdx new file mode 100644 index 000000000..3b5eb16b6 --- /dev/null +++ b/docs/api-reference/core/ParenthesizedExpression.mdx @@ -0,0 +1,463 @@ +--- +title: "ParenthesizedExpression" +sidebarTitle: "ParenthesizedExpression" +icon: "" +description: "An expression surrounded in a set of parenthesis. + +Example: +```typescript +(5 + 5) +``` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Unwrappable](/api-reference/core/Unwrappable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Retrieves a list of function calls within a parenthesized expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ParenthesizedExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies an expression based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> +Editable } + description="The node to be simplified." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### resolve +Resolves the wrapper expression and returns the first concrete expression. + + + +Expression } description=""/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Placeholder.mdx b/docs/api-reference/core/Placeholder.mdx new file mode 100644 index 000000000..2730e58a8 --- /dev/null +++ b/docs/api-reference/core/Placeholder.mdx @@ -0,0 +1,67 @@ +--- +title: "Placeholder" +sidebarTitle: "Placeholder" +icon: "" +description: "A placeholder for a node that does not exist yet. + +Use bool checks (ie is node) to check if the node exists. You can call edit to replace the +placeholder with a real node and it will automatically insert formatting. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + + +## Methods + +### edit +Replaces the content of a placeholder node with new source code. + + + +str } + description="The new source code to replace the placeholder with." + defaultValue="" +/> +bool, optional } + description="Whether to automatically fix the" + defaultValue="False" +/> +int, optional } + description="Priority value for conflict resolution." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions." + defaultValue="True" +/> + + + +None } description=""/> + + +### remove +Removes this element from its parent container. + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/PlaceholderType.mdx b/docs/api-reference/core/PlaceholderType.mdx new file mode 100644 index 000000000..6fa488a91 --- /dev/null +++ b/docs/api-reference/core/PlaceholderType.mdx @@ -0,0 +1,413 @@ +--- +title: "PlaceholderType" +sidebarTitle: "PlaceholderType" +icon: "" +description: "Represents a type that has not been implemented yet." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PlaceholderType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/RaiseStatement.mdx b/docs/api-reference/core/RaiseStatement.mdx new file mode 100644 index 000000000..39130adcb --- /dev/null +++ b/docs/api-reference/core/RaiseStatement.mdx @@ -0,0 +1,457 @@ +--- +title: "RaiseStatement" +sidebarTitle: "RaiseStatement" +icon: "" +description: "Abstract representation of raise statements, e.g. in Python: + +```python +def f(x): +raise ValueError() +``` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets function calls within a raise statement's value expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ RaiseStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ RaiseStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/ReturnStatement.mdx b/docs/api-reference/core/ReturnStatement.mdx new file mode 100644 index 000000000..3cec84b89 --- /dev/null +++ b/docs/api-reference/core/ReturnStatement.mdx @@ -0,0 +1,460 @@ +--- +title: "ReturnStatement" +sidebarTitle: "ReturnStatement" +icon: "" +description: "Abstract representation of return statements, e.g. in Python: + +```python +def f(x): +if x: +return x**2 # ReturnStatement +else: +return 1 # ReturnStatement +``` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of function calls contained within this return statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ ReturnStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ ReturnStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/SourceFile.mdx b/docs/api-reference/core/SourceFile.mdx new file mode 100644 index 000000000..1a584c2b7 --- /dev/null +++ b/docs/api-reference/core/SourceFile.mdx @@ -0,0 +1,789 @@ +--- +title: "SourceFile" +sidebarTitle: "SourceFile" +icon: "" +description: "Represents a file with source code in the codebase. + +Enables creating, reading, updating, and deleting files and searching through their contents, +etc. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Usable](/api-reference/core/Usable), [HasBlock](/api-reference/core/HasBlock), [File](/api-reference/core/File), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [HasName](/api-reference/core/HasName) + +## Attributes + +### classes + +list[ Class ] } description="Returns all Classes in the file." /> + +### code_block + +CodeBlock } description=" +" /> + +### content + +str } description="Returns the content of the file as a UTF-8 encoded string." /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### directory + +Directory | None } description="Returns the directory that contains this file." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### extension + +str } description="Returns the file extension." /> + +### file + +SourceFile } description="A property that returns the file object for non-source files." /> + +### file_node_id + +NodeId } description=" +" /> + +### file_path + +str } description=" +" /> + +### filepath + +str } description="Retrieves the file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### functions + +list[ Function ] } description="Returns all Functions in the file." /> + +### global_vars + +list[ Assignment ] } description="Returns all GlobalVars in the file." /> + +### import_module_name + +str } description="Returns the module name that this file gets imported as." /> + +### import_statements + +list[ ImportStatement ] } description="Returns all ImportStatements in the file, where each import statement can contain" /> + +### importers + +list[ Import ] } description="Returns all imports that directly imports this file as a module." /> + +### imports + +list[ Import ] } description="List of all Imports in this file." /> + +### inbound_imports + +list[ Import ] } description="Returns all imports that are importing symbols contained in this file." /> + +### is_binary + +bool } description="Indicates whether the file contains binary data." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.FILE] } description=" +" /> + +### owners + +set[str] } description="Returns the CODEOWNERS of the file." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### path + +Path } description=" +" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### start_byte + +int } description="Returns the starting byte position of a file in its content." /> + +### symbols_sorted_topologically + +list[ Symbol ] } description="Returns all Symbols in the file, sorted topologically (parents first). Robust to" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_import_from_import_string +Adds import to the file from a string representation of an import statement. + + + +str } + description="The string representation of the import statement to add." + defaultValue="" +/> + + + +None } description=""/> + + +### add_symbol_from_source +Adds a symbol to a file from a string representation. + + + +str } + description="String representation of the symbol to be added. This should be valid source code for" + defaultValue="" +/> + + + +None } description="The symbol is added directly to the file's content."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_by_byte_range +Finds all editable objects that overlap with the given byte range in the file. + + + +Range } + description="The byte range to search within the file." + defaultValue="" +/> + + + +list[ Editable ] } description="A list of all Editable objects that overlap with the given range."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ SourceFile ] } description=""/> + + +### get_class +Returns a specific Class by full name. Returns None if not found. + + + +str } + description="The full name of the class to search for." + defaultValue="" +/> + + + +Class | None } description="The matching Class object if found, None otherwise."/> + + +### get_function +Returns a specific Function by name. + + + +str } + description="The name of the function to find." + defaultValue="" +/> + + + +Function | None } description="The matching Function object if found, None otherwise."/> + + +### get_global_var +Returns a specific global var by name. Returns None if not found. + + + +str } + description="The name of the global variable to find." + defaultValue="" +/> + + + +Assignment | None } description="The global variable if found, None otherwise."/> + + +### get_import +Returns the import with matching alias. Returns None if not found. + + + +str } + description="The alias name to search for. This can match either the direct import name or the aliased name." + defaultValue="" +/> + + + +Import | None } description="The import statement with the matching alias if found, None otherwise."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_symbol +Gets a symbol by its name from the file. + + + +str } + description="The name of the symbol to find." + defaultValue="" +/> + + + +Symbol | None } description="The found symbol, or None if not found."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### has_import +Returns True if the file has an import with the given alias. + + + +str } + description="The alias to check for in the import statements." + defaultValue="" +/> + + + +bool } description="True if an import with the given alias exists, False otherwise."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes the file from the file system and graph. + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_can_be_added +Checks if the file type supports adding the given symbol. + + + +Symbol } + description="The symbol to check for add compatibility." + defaultValue="" +/> + + + +bool } description="True if the symbol can be added to this file type, False otherwise."/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### symbols +Returns all Symbols in the file, sorted by position in the file. + + + +list[ Symbol | Class | Function | Assignment | TInterface] } description="A list of all top-level symbols in the file, sorted by their position in the file. Symbols can be one of the following types: - Symbol: Base symbol class - TClass: Class definition - TFunction: Function definition - TGlobalVar: Global variable assignment - TInterface: Interface definition"/> + + +### update_filepath +Renames the file and updates all imports to point to the new location. + + + +str } + description="The new filepath to move the file to." + defaultValue="" +/> + + + +None } description=""/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/Span.mdx b/docs/api-reference/core/Span.mdx new file mode 100644 index 000000000..a16e1e749 --- /dev/null +++ b/docs/api-reference/core/Span.mdx @@ -0,0 +1,35 @@ +--- +title: "Span" +sidebarTitle: "Span" +icon: "" +description: "Range within the codebase" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### filepath + +str } description=" +" /> + +### model_config + + } description=" +" /> + +### range + +RangeAdapter } description=" +" /> + + + diff --git a/docs/api-reference/core/Statement.mdx b/docs/api-reference/core/Statement.mdx new file mode 100644 index 000000000..3d97f11c4 --- /dev/null +++ b/docs/api-reference/core/Statement.mdx @@ -0,0 +1,430 @@ +--- +title: "Statement" +sidebarTitle: "Statement" +icon: "" +description: "Represents a single code statement, e.g. a function definition, an assignment, an if/else statement, etc." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ Statement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Statement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/StatementType.mdx b/docs/api-reference/core/StatementType.mdx new file mode 100644 index 000000000..87af8bd93 --- /dev/null +++ b/docs/api-reference/core/StatementType.mdx @@ -0,0 +1,115 @@ +--- +title: "StatementType" +sidebarTitle: "StatementType" +icon: "" +description: "Enum representing the different types of statements that can be parsed." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### ASSIGNMENT + + } description=" +" /> + +### BREAK_STATEMENT + + } description=" +" /> + +### CLASS_ATTRIBUTE + + } description=" +" /> + +### COMMENT + + } description=" +" /> + +### EXPORT_STATEMENT + + } description=" +" /> + +### EXPRESSION_STATEMENT + + } description=" +" /> + +### FOR_LOOP_STATEMENT + + } description=" +" /> + +### IF_BLOCK_STATEMENT + + } description=" +" /> + +### IMPORT_STATEMENT + + } description=" +" /> + +### LABELED_STATEMENT + + } description=" +" /> + +### PASS_STATEMENT + + } description=" +" /> + +### RAISE_STATEMENT + + } description=" +" /> + +### RETURN_STATEMENT + + } description=" +" /> + +### SWITCH_STATEMENT + + } description=" +" /> + +### SYMBOL_STATEMENT + + } description=" +" /> + +### TRY_CATCH_STATEMENT + + } description=" +" /> + +### UNSPECIFIED + + } description=" +" /> + +### WHILE_STATEMENT + + } description=" +" /> + +### WITH_STATEMENT + + } description=" +" /> + + + diff --git a/docs/api-reference/core/String.mdx b/docs/api-reference/core/String.mdx new file mode 100644 index 000000000..75650387e --- /dev/null +++ b/docs/api-reference/core/String.mdx @@ -0,0 +1,435 @@ +--- +title: "String" +sidebarTitle: "String" +icon: "" +description: "GraphSitter representation of String. + +Attributes: +content: The content of the string +expressions: embedded expressions in the string, only applicable for templated or formatted strings +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### content + +str } description="The content of the string" /> + +### content_nodes + +Collection[ Expression [ Editable ], PyString ] } description=" +" /> + +### expressions + +list[ Expression [ Editable ]] } description="embedded expressions in the string, only applicable for templated or formatted strings" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + +### with_quotes + +str } description="Retrieves the string representation with quotation marks." /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ String ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/StubPlaceholder.mdx b/docs/api-reference/core/StubPlaceholder.mdx new file mode 100644 index 000000000..1c03769d2 --- /dev/null +++ b/docs/api-reference/core/StubPlaceholder.mdx @@ -0,0 +1,67 @@ +--- +title: "StubPlaceholder" +sidebarTitle: "StubPlaceholder" +icon: "" +description: "A placeholder for a stub that does not exist. +Can be populated using the `edit` method. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Placeholder](/api-reference/core/Placeholder) + + +## Methods + +### edit +Edits the source code of this placeholder node. + + + +str } + description="The new source code to replace the current source code." + defaultValue="" +/> +bool, optional } + description="Whether to automatically fix the indentation of the new source code. Defaults to False." + defaultValue="False" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate this edit against other pending edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### remove +Removes this element from its parent container. + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/SubscriptExpression.mdx b/docs/api-reference/core/SubscriptExpression.mdx new file mode 100644 index 000000000..bb7ec93f2 --- /dev/null +++ b/docs/api-reference/core/SubscriptExpression.mdx @@ -0,0 +1,427 @@ +--- +title: "SubscriptExpression" +sidebarTitle: "SubscriptExpression" +icon: "" +description: "Indexing onto an object (Aka using brackets on an object) + +Examples: +A[] +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### indices + +list[ Expression ] } description=" +" /> + +### node_type + +NodeType } description=" +" /> + +### object + +Object } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ SubscriptExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/SwitchCase.mdx b/docs/api-reference/core/SwitchCase.mdx new file mode 100644 index 000000000..eecf48839 --- /dev/null +++ b/docs/api-reference/core/SwitchCase.mdx @@ -0,0 +1,496 @@ +--- +title: "SwitchCase" +sidebarTitle: "SwitchCase" +icon: "" +description: "Abstract representation for a switch case. + +Attributes: +code_block: The code block that is executed if the condition is met +condition: The condition which triggers this case +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### condition + +Expression [ PyMatchCase ] | None } description="The condition which triggers this case" /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ SwitchCase ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ SwitchCase ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + + diff --git a/docs/api-reference/core/SwitchStatement.mdx b/docs/api-reference/core/SwitchStatement.mdx new file mode 100644 index 000000000..aa341539e --- /dev/null +++ b/docs/api-reference/core/SwitchStatement.mdx @@ -0,0 +1,443 @@ +--- +title: "SwitchStatement" +sidebarTitle: "SwitchStatement" +icon: "" +description: "Abstract representation of the switch statement. + +Attributes: +value: The value to switch on +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### cases + +list[ SwitchCase ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the switch statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the switch statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ SwitchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression [ PyMatchStatement ] } description="The value to switch on" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ SwitchStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Symbol.mdx b/docs/api-reference/core/Symbol.mdx new file mode 100644 index 000000000..dc0df6486 --- /dev/null +++ b/docs/api-reference/core/Symbol.mdx @@ -0,0 +1,590 @@ +--- +title: "Symbol" +sidebarTitle: "Symbol" +icon: "" +description: "Abstract representation of a Symbol in a Codebase. A Symbol is a top-level entity in a file, +e.g. a Function, Class, GlobalVariable, etc. + +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### comment + +CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### inline_comment + +CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + +SymbolType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a comment to the symbol. + + + +str } + description="The comment text to add." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Symbol ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to set." + defaultValue="" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The text of the inline comment to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/SymbolGroup.mdx b/docs/api-reference/core/SymbolGroup.mdx new file mode 100644 index 000000000..3012ec315 --- /dev/null +++ b/docs/api-reference/core/SymbolGroup.mdx @@ -0,0 +1,417 @@ +--- +title: "SymbolGroup" +sidebarTitle: "SymbolGroup" +icon: "" +description: "These are groups of symbols that form some kind of logical grouping, like a class or module, +that do not follow the traditional tree structure. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Returns the concatenated source code of all symbols in the group." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new text. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool, optional } + description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Prevents duplicate edits at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ SymbolGroup ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes this node and its related extended nodes from the codebase. + + + +bool, optional } + description="Whether to delete related extended nodes like decorators and comments. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level of the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/core/SymbolStatement.mdx b/docs/api-reference/core/SymbolStatement.mdx new file mode 100644 index 000000000..e79d49d2e --- /dev/null +++ b/docs/api-reference/core/SymbolStatement.mdx @@ -0,0 +1,439 @@ +--- +title: "SymbolStatement" +sidebarTitle: "SymbolStatement" +icon: "" +description: "A statement that represents a symbol definition in a codeblock. + +Examples include: +- a function definition, class definition, global variable assignment +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls contained within the symbol associated with this statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ SymbolStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### symbol + +Editable } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ SymbolStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/TernaryExpression.mdx b/docs/api-reference/core/TernaryExpression.mdx new file mode 100644 index 000000000..40d7b9417 --- /dev/null +++ b/docs/api-reference/core/TernaryExpression.mdx @@ -0,0 +1,443 @@ +--- +title: "TernaryExpression" +sidebarTitle: "TernaryExpression" +icon: "" +description: "Any ternary expression in the code where a condition will determine branched execution." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### alternative + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### condition + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### consequence + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TernaryExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a ternary expression based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to. If True, keeps the consequence branch. If False, keeps the alternative branch." + defaultValue="" +/> +Editable | None, optional } + description="The node to be edited. Defaults to None." + defaultValue="None" +/> + + + +None } description="Modifies the ternary expression in place."/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/TryCatchStatement.mdx b/docs/api-reference/core/TryCatchStatement.mdx new file mode 100644 index 000000000..bc9d66844 --- /dev/null +++ b/docs/api-reference/core/TryCatchStatement.mdx @@ -0,0 +1,495 @@ +--- +title: "TryCatchStatement" +sidebarTitle: "TryCatchStatement" +icon: "" +description: "Abstract representation of the try catch statement block. + +Attributes: +code_block: The code block that may trigger an exception +finalizer: The code block executed regardless of if an exception is thrown or not +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [BlockStatement](/api-reference/core/BlockStatement), [Expression](/api-reference/core/Expression), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### finalizer + +BlockStatement | None } description="The code block executed regardless of if an exception is thrown or not" /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TryCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TryCatchStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + + diff --git a/docs/api-reference/core/Tuple.mdx b/docs/api-reference/core/Tuple.mdx new file mode 100644 index 000000000..577ce2a1b --- /dev/null +++ b/docs/api-reference/core/Tuple.mdx @@ -0,0 +1,397 @@ +--- +title: "Tuple" +sidebarTitle: "Tuple" +icon: "" +description: "A tuple object. + +You can use standard operations to operate on this list (IE len, del, append, insert, etc) +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [SymbolGroup](/api-reference/core/SymbolGroup) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Get the source code content of the node." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Edit the source for this Collection instance. + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Tuple ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### index +Return the index of the first occurrence of value. + + + +int } description=""/> + + +### insert +Adds `value` to the container that this node represents + + + +None } description=""/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes an element from a Collection. + + + +Editable | None } + description="The element to remove from the Collection. If None, delegates to parent class." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/TupleType.mdx b/docs/api-reference/core/TupleType.mdx new file mode 100644 index 000000000..93c81201a --- /dev/null +++ b/docs/api-reference/core/TupleType.mdx @@ -0,0 +1,398 @@ +--- +title: "TupleType" +sidebarTitle: "TupleType" +icon: "" +description: "An abstract representation of a tuple type. +For example `[number, number]`. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Get the source code content of the node." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Edit the source for this Collection instance. + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TupleType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### index +Return the index of the first occurrence of value. + + + +int } description=""/> + + +### insert +Adds `value` to the container that this node represents + + + +None } description=""/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes an element from a Collection. + + + +Editable | None } + description="The element to remove from the Collection. If None, delegates to parent class." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/core/Type.mdx b/docs/api-reference/core/Type.mdx new file mode 100644 index 000000000..89dbc378c --- /dev/null +++ b/docs/api-reference/core/Type.mdx @@ -0,0 +1,415 @@ +--- +title: "Type" +sidebarTitle: "Type" +icon: "" +description: "Abstract representation of a type +Used to store the types of variables, parameters, or return values in functions, classes, etc. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Type ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/TypeAlias.mdx b/docs/api-reference/core/TypeAlias.mdx new file mode 100644 index 000000000..c5bea754c --- /dev/null +++ b/docs/api-reference/core/TypeAlias.mdx @@ -0,0 +1,685 @@ +--- +title: "TypeAlias" +sidebarTitle: "TypeAlias" +icon: "" +description: "Abstract representation of a Type object. + +Only applicable for some programming languages like TypeScript. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [HasBlock](/api-reference/core/HasBlock), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### attributes + +list[ Attribute ] } description="List of expressions defined in this Type object." /> + +### code_block + +CodeBlock } description=" +" /> + +### comment + +CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### inline_comment + +CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a comment to the symbol. + + + +str } + description="The comment text to add." + defaultValue="" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TypeAlias ] } description=""/> + + +### get_attribute +Get attribute by name. + + + +Attribute | None } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to set." + defaultValue="" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The text of the inline comment to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/TypePlaceholder.mdx b/docs/api-reference/core/TypePlaceholder.mdx new file mode 100644 index 000000000..137fb344e --- /dev/null +++ b/docs/api-reference/core/TypePlaceholder.mdx @@ -0,0 +1,67 @@ +--- +title: "TypePlaceholder" +sidebarTitle: "TypePlaceholder" +icon: "" +description: "A placeholder for a Type node that does not exist. +Can be populated using the `edit` method. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Placeholder](/api-reference/core/Placeholder) + + +## Methods + +### edit +Edits the type annotation of a placeholder node. + + + +str } + description="The new type annotation text to be inserted." + defaultValue="" +/> +bool, optional } + description="Whether to fix the indentation of the new source." + defaultValue="False" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Whether to remove duplicate edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### remove +Removes this element from its parent container. + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Typeable.mdx b/docs/api-reference/core/Typeable.mdx new file mode 100644 index 000000000..e4ac5a612 --- /dev/null +++ b/docs/api-reference/core/Typeable.mdx @@ -0,0 +1,421 @@ +--- +title: "Typeable" +sidebarTitle: "Typeable" +icon: "" +description: "An interface for any node object that can be typed, eg. function parameters, variables, etc. + +Attributes: +type: The type annotation associated with this node +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### is_typed + +bool } description="Indicates if a node has an explicit type annotation." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### type + +Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Typeable ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/UnaryExpression.mdx b/docs/api-reference/core/UnaryExpression.mdx new file mode 100644 index 000000000..f2e9edad8 --- /dev/null +++ b/docs/api-reference/core/UnaryExpression.mdx @@ -0,0 +1,430 @@ +--- +title: "UnaryExpression" +sidebarTitle: "UnaryExpression" +icon: "" +description: "Unary expression which is a single operation on a single operand. eg. -5, !true. + +Attributes: +argument: The argument of the unary expression +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### argument + +Expression [ UnaryExpression ] } description="The argument of the unary expression" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ UnaryExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a unary expression by reducing it based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/UnionType.mdx b/docs/api-reference/core/UnionType.mdx new file mode 100644 index 000000000..cdcd2b9f2 --- /dev/null +++ b/docs/api-reference/core/UnionType.mdx @@ -0,0 +1,398 @@ +--- +title: "UnionType" +sidebarTitle: "UnionType" +icon: "" +description: "An abstract representation of a union type. +For example `str | None` or `string | number`. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Get the source code content of the node." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Edit the source for this Collection instance. + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ UnionType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### index +Return the index of the first occurrence of value. + + + +int } description=""/> + + +### insert +Adds `value` to the container that this node represents + + + +None } description=""/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes an element from a Collection. + + + +Editable | None } + description="The element to remove from the Collection. If None, delegates to parent class." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/core/Unpack.mdx b/docs/api-reference/core/Unpack.mdx new file mode 100644 index 000000000..c19151b26 --- /dev/null +++ b/docs/api-reference/core/Unpack.mdx @@ -0,0 +1,448 @@ +--- +title: "Unpack" +sidebarTitle: "Unpack" +icon: "" +description: "Unpacking of an iterable. + +Example: +```python +[a, *b] +``` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Unwrappable](/api-reference/core/Unwrappable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Unpack ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### resolve +Resolves the wrapper expression and returns the first concrete expression. + + + +Expression } description=""/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/core/Unwrappable.mdx b/docs/api-reference/core/Unwrappable.mdx new file mode 100644 index 000000000..ae70d4a90 --- /dev/null +++ b/docs/api-reference/core/Unwrappable.mdx @@ -0,0 +1,415 @@ +--- +title: "Unwrappable" +sidebarTitle: "Unwrappable" +icon: "" +description: "An abstract representation of an expression that can be unwrapped. +Expressions that can be unwrapped include binary expressions and ternary expressions. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Unwrappable ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/Usable.mdx b/docs/api-reference/core/Usable.mdx new file mode 100644 index 000000000..7ac9b5bf5 --- /dev/null +++ b/docs/api-reference/core/Usable.mdx @@ -0,0 +1,484 @@ +--- +title: "Usable" +sidebarTitle: "Usable" +icon: "" +description: "An interface for any node object that can be referenced by another node." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Usable ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/core/Usage.mdx b/docs/api-reference/core/Usage.mdx new file mode 100644 index 000000000..d4f6ff47b --- /dev/null +++ b/docs/api-reference/core/Usage.mdx @@ -0,0 +1,48 @@ +--- +title: "Usage" +sidebarTitle: "Usage" +icon: "" +description: "A reference to an exportable object in a file. + +Attributes: +match: The exact match of the usage +usage_symbol: The symbol this object is used in +usage_type: How this symbol was used +kind: Where this symbol was used (IE: in a type parameter or in the body of the class, etc) +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### imported_by + +Import | None } description=" +" /> + +### kind + +UsageKind } description="Where this symbol was used (IE: in a type parameter or in the body of the class, etc)" /> + +### match + +Name | ChainedAttribute | FunctionCall } description="The exact match of the usage" /> + +### usage_symbol + +Import | Symbol | Export | SourceFile } description="The symbol this object is used in" /> + +### usage_type + +UsageType } description="How this symbol was used" /> + + + diff --git a/docs/api-reference/core/UsageKind.mdx b/docs/api-reference/core/UsageKind.mdx new file mode 100644 index 000000000..9956bf4f8 --- /dev/null +++ b/docs/api-reference/core/UsageKind.mdx @@ -0,0 +1,88 @@ +--- +title: "UsageKind" +sidebarTitle: "UsageKind" +icon: "" +description: "SymbolUsageType is an enumeration class that defines different types of symbol usage within Python code. + +Attributes: +SUBCLASS: Used in symbol inheritance. +TYPE_ANNOTATION: Used as a type annotation on a parameter or assignment statement. +BODY: Usage within the body of a function/method. +DECORATOR: Usage within a decorator. +RETURN_TYPE: Used as a return type annotation +TYPE_DEFINITION: Used in a type alias. +EXPORTED_SYMBOL: Used in an export statement. +EXPORTED_WILDCARD: Re-exported by a wildcard export. +GENERIC: Used as a type parameter to another type. +IMPORTED: Imported with an import statement. +DEFAULT_VALUE: Represents a default value in a function/method parameter. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### BODY + + } description="Usage within the body of a function/method." /> + +### DECORATOR + + } description="Usage within a decorator." /> + +### DEFAULT_VALUE + + } description="Represents a default value in a function/method parameter." /> + +### EXPORTED_SYMBOL + + } description="Used in an export statement." /> + +### EXPORTED_WILDCARD + + } description="Re-exported by a wildcard export." /> + +### GENERIC + + } description="Used as a type parameter to another type." /> + +### IMPORTED + + } description="Imported with an import statement." /> + +### IMPORTED_WILDCARD + + } description=" +" /> + +### RETURN_TYPE + + } description="Used as a return type annotation" /> + +### SUBCLASS + + } description="Used in symbol inheritance." /> + +### TYPED_PARAMETER + + } description=" +" /> + +### TYPE_ANNOTATION + + } description=" Used as a type annotation on a parameter or assignment statement." /> + +### TYPE_DEFINITION + + } description="Used in a type alias." /> + + + diff --git a/docs/api-reference/core/UsageType.mdx b/docs/api-reference/core/UsageType.mdx new file mode 100644 index 000000000..fbef98871 --- /dev/null +++ b/docs/api-reference/core/UsageType.mdx @@ -0,0 +1,43 @@ +--- +title: "UsageType" +sidebarTitle: "UsageType" +icon: "" +description: "Describes how a symbol is used elsewhere. Used in conjunction with get_usages + +Attributes: +DIRECT: Direct imports and usages within the same file +CHAINED: Chained references (ie: module.foo) +INDIRECT: Indirect usages with the same name +ALIASED: Aliased indirect usages +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### ALIASED + + } description="Aliased indirect usages" /> + +### CHAINED + + } description="Chained references (ie: module.foo)" /> + +### DIRECT + + } description="Direct imports and usages within the same file" /> + +### INDIRECT + + } description=" Indirect usages with the same name" /> + + + diff --git a/docs/api-reference/core/Value.mdx b/docs/api-reference/core/Value.mdx new file mode 100644 index 000000000..cda9f591f --- /dev/null +++ b/docs/api-reference/core/Value.mdx @@ -0,0 +1,418 @@ +--- +title: "Value" +sidebarTitle: "Value" +icon: "" +description: "Editable attribute on code objects that has a value. + +For example, Functions, Classes, Assignments, Interfaces, Expressions, Arguments and Parameters all have values. + +See also HasValue. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ Value ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/core/WhileStatement.mdx b/docs/api-reference/core/WhileStatement.mdx new file mode 100644 index 000000000..bb203fcbc --- /dev/null +++ b/docs/api-reference/core/WhileStatement.mdx @@ -0,0 +1,491 @@ +--- +title: "WhileStatement" +sidebarTitle: "WhileStatement" +icon: "" +description: "Abstract representation of the while statement block." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description=" +" /> + +### condition + +Expression [ TSWhileStatement ] } description="The condition expression of the while loop." /> + +### decorators + +list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> + +### docstring + +CommentGroup | None } description="Retrieves the docstring of the expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the while statement block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Check if the symbol has decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ WhileStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ WhileStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates the docstring for the current entity. + + + +str } + description="The new docstring content to set." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + + diff --git a/docs/api-reference/core/WithStatement.mdx b/docs/api-reference/core/WithStatement.mdx new file mode 100644 index 000000000..ab72c79e9 --- /dev/null +++ b/docs/api-reference/core/WithStatement.mdx @@ -0,0 +1,525 @@ +--- +title: "WithStatement" +sidebarTitle: "WithStatement" +icon: "" +description: "Pythons implementation of the with statement. + +Examples: +with feature_flag_enabled(...): +# code block + +with open(\"file.txt\") as file: +# code block + +with (context_manager1 as var1, +context_manager2 as var2, +context_manager3 as var3): +# code block + +Attributes: +code_block: (PyCodeBlock) the code block of the with statement +clause: the expression of the with clause +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyHasBlock](/api-reference/python/PyHasBlock), [Statement](/api-reference/core/Statement), [HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### clause + +ExpressionGroup } description="the expression of the with clause" /> + +### code_block + +PyCodeBlock [ WithStatement ] } description="(PyCodeBlock) the code block of the with statement" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls in the code block and within the with clause." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### nested_code_blocks + +list[ PyCodeBlock ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ WithStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ WithStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyAssignment.mdx b/docs/api-reference/python/PyAssignment.mdx new file mode 100644 index 000000000..d3274390b --- /dev/null +++ b/docs/api-reference/python/PyAssignment.mdx @@ -0,0 +1,783 @@ +--- +title: "PyAssignment" +sidebarTitle: "PyAssignment" +icon: "" +description: "An abstract representation of a assignment in python. + +This includes assignments of variables to functions, other variables, class instantiations, etc. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PySymbol](/api-reference/python/PySymbol), [Assignment](/api-reference/core/Assignment), [Symbol](/api-reference/core/Symbol), [HasValue](/api-reference/core/HasValue), [Typeable](/api-reference/core/Typeable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### comment + +PyCommentGroup | None } description="Returns the comment group associated with the symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="Returns the index of the assignment statement in its parent's code block." /> + +### inline_comment + +PyCommentGroup | None } description="A property that retrieves the inline comment group associated with a symbol." /> + +### is_exported + +bool } description="Indicates whether a Python symbol is exported." /> + +### is_local_variable + +bool } description="Determines if an assignment represents a local variable in the current scope." /> + +### is_typed + +bool } description="Indicates if a node has an explicit type annotation." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type + +Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a proper comment format." + defaultValue="True" +/> +bool } + description="Whether to clean and normalize the comment text before adding." + defaultValue="True" +/> +PyCommentType } + description="The style of comment to add (e.g., single-line, multi-line)." + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyAssignment ] } description=""/> + + +### from_named_expression +Creates a MultiExpression from a Python named expression. + + + +TSNode } + description="The TreeSitter node representing the named expression." + defaultValue="" +/> +NodeId } + description="The identifier of the file containing this node." + defaultValue="" +/> +CodebaseGraph } + description="The codebase graph instance." + defaultValue="" +/> +Editable } + description="The parent node that contains this expression." + defaultValue="" +/> + + + +MultiExpression [ PyAssignmentStatement , PyAssignment ] } description="A MultiExpression containing the assignments created from the named expression."/> + + +### get_import_string +Generates an import string for a Python symbol. + + + +str | None } + description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." + defaultValue="None" +/> +str | None } + description="Optional module name to import from. If not provided, uses the symbol's file's module name." + defaultValue="None" +/> +ImportType } + description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type import. Currently unused. Defaults to False." + defaultValue="False" +/> + + + +str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### local_usages +Retrieves all usages of the assigned variable within its code block scope. + + + +list[ Editable [ Statement ]] } description="A sorted list of statement nodes where the variable is used."/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies an assignment expression by reducing it based on a boolean condition and updating all the usages. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment for the Python symbol. + + + +str } + description="The comment text to be added or set." + defaultValue="" +/> +bool, optional } + description="If True, automatically formats the text as a comment." + defaultValue="True" +/> +bool, optional } + description="If True, cleans the format of the comment before" + defaultValue="True" +/> +PyCommentType , optional } + description="Type of comment to add (e.g., single line," + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description="This method modifies the symbol's comment in place."/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to add." + defaultValue="" +/> +bool, optional } + description="If True, formats the text into a proper inline" + defaultValue="True" +/> +bool, optional } + description="If True, cleans the comment text before insertion" + defaultValue="True" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_type_annotation +Adds or updates a type annotation for the current assignment. + + + +str } + description="The type annotation to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of an assignment expression. + + + +str } + description="The source code string representing the new value to be assigned." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyAssignmentStatement.mdx b/docs/api-reference/python/PyAssignmentStatement.mdx new file mode 100644 index 000000000..531751c40 --- /dev/null +++ b/docs/api-reference/python/PyAssignmentStatement.mdx @@ -0,0 +1,529 @@ +--- +title: "PyAssignmentStatement" +sidebarTitle: "PyAssignmentStatement" +icon: "" +description: "A class that represents a Python assignment statement in a codebase, such as `x = 1` or `a, b = 1, 2`. + +This includes potentially multiple Assignments via `statement.assignments`, which represent each assignment of a value to a variable within this statement. + +For example, assigning to a list, or assigning multiple values to multiple variables in a single statement. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[AssignmentStatement](/api-reference/core/AssignmentStatement), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### assignment_types + + } description=" +" /> + +### assignments + +list[ Assignment ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### left + +Expression [ Assignment ] } description=" +" /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyAssignmentStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ Assignment ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyAssignmentStatement ] } description=""/> + + +### from_assignment +Creates a PyAssignmentStatement instance from a TreeSitter assignment node. + + + +TSNode } + description="The TreeSitter node representing the entire statement." + defaultValue="" +/> +NodeId } + description="The ID of the file containing this node." + defaultValue="" +/> +CodebaseGraph } + description="The codebase graph instance." + defaultValue="" +/> +PyHasBlock } + description="The parent block containing this statement." + defaultValue="" +/> +PyCodeBlock } + description="The code block containing this statement." + defaultValue="" +/> +int } + description="The position of this statement within its code block." + defaultValue="" +/> +TSNode } + description="The TreeSitter node representing the assignment operation." + defaultValue="" +/> + + + +PyAssignmentStatement } description="A new assignment statement instance, either PyAttribute or PyAssignmentStatement."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyAttribute.mdx b/docs/api-reference/python/PyAttribute.mdx new file mode 100644 index 000000000..86bd6044a --- /dev/null +++ b/docs/api-reference/python/PyAttribute.mdx @@ -0,0 +1,616 @@ +--- +title: "PyAttribute" +sidebarTitle: "PyAttribute" +icon: "" +description: "Python implementation of Attribute detached symbol." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyAssignmentStatement](/api-reference/python/PyAssignmentStatement), [Attribute](/api-reference/core/Attribute), [AssignmentStatement](/api-reference/core/AssignmentStatement), [Usable](/api-reference/core/Usable), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### assignment + +Assignment } description=" +" /> + +### assignment_types + + } description=" +" /> + +### assignments + +list[ Assignment ] } description=" +" /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_optional + +bool } description="Check if the attribute is optional." /> + +### is_private + +bool } description="Determines if this attribute is private by checking if its name starts with an underscore." /> + +### left + +Expression [ Assignment ] } description=" +" /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyAttribute ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ Assignment ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyAttribute ] } description=""/> + + +### from_assignment +Creates a PyAssignmentStatement instance from a TreeSitter assignment node. + + + +TSNode } + description="The TreeSitter node representing the entire statement." + defaultValue="" +/> +NodeId } + description="The ID of the file containing this node." + defaultValue="" +/> +CodebaseGraph } + description="The codebase graph instance." + defaultValue="" +/> +PyHasBlock } + description="The parent block containing this statement." + defaultValue="" +/> +PyCodeBlock } + description="The code block containing this statement." + defaultValue="" +/> +int } + description="The position of this statement within its code block." + defaultValue="" +/> +TSNode } + description="The TreeSitter node representing the assignment operation." + defaultValue="" +/> + + + +PyAssignmentStatement } description="A new assignment statement instance, either PyAttribute or PyAssignmentStatement."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### local_usages +Returns all instances where this attribute is used within its parent code block. + + + +list[ Editable [ PyAttribute ]] } description="A sorted list of unique attribute references. Each reference is an Editable object representing a usage of this attribute."/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of a node's assignment. + + + +str } + description="The new value to set for the assignment." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyBlockStatement.mdx b/docs/api-reference/python/PyBlockStatement.mdx new file mode 100644 index 000000000..1d655b32c --- /dev/null +++ b/docs/api-reference/python/PyBlockStatement.mdx @@ -0,0 +1,505 @@ +--- +title: "PyBlockStatement" +sidebarTitle: "PyBlockStatement" +icon: "" +description: "Statement which contains a block." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyBlockStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyBreakStatement.mdx b/docs/api-reference/python/PyBreakStatement.mdx new file mode 100644 index 000000000..27cdade2e --- /dev/null +++ b/docs/api-reference/python/PyBreakStatement.mdx @@ -0,0 +1,430 @@ +--- +title: "PyBreakStatement" +sidebarTitle: "PyBreakStatement" +icon: "" +description: "An abstract representation of a python break statement." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyBreakStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyBreakStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyCatchStatement.mdx b/docs/api-reference/python/PyCatchStatement.mdx new file mode 100644 index 000000000..1bdff7d93 --- /dev/null +++ b/docs/api-reference/python/PyCatchStatement.mdx @@ -0,0 +1,514 @@ +--- +title: "PyCatchStatement" +sidebarTitle: "PyCatchStatement" +icon: "" +description: "Python catch clause. + +Attributes: +code_block: The code block that may trigger an exception +condition: The condition which triggers this clause +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyBlockStatement](/api-reference/python/PyBlockStatement), [CatchStatement](/api-reference/core/CatchStatement), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### condition + +Expression [ PyCatchStatement ] | None } description="The condition which triggers this clause" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyCatchStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyChainedAttribute.mdx b/docs/api-reference/python/PyChainedAttribute.mdx new file mode 100644 index 000000000..227353224 --- /dev/null +++ b/docs/api-reference/python/PyChainedAttribute.mdx @@ -0,0 +1,427 @@ +--- +title: "PyChainedAttribute" +sidebarTitle: "PyChainedAttribute" +icon: "" +description: "Abstract representation of a python chained attribute. +This includes methods of python classes and module functions. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[ChainedAttribute](/api-reference/core/ChainedAttribute), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### attribute + +Attribute } description="Gets the attribute being accessed in a chained attribute expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str } description="Returns the full name of the attribute, including the object expression." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### object + +Object } description="Returns the object that contains the attribute being looked up." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyChainedAttribute ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyClass.mdx b/docs/api-reference/python/PyClass.mdx new file mode 100644 index 000000000..72846998b --- /dev/null +++ b/docs/api-reference/python/PyClass.mdx @@ -0,0 +1,1077 @@ +--- +title: "PyClass" +sidebarTitle: "PyClass" +icon: "" +description: "Extends Class for Python codebases" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyHasBlock](/api-reference/python/PyHasBlock), [PySymbol](/api-reference/python/PySymbol), [Class](/api-reference/core/Class), [HasBlock](/api-reference/core/HasBlock), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### comment + +PyCommentGroup | None } description="Retrieves the comment group associated with a Python symbol." /> + +### constructor + +Function | None } description="Returns the constructor method for this class." /> + +### constructor_keyword + + } description=" +" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### inline_comment + +PyCommentGroup | None } description="Returns the inline comment group associated with this symbol." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### is_exported + +bool } description="Indicates whether a Python symbol is exported." /> + +### is_subclass + +bool } description="Indicates whether the current class is a subclass of another class." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_classes + +list[ PyClass ] } description="Retrieves the nested classes defined within this class." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parameters + +SymbolGroup [ Parameter , PyClass ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_class_names + +list[ Name | ChainedAttribute ] } description="Returns a list of the parent class names that this class inherits from." /> + +### parent_classes + +Parents[ Type , PyClass ] | None } description=" +" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_attribute +Adds an attribute to a class from another class. + + + +Attribute } + description="The attribute to add to the class." + defaultValue="" +/> +bool, optional } + description="Whether to include the attribute's dependencies. If True, adds any necessary imports to the class's file. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### add_attribute_from_source +Adds an attribute to a class from raw source code, placing it in a specific location + + + +str } + description="The source code of the attribute to be added." + defaultValue="" +/> + + + +None } description=""/> + + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a proper comment format." + defaultValue="True" +/> +bool } + description="Whether to clean and normalize the comment text before adding." + defaultValue="True" +/> +PyCommentType } + description="The style of comment to add (e.g., single-line, multi-line)." + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_source +Adds source code to the class definition. + + + +str } + description="The source code to be added to the class definition. If the source doesn't" + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### attributes +Retrieves all attributes from this Class including those from its superclasses up to a + + + +int | None } + description="The maximum depth of superclass traversal. None means no limit, 0 means only this class." + defaultValue="0" +/> +bool } + description="Whether to include private attributes. Defaults to True." + defaultValue="True" +/> + + + +list[ Attribute ] } description="A list of unique attributes from this class and its superclasses. If an attribute is defined in multiple classes, the first definition encountered is used."/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyClass ] } description=""/> + + +### get_attribute +Returns a specific attribute by name. + + + +str } + description="The name of the attribute to search for." + defaultValue="" +/> + + + +Attribute | None } description="The matching attribute if found, None otherwise. If multiple attributes with the same name exist in the inheritance hierarchy, returns the first one found."/> + + +### get_import_string +Generates an import string for a Python symbol. + + + +str | None } + description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." + defaultValue="None" +/> +str | None } + description="Optional module name to import from. If not provided, uses the symbol's file's module name." + defaultValue="None" +/> +ImportType } + description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type import. Currently unused. Defaults to False." + defaultValue="False" +/> + + + +str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> + + +### get_method +Returns a specific method by name from the class or any of its superclasses. + + + +str } + description="The name of the method to find." + defaultValue="" +/> + + + +Function | None } description="The method if found, None otherwise."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_nested_class +Returns a nested class by name from the current class. + + + +str } + description="The name of the nested class to find." + defaultValue="" +/> + + + +PyClass | None } description="The nested class if found, None otherwise."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_parent_class +Returns the parent class node with the specified name. + + + +str } + description="The name of the parent class to find." + defaultValue="" +/> + + + +Editable | None } description="The matching parent class node, or None if no match is found."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_subclass_of +Checks if the class inherits from a specified parent class. + + + +str | Class } + description="The parent class to check for. Can be specified either as a class name string or Class object." + defaultValue="" +/> +int | None } + description="Maximum inheritance depth to search. None means no limit." + defaultValue="None" +/> + + + +bool } description="True if this class inherits from the parent class, False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### methods +Retrieves all methods that exist on this Class, including methods from superclasses, with + + + +int | None, optional } + description="Include parent classes up to max_depth. None means no limit, 0 means only current class. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to include private methods. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include magic methods. Defaults to False." + defaultValue="True" +/> + + + +list[ Function ] | MultiLineCollection [ Function , PyClass ] } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment for the Python symbol. + + + +str } + description="The comment text to be added or set." + defaultValue="" +/> +bool, optional } + description="If True, automatically formats the text as a comment." + defaultValue="True" +/> +bool, optional } + description="If True, cleans the format of the comment before" + defaultValue="True" +/> +PyCommentType , optional } + description="Type of comment to add (e.g., single line," + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description="This method modifies the symbol's comment in place."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to add." + defaultValue="" +/> +bool, optional } + description="If True, formats the text into a proper inline" + defaultValue="True" +/> +bool, optional } + description="If True, cleans the comment text before insertion" + defaultValue="True" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### subclasses +Returns all classes which subclass this class. + + + +int | None, optional } + description="Maximum inheritance depth to search. If None, searches all depths. Defaults to None." + defaultValue="None" +/> + + + +list[ Class ] } description="A list of Class objects that inherit from this class."/> + + +### superclasses +Returns a list of all classes that this class extends, up to max_depth. + + + +int | None } + description="The maximum depth to traverse up the inheritance tree. If None, traverses the entire tree." + defaultValue="None" +/> + + + +list[ Class | ExternalModule | Interface] } description="A list of all superclass symbols in MRO order, up to max_depth. Returns an empty list if the class has no parent classes."/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyCodeBlock.mdx b/docs/api-reference/python/PyCodeBlock.mdx new file mode 100644 index 000000000..28784df61 --- /dev/null +++ b/docs/api-reference/python/PyCodeBlock.mdx @@ -0,0 +1,606 @@ +--- +title: "PyCodeBlock" +sidebarTitle: "PyCodeBlock" +icon: "" +description: "Extends CodeBlock for Python codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[CodeBlock](/api-reference/core/CodeBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### assignment_statements + +list[ AssignmentStatement [ PyCodeBlock , Assignment ]] } description="Returns list of top level assignment statements in the code block." /> + +### assignments + +list[ Assignment [ Editable , PyCodeBlock ]] } description="Returns all assignments in the code block across all nesting levels." /> + +### attributes + +list[ Attribute [ Editable , PyCodeBlock ]] } description="Returns a list of top level class attribute statements in the code block." /> + +### comments + +list[ Comment [ Editable , PyCodeBlock ]] } description="Gets list of top level comments in the code block." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls in the code block." /> + +### if_blocks + +list[ IfBlockStatement [ PyCodeBlock ]] } description="Returns a list of top level if statements in the code block." /> + +### level + +int } description=" +" /> + +### local_var_assignments + +list[ Assignment [ Editable , PyCodeBlock ]] } description="Returns all local variable assignment in the code block, for all nest levels." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_block + +CodeBlock | None } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_statements + +list[ ReturnStatement [ PyCodeBlock ]] } description="Gets all return statements at the top level of the code block." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statements + +MultiLineCollection [ Statement , PyCodeBlock ] } description="Gets a view of the top-level statements in the code block." /> + +### symbol_statements + +list[ SymbolStatement ] } description="Returns list of top level symbol statements in the code block." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + +### with_statements + +list[ WithStatement ] } description="Returns a list of all 'with' statements within the code block." /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyCodeBlock ] } description=""/> + + +### get_assignments +Returns a list of assignments with the specified variable name. + + + +str } + description="The name of the variable to find assignments for." + defaultValue="" +/> + + + +list[ Assignment [ Editable , PyCodeBlock ]] } description="A list of Assignment objects that match the variable name."/> + + +### get_attributes +Returns attributes from the code block, with the option to include or exclude private + + + +bool } + description="Whether to include private attributes in the returned list. If True, returns both private and" + defaultValue="" +/> + + + +list[ Attribute [ Editable , PyCodeBlock ]] } description="A list of attribute statements matching the privacy criteria."/> + + +### get_comment +Gets the first comment statement containing a specific text string. + + + +str } + description="The text string to search for within comment statements." + defaultValue="" +/> + + + +Comment [ Editable , PyCodeBlock ] | None } description="The first comment statement containing the search text, or None if no matching comment is found."/> + + +### get_local_var_assignment +Returns the first code statement that assigns a local variable with the specified name. + + + +str } + description="The name of the local variable to search for." + defaultValue="" +/> + + + +Assignment [ Editable , PyCodeBlock ] | None } description="The first matching local variable assignment, or None if no match is found."/> + + +### get_local_var_assignments +Returns all instances of local variable assignments that match the specified variable + + + +str } + description="The name of the local variable to search for." + defaultValue="" +/> +bool, optional } + description="If True, matches variables whose names contain var_name." + defaultValue="False" +/> + + + +list[ Assignment [ Editable , PyCodeBlock ]] } description="List of Assignment objects representing local variable assignments that match the specified name criteria."/> + + +### get_statements +Returns all statements of a given type up to the specified block level. + + + +StatementType | None } + description="The type of statements to return. If None, returns all statement types." + defaultValue="None" +/> +int | None } + description="The maximum block depth level to search. If None, searches all levels." + defaultValue="None" +/> + + + +list[ Statement [ PyCodeBlock ]] } description=""/> + + +### get_variable_usages +Returns all instances of variable usages in a code block. + + + +str } + description="The name of the variable to search for." + defaultValue="" +/> +bool } + description="When True, matches on variable names that contain var_name. When False (default), only matches exact variable names." + defaultValue="False" +/> + + + +list[ Editable [ PyCodeBlock ]] } description="A sorted list of variable usage instances as Editable objects."/> + + +### get_with_statements +Gets with statements at a specific block level. + + + +int } + description="The block level to filter by. 0 represents the top level." + defaultValue="" +/> + + + +list[ WithStatement ] } description="A list of WithStatement objects at the specified block level."/> + + +### indent +Adjusts the indentation level of the entire code block. + + + +int } + description="The number of indentation levels to adjust. Positive values indent right, negative values indent left." + defaultValue="" +/> + + + +None } description=""/> + + +### insert_before +Inserts new source code at the top of the code block. + + + +str } + description="The source code to insert at the top of the code block." + defaultValue="" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename_variable_usages +Renames all instances of variable usages in the code block. + + + +str } + description="The current name of the variable to rename." + defaultValue="" +/> +str } + description="The new name to give the variable." + defaultValue="" +/> +bool } + description="When True, matches variables containing old_var_name. When False, only exact matches. Defaults to False." + defaultValue="False" +/> + + + +None } description="This method mutates the code block in place."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### unwrap +Extracts a code block from its parent wrapper container by removing the wrapping + + + +None } description=""/> + + +### wrap +Wraps a code block with a statement and indents it. + + + +str } + description="The source code to insert before the block." + defaultValue="" +/> +str } + description="The source code to insert after the block. Defaults to an empty string." + defaultValue="""" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyComment.mdx b/docs/api-reference/python/PyComment.mdx new file mode 100644 index 000000000..140e27fc9 --- /dev/null +++ b/docs/api-reference/python/PyComment.mdx @@ -0,0 +1,511 @@ +--- +title: "PyComment" +sidebarTitle: "PyComment" +icon: "" +description: "Abstract representation of python comments" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Comment](/api-reference/core/Comment), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### comment_type + +PyCommentType } description="Determines the type of Python comment based on its syntax." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### google_style + +bool } description="Determines if a Python docstring follows Google style formatting." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns a list of nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyComment ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### text + +str } description="Returns the text content of the comment." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### clean_comment +Cleans a comment block by removing comment symbols, leading/trailing whitespace, and standardizing indentation. + + + +str } + description="The raw comment block to be cleaned. Can be a single-line comment or multi-line docstring." + defaultValue="" +/> + + + +str } description="The cleaned comment text with comment symbols and excess whitespace removed."/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### edit_text +Replace the text of a comment with new text. + + + +str } + description="The new text content to replace the existing comment text." + defaultValue="" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyComment ] } description=""/> + + +### generate_comment +Converts text content into a Python comment block. + + + +str } + description="The text content to be converted into a comment." + defaultValue="" +/> +PyCommentType } + description="The type of comment to generate (SINGLE_LINE, MULTI_LINE_QUOTE, or MULTI_LINE_DOUBLE_QUOTE)." + defaultValue="" +/> +bool, optional } + description="When True, forces multi-line format even for single-line content. Defaults to False." + defaultValue="" +/> +bool, optional } + description="When True, formats multi-line comments in Google style without newline after opening quotes. Defaults to True." + defaultValue="" +/> + + + +str } description="The formatted comment block with appropriate comment syntax."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyCommentGroup.mdx b/docs/api-reference/python/PyCommentGroup.mdx new file mode 100644 index 000000000..9cca760b6 --- /dev/null +++ b/docs/api-reference/python/PyCommentGroup.mdx @@ -0,0 +1,462 @@ +--- +title: "PyCommentGroup" +sidebarTitle: "PyCommentGroup" +icon: "" +description: "A group of related symbols that represent a comment or docstring in Python + +For example: +``` +# Comment 1 +# Comment 2 +# Comment 3 +``` +would be 3 individual comments (accessible via `symbols`), but together they form a `CommentGroup` (accessible via `self`). +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[CommentGroup](/api-reference/core/CommentGroup), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Returns the concatenated source code of all symbols in the group." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### text + +str } description="Return the text content of all comments in the comment block." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new text. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool, optional } + description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Prevents duplicate edits at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### edit_text +Replace the text content of a comment group with new text. + + + +str } + description="The new text content to replace the existing comment text." + defaultValue="" +/> + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyCommentGroup ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes this node and its related extended nodes from the codebase. + + + +bool, optional } + description="Whether to delete related extended nodes like decorators and comments. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level of the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + +### to_google_docstring +Convert a comment group into a Google-style docstring. + + + +PyFunction } + description="The Python function whose signature will be used to extract parameter and return type information." + defaultValue="" +/> + + + +str } description="A formatted Google-style docstring string that includes the function's description, parameters, and return value information."/> + + + diff --git a/docs/api-reference/python/PyCommentType.mdx b/docs/api-reference/python/PyCommentType.mdx new file mode 100644 index 000000000..09d982467 --- /dev/null +++ b/docs/api-reference/python/PyCommentType.mdx @@ -0,0 +1,40 @@ +--- +title: "PyCommentType" +sidebarTitle: "PyCommentType" +icon: "" +description: "Enum representing different types of comments." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### MULTI_LINE_DOUBLE_QUOTE + + } description=" +" /> + +### MULTI_LINE_QUOTE + + } description=" +" /> + +### SINGLE_LINE + + } description=" +" /> + +### UNKNOWN + + } description=" +" /> + + + diff --git a/docs/api-reference/python/PyConditionalExpression.mdx b/docs/api-reference/python/PyConditionalExpression.mdx new file mode 100644 index 000000000..7973a211a --- /dev/null +++ b/docs/api-reference/python/PyConditionalExpression.mdx @@ -0,0 +1,443 @@ +--- +title: "PyConditionalExpression" +sidebarTitle: "PyConditionalExpression" +icon: "" +description: "Conditional Expressions (A if condition else B)" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TernaryExpression](/api-reference/core/TernaryExpression), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### alternative + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### condition + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### consequence + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyConditionalExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a ternary expression based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to. If True, keeps the consequence branch. If False, keeps the alternative branch." + defaultValue="" +/> +Editable | None, optional } + description="The node to be edited. Defaults to None." + defaultValue="None" +/> + + + +None } description="Modifies the ternary expression in place."/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyDecorator.mdx b/docs/api-reference/python/PyDecorator.mdx new file mode 100644 index 000000000..f5fd7a7c0 --- /dev/null +++ b/docs/api-reference/python/PyDecorator.mdx @@ -0,0 +1,467 @@ +--- +title: "PyDecorator" +sidebarTitle: "PyDecorator" +icon: "" +description: "Extends Decorators for Python codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Decorator](/api-reference/core/Decorator), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### call + +FunctionCall | None } description="Gets the function call node from the decorator if the decorator is a call." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyDecorator ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyFile.mdx b/docs/api-reference/python/PyFile.mdx new file mode 100644 index 000000000..bffafca49 --- /dev/null +++ b/docs/api-reference/python/PyFile.mdx @@ -0,0 +1,851 @@ +--- +title: "PyFile" +sidebarTitle: "PyFile" +icon: "" +description: "SourceFile representation for Python codebase" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyHasBlock](/api-reference/python/PyHasBlock), [SourceFile](/api-reference/core/SourceFile), [HasBlock](/api-reference/core/HasBlock), [Usable](/api-reference/core/Usable), [File](/api-reference/core/File), [Expression](/api-reference/core/Expression), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [HasName](/api-reference/core/HasName) + +## Attributes + +### classes + +list[ Class ] } description="Returns all Classes in the file." /> + +### code_block + +CodeBlock } description=" +" /> + +### content + +str } description="Returns the content of the file as a UTF-8 encoded string." /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### directory + +Directory | None } description="Returns the directory that contains this file." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### extension + +str } description="Returns the file extension." /> + +### file + +PyFile } description="A property that returns the file object for non-source files." /> + +### file_node_id + +NodeId } description=" +" /> + +### file_path + +str } description=" +" /> + +### filepath + +str } description="Retrieves the file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### functions + +list[ Function ] } description="Returns all Functions in the file." /> + +### global_vars + +list[ Assignment ] } description="Returns all GlobalVars in the file." /> + +### import_module_name + +str } description="Returns the module name that this file gets imported as." /> + +### import_statements + +list[ ImportStatement ] } description="Returns all ImportStatements in the file, where each import statement can contain" /> + +### importers + +list[ Import ] } description="Returns all imports that directly imports this file as a module." /> + +### imports + +list[ Import ] } description="List of all Imports in this file." /> + +### inbound_imports + +list[ Import ] } description="Returns all imports that are importing symbols contained in this file." /> + +### is_binary + +bool } description="Indicates whether the file contains binary data." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.FILE] } description=" +" /> + +### owners + +set[str] } description="Returns the CODEOWNERS of the file." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### path + +Path } description=" +" /> + +### programming_language + + } description=" +" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### start_byte + +int } description="Returns the starting byte position of a file in its content." /> + +### symbols_sorted_topologically + +list[ Symbol ] } description="Returns all Symbols in the file, sorted topologically (parents first). Robust to" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_import_from_import_string +Adds an import statement to the file from a string representation. + + + +str } + description="The string representation of the import statement to add (e.g., 'from module import symbol')." + defaultValue="" +/> + + + +None } description="This function modifies the file in place."/> + + +### add_symbol_from_source +Adds a symbol to a file from a string representation. + + + +str } + description="String representation of the symbol to be added. This should be valid source code for" + defaultValue="" +/> + + + +None } description="The symbol is added directly to the file's content."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_by_byte_range +Finds all editable objects that overlap with the given byte range in the file. + + + +Range } + description="The byte range to search within the file." + defaultValue="" +/> + + + +list[ Editable ] } description="A list of all Editable objects that overlap with the given range."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyFile ] } description=""/> + + +### get_class +Returns a specific Class by full name. Returns None if not found. + + + +str } + description="The full name of the class to search for." + defaultValue="" +/> + + + +Class | None } description="The matching Class object if found, None otherwise."/> + + +### get_extensions +Returns the file extensions associated with Python files. + + + +list[str] } description="A list containing '.py' as the only Python file extension."/> + + +### get_function +Returns a specific Function by name. + + + +str } + description="The name of the function to find." + defaultValue="" +/> + + + +Function | None } description="The matching Function object if found, None otherwise."/> + + +### get_global_var +Returns a specific global var by name. Returns None if not found. + + + +str } + description="The name of the global variable to find." + defaultValue="" +/> + + + +Assignment | None } description="The global variable if found, None otherwise."/> + + +### get_import +Returns the import with matching alias. Returns None if not found. + + + +str } + description="The alias name to search for. This can match either the direct import name or the aliased name." + defaultValue="" +/> + + + +Import | None } description="The import statement with the matching alias if found, None otherwise."/> + + +### get_import_string +Generates an import string for a symbol. + + + +str | None, optional } + description="Alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="Module path to import from. If None, uses module name from source. Defaults to None." + defaultValue="None" +/> +ImportType, optional } + description="Type of import statement to generate. Defaults to ImportType.UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type import. Currently unused. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import string in the form of 'from {module} import {symbol}' with optional alias or wildcard syntax."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_symbol +Gets a symbol by its name from the file. + + + +str } + description="The name of the symbol to find." + defaultValue="" +/> + + + +Symbol | None } description="The found symbol, or None if not found."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### has_import +Returns True if the file has an import with the given alias. + + + +str } + description="The alias to check for in the import statements." + defaultValue="" +/> + + + +bool } description="True if an import with the given alias exists, False otherwise."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes the file from the file system and graph. + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_can_be_added +Checks if a Python symbol can be added to this Python source file. + + + +PySymbol } + description="The Python symbol to check for compatibility with this file." + defaultValue="" +/> + + + +bool } description="Always returns True as Python files can contain any Python symbol type."/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### symbols +Returns all Symbols in the file, sorted by position in the file. + + + +list[ Symbol | Class | Function | Assignment | TInterface] } description="A list of all top-level symbols in the file, sorted by their position in the file. Symbols can be one of the following types: - Symbol: Base symbol class - TClass: Class definition - TFunction: Function definition - TGlobalVar: Global variable assignment - TInterface: Interface definition"/> + + +### update_filepath +Renames the file and updates all imports to point to the new location. + + + +str } + description="The new filepath to move the file to." + defaultValue="" +/> + + + +None } description=""/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyForLoopStatement.mdx b/docs/api-reference/python/PyForLoopStatement.mdx new file mode 100644 index 000000000..a746070ce --- /dev/null +++ b/docs/api-reference/python/PyForLoopStatement.mdx @@ -0,0 +1,518 @@ +--- +title: "PyForLoopStatement" +sidebarTitle: "PyForLoopStatement" +icon: "" +description: "Abstract representation of the for loop in Python + +Attributes: +item: An item in the iterable object +iterable: The iterable that is being iterated over +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyBlockStatement](/api-reference/python/PyBlockStatement), [ForLoopStatement](/api-reference/core/ForLoopStatement), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within this for loop statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### item + +Expression [ PyForLoopStatement ] } description="An item in the iterable object" /> + +### iterable + +Expression [ PyForLoopStatement ] } description="The iterable that is being iterated over" /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyForLoopStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyForLoopStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyFunction.mdx b/docs/api-reference/python/PyFunction.mdx new file mode 100644 index 000000000..64231f272 --- /dev/null +++ b/docs/api-reference/python/PyFunction.mdx @@ -0,0 +1,961 @@ +--- +title: "PyFunction" +sidebarTitle: "PyFunction" +icon: "" +description: "Extends Function for Python codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyHasBlock](/api-reference/python/PyHasBlock), [PySymbol](/api-reference/python/PySymbol), [Function](/api-reference/core/Function), [HasBlock](/api-reference/core/HasBlock), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### body + +str } description="Returns the body of the function as a string." /> + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### comment + +PyCommentGroup | None } description="Retrieves the comment group associated with a Python symbol." /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the function and its parameters." /> + +### function_signature + +str } description="Returns the function signature as a string." /> + +### inferred_return_type + +str | None } description="Gets the inferred type of the function from the language's native language engine / compiler." /> + +### inline_comment + +PyCommentGroup | None } description="Returns the inline comment group associated with this symbol." /> + +### is_async + +bool } description="Returns True if the function is asynchronous." /> + +### is_class_method + +bool } description="Indicates whether the current function is decorated with @classmethod." /> + +### is_constructor + +bool } description="Determines if the current function is a constructor method." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### is_exported + +bool } description="Indicates whether a Python symbol is exported." /> + +### is_magic + +bool } description="Determines if a method is a magic method." /> + +### is_method + +bool } description="Returns whether the function is a method of a class." /> + +### is_overload + +bool } description="Determines whether a function is decorated with an overload decorator." /> + +### is_private + +bool } description="Determines if a method is a private method." /> + +### is_property + +bool } description="Determines if the function is a property." /> + +### is_static_method + +bool } description="Determines if the function is a static method." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_functions + +list[ Function ] } description="Returns a list of nested functions defined within this function's code block." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parameters + +SymbolGroup [ Parameter , PyFunction ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_statements + +list[ ReturnStatement ] } description="Returns a list of all return statements within this function's body." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a proper comment format." + defaultValue="True" +/> +bool } + description="Whether to clean and normalize the comment text before adding." + defaultValue="True" +/> +PyCommentType } + description="The style of comment to add (e.g., single-line, multi-line)." + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_statements +Adds statements to the end of a function body. + + + +str } + description="The lines of code to be added at the end of the function body." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### asyncify +Modifies the function to be asynchronous. + + + +None } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyFunction ] } description=""/> + + +### get_import_string +Generates an import string for a Python symbol. + + + +str | None } + description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." + defaultValue="None" +/> +str | None } + description="Optional module name to import from. If not provided, uses the symbol's file's module name." + defaultValue="None" +/> +ImportType } + description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type import. Currently unused. Defaults to False." + defaultValue="False" +/> + + + +str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### prepend_statements +Prepends statements to the start of the function body. + + + +str } + description="The code statements to prepend to the function body." + defaultValue="" +/> + + + +None } description="This method modifies the function in place."/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename_local_variable +Renames a local variable and all its usages within a function body. + + + +str } + description="The current name of the local variable to be renamed." + defaultValue="" +/> +str } + description="The new name to give to the local variable." + defaultValue="" +/> +bool, optional } + description="If True, matches variable names that contain old_var_name. Defaults to False." + defaultValue="False" +/> + + + +None } description="The method modifies the AST in place."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment for the Python symbol. + + + +str } + description="The comment text to be added or set." + defaultValue="" +/> +bool, optional } + description="If True, automatically formats the text as a comment." + defaultValue="True" +/> +bool, optional } + description="If True, cleans the format of the comment before" + defaultValue="True" +/> +PyCommentType , optional } + description="Type of comment to add (e.g., single line," + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description="This method modifies the symbol's comment in place."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to add." + defaultValue="" +/> +bool, optional } + description="If True, formats the text into a proper inline" + defaultValue="True" +/> +bool, optional } + description="If True, cleans the comment text before insertion" + defaultValue="True" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_return_type +Sets or modifies the return type annotation of a function. + + + +str } + description="The new return type annotation to set. Provide an empty string to remove the return type annotation." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyGenericType.mdx b/docs/api-reference/python/PyGenericType.mdx new file mode 100644 index 000000000..83fc16684 --- /dev/null +++ b/docs/api-reference/python/PyGenericType.mdx @@ -0,0 +1,471 @@ +--- +title: "PyGenericType" +sidebarTitle: "PyGenericType" +icon: "" +description: "Generic python type. + +Examples: +list[int] +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyNamedType](/api-reference/python/PyNamedType), [GenericType](/api-reference/core/GenericType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parameters + +Collection[ Type , PyGenericType ] } description="Retrieves the generic type parameters associated with this type." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyGenericType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyHasBlock.mdx b/docs/api-reference/python/PyHasBlock.mdx new file mode 100644 index 000000000..4ca25b547 --- /dev/null +++ b/docs/api-reference/python/PyHasBlock.mdx @@ -0,0 +1,487 @@ +--- +title: "PyHasBlock" +sidebarTitle: "PyHasBlock" +icon: "" +description: "Extends HasBlock for Python codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyHasBlock ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyIfBlockStatement.mdx b/docs/api-reference/python/PyIfBlockStatement.mdx new file mode 100644 index 000000000..06d2265ee --- /dev/null +++ b/docs/api-reference/python/PyIfBlockStatement.mdx @@ -0,0 +1,484 @@ +--- +title: "PyIfBlockStatement" +sidebarTitle: "PyIfBlockStatement" +icon: "" +description: "Pythons implementation of the if/elif/else statement block. +For example, if there is a code block like: +if condition1: +block1 +elif condition2: +block2 +else: +block3 +This class represents the entire block, including the conditions and nested code blocks. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[IfBlockStatement](/api-reference/core/IfBlockStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### alternative_blocks + +list[ IfBlockStatement ] } description="Returns a list of alternative if/elif/else blocks for the current block." /> + +### condition + +Expression [ PyIfBlockStatement ] | None } description="The condition expression for the if block. None if the block is an else block." /> + +### consequence_block + +CodeBlock } description="The code block that is executed if the condition is True." /> + +### else_statement + +IfBlockStatement | None } description="Returns the else block within the if-statement." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the if block statement and its alternative blocks." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_elif_statement + +bool } description="Determines if the current block is an 'elif' clause." /> + +### is_else_statement + +bool } description="Determines if the current block is an else block." /> + +### is_if_statement + +bool } description="Check if the current block is an if statement." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested code blocks within an if/elif/else statement block." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyIfBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### elif_statements +Returns all elif blocks within the if block. + + + +list[ IfBlockStatement ] } description="A list of elif block statements. Empty list if no elif blocks exist."/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyIfBlockStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a conditional block by reducing its condition to a boolean value. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyImport.mdx b/docs/api-reference/python/PyImport.mdx new file mode 100644 index 000000000..2dd99c8f6 --- /dev/null +++ b/docs/api-reference/python/PyImport.mdx @@ -0,0 +1,672 @@ +--- +title: "PyImport" +sidebarTitle: "PyImport" +icon: "" +description: "Extends Import for Python codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Import](/api-reference/core/Import), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### alias + +Editable | None } description=" +" /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### from_file + +SourceFile | None } description="Returns the SourceFile that an Import is importing from." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### import_specifier + +Editable } description="Retrieves the import specifier node for this import." /> + +### import_statement + +ImportStatement } description="the ImportStatement that this import belongs to" /> + +### import_type + +ImportType } description=" +" /> + +### imported_exports + +list[ Exportable ] } description="Returns a list of exports from an import statement." /> + +### imported_symbol + +Symbol | ExternalModule | SourceFile | Import | None } description="Returns the symbol directly being imported, including an indirect import and an External" /> + +### module + +Editable | None } description=" +" /> + +### name + +str | None } description="Returns the name or alias of the symbol being imported." /> + +### namespace + +str | None } description="Returns the namespace of the import if it imports a file, or None otherwise." /> + +### node_type + +Literal[NodeType.IMPORT] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_symbol + +Symbol | ExternalModule | SourceFile | None } description="Returns the symbol, source file, or external module that this import ultimately resolves" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### symbol_name + +Editable | None } description="The name of the symbol being imported. For instance import a as b has a symbol_name of a." /> + +### to_file + +SourceFile } description="SourceFile that this import resides in." /> + +### to_file_id + +NodeId } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyImport ] } description=""/> + + +### get_import_string +Generates an import string for a Python import statement. + + + +str | None } + description="Optional alias name for the imported symbol." + defaultValue="None" +/> +str | None } + description="Optional module name to import from. If not provided, uses the file's import module name." + defaultValue="None" +/> +ImportType } + description="Type of import to generate. Defaults to UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_aliased_import +Returns True if this import is aliased. + + + +bool } description="True if the import has an alias different from its original name, False otherwise."/> + + +### is_module_import +Determines if the import is a module-level or wildcard import. + + + +bool } description="True if the import is a module-level or wildcard import, False otherwise."/> + + +### is_reexport +Returns true if the Import object is also an Export object. + + + +bool } description="True if the import is re-exported, False otherwise."/> + + +### is_symbol_import +Returns True if this import is importing a symbol rather than a module. + + + +bool } description="True if this import is a symbol import, False if it is a module import."/> + + +### is_wildcard_import +Returns True if the import symbol is a wildcard import. + + + +bool } description="True if this is a wildcard import, False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Remove this import from the import statement. + + + +bool, optional } + description="Whether to delete any associated formatting. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of the operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate imports. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Renames the import symbol and updates all its usages throughout the codebase. + + + +str } + description="The new name to give the imported symbol." + defaultValue="" +/> +int, optional } + description="Priority of the rename operation. Defaults to 0." + defaultValue="0" +/> + + + +tuple[NodeId, NodeId] } description="A tuple containing (file_node_id, new_import_node_id)."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_import_module +Sets the module of an import. + + + +str } + description="The new module path to import from." + defaultValue="" +/> + + + +None } description=""/> + + +### set_import_symbol_alias +Sets alias or name of an import at the declaration level. + + + +str } + description="The new name to use for the imported symbol." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyImportStatement.mdx b/docs/api-reference/python/PyImportStatement.mdx new file mode 100644 index 000000000..a909f4a2d --- /dev/null +++ b/docs/api-reference/python/PyImportStatement.mdx @@ -0,0 +1,434 @@ +--- +title: "PyImportStatement" +sidebarTitle: "PyImportStatement" +icon: "" +description: "An abstract representation of a python import statement." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[ImportStatement](/api-reference/core/ImportStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### imports + +Collection[ Import , PyImportStatement ] } description="A collection of the individual imports this statement represents" /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyImportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyImportStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyMatchCase.mdx b/docs/api-reference/python/PyMatchCase.mdx new file mode 100644 index 000000000..14652356f --- /dev/null +++ b/docs/api-reference/python/PyMatchCase.mdx @@ -0,0 +1,509 @@ +--- +title: "PyMatchCase" +sidebarTitle: "PyMatchCase" +icon: "" +description: "Python match case." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyBlockStatement](/api-reference/python/PyBlockStatement), [SwitchCase](/api-reference/core/SwitchCase), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### condition + +Expression [ PyMatchCase ] | None } description="The condition which triggers this case" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyMatchCase ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyMatchCase ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyMatchStatement.mdx b/docs/api-reference/python/PyMatchStatement.mdx new file mode 100644 index 000000000..2b75be2f7 --- /dev/null +++ b/docs/api-reference/python/PyMatchStatement.mdx @@ -0,0 +1,439 @@ +--- +title: "PyMatchStatement" +sidebarTitle: "PyMatchStatement" +icon: "" +description: "Abstract representation of the match block" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[SwitchStatement](/api-reference/core/SwitchStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### cases + +list[ SwitchCase ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the switch statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the switch statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyMatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression [ PyMatchStatement ] } description="The value to switch on" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyMatchStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyNamedType.mdx b/docs/api-reference/python/PyNamedType.mdx new file mode 100644 index 000000000..71ac704ad --- /dev/null +++ b/docs/api-reference/python/PyNamedType.mdx @@ -0,0 +1,468 @@ +--- +title: "PyNamedType" +sidebarTitle: "PyNamedType" +icon: "" +description: "Named python type + +Examples: +int,str (builtin types) +Path (classes) +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyNamedType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyParameter.mdx b/docs/api-reference/python/PyParameter.mdx new file mode 100644 index 000000000..4d37457c4 --- /dev/null +++ b/docs/api-reference/python/PyParameter.mdx @@ -0,0 +1,592 @@ +--- +title: "PyParameter" +sidebarTitle: "PyParameter" +icon: "" +description: "Extends Parameter for Python codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Parameter](/api-reference/core/Parameter), [HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Typeable](/api-reference/core/Typeable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### default + +str | None } description="Returns the default value of a parameter if one exists." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="Returns the 0-based index of this parameter within its parent function's parameter list." /> + +### is_optional + +bool } description="Determines if the parameter is optional in Python code." /> + +### is_typed + +bool } description="Indicates if a node has an explicit type annotation." /> + +### is_variadic + +bool } description="Determines if a parameter is a variadic parameter." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### type + +Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_trailing_comment +Add a trailing comment to a parameter in a function signature. + + + +str } + description="The comment text to be added after the parameter." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyParameter ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes the parameter from the function definition and all its call sites. + + + +bool, optional } + description="Whether to delete formatting around the parameter. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level for the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Renames a parameter in a function definition and updates all related references. + + + +str } + description="The new name for the parameter." + defaultValue="" +/> +int, optional } + description="The priority of the edit operation. Defaults to 0." + defaultValue="0" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_type_annotation +Sets the type annotation of a parameter. + + + +str } + description="The type annotation to set for the parameter." + defaultValue="" +/> +str, optional } + description="A comment to include with the type annotation. Defaults to ""." + defaultValue="""" +/> + + + +None } description="Use `type.edit` instead."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyPassStatement.mdx b/docs/api-reference/python/PyPassStatement.mdx new file mode 100644 index 000000000..212e1961b --- /dev/null +++ b/docs/api-reference/python/PyPassStatement.mdx @@ -0,0 +1,430 @@ +--- +title: "PyPassStatement" +sidebarTitle: "PyPassStatement" +icon: "" +description: "An abstract representation of a python pass statement." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyPassStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyPassStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PyReturnTypePlaceholder.mdx b/docs/api-reference/python/PyReturnTypePlaceholder.mdx new file mode 100644 index 000000000..7a394a119 --- /dev/null +++ b/docs/api-reference/python/PyReturnTypePlaceholder.mdx @@ -0,0 +1,67 @@ +--- +title: "PyReturnTypePlaceholder" +sidebarTitle: "PyReturnTypePlaceholder" +icon: "" +description: "A placeholder for a python return type that does not exist. +Can be populated using the `edit` method. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Placeholder](/api-reference/core/Placeholder) + + +## Methods + +### edit +Edits or creates a return type annotation for a method or function. + + + +str } + description="The new return type annotation text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to fix the indentation of the new source. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the edit operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate the edit operation. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### remove +Removes this element from its parent container. + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyString.mdx b/docs/api-reference/python/PyString.mdx new file mode 100644 index 000000000..74344fde2 --- /dev/null +++ b/docs/api-reference/python/PyString.mdx @@ -0,0 +1,430 @@ +--- +title: "PyString" +sidebarTitle: "PyString" +icon: "" +description: "An abstract representation of a python string." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[String](/api-reference/core/String), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### content + +str } description="The content of the string" /> + +### content_nodes + +Collection[ Expression [ Editable ], PyString ] } description=" +" /> + +### expressions + +list[ Expression [ Editable ]] } description="embedded expressions in the string, only applicable for templated or formatted strings" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + +### with_quotes + +str } description="Retrieves the string representation with quotation marks." /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyString ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/python/PySymbol.mdx b/docs/api-reference/python/PySymbol.mdx new file mode 100644 index 000000000..c32ad4502 --- /dev/null +++ b/docs/api-reference/python/PySymbol.mdx @@ -0,0 +1,674 @@ +--- +title: "PySymbol" +sidebarTitle: "PySymbol" +icon: "" +description: "Extends `Symbol` for Python codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Symbol](/api-reference/core/Symbol), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### comment + +PyCommentGroup | None } description="Retrieves the comment group associated with a Python symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### inline_comment + +PyCommentGroup | None } description="Returns the inline comment group associated with this symbol." /> + +### is_exported + +bool } description="Indicates whether a Python symbol is exported." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + +SymbolType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a proper comment format." + defaultValue="True" +/> +bool } + description="Whether to clean and normalize the comment text before adding." + defaultValue="True" +/> +PyCommentType } + description="The style of comment to add (e.g., single-line, multi-line)." + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PySymbol ] } description=""/> + + +### get_import_string +Generates an import string for a Python symbol. + + + +str | None } + description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." + defaultValue="None" +/> +str | None } + description="Optional module name to import from. If not provided, uses the symbol's file's module name." + defaultValue="None" +/> +ImportType } + description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type import. Currently unused. Defaults to False." + defaultValue="False" +/> + + + +str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment for the Python symbol. + + + +str } + description="The comment text to be added or set." + defaultValue="" +/> +bool, optional } + description="If True, automatically formats the text as a comment." + defaultValue="True" +/> +bool, optional } + description="If True, cleans the format of the comment before" + defaultValue="True" +/> +PyCommentType , optional } + description="Type of comment to add (e.g., single line," + defaultValue="PyCommentType.SINGLE_LINE" +/> + + + +None } description="This method modifies the symbol's comment in place."/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to add." + defaultValue="" +/> +bool, optional } + description="If True, formats the text into a proper inline" + defaultValue="True" +/> +bool, optional } + description="If True, cleans the comment text before insertion" + defaultValue="True" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/python/PyTryCatchStatement.mdx b/docs/api-reference/python/PyTryCatchStatement.mdx new file mode 100644 index 000000000..3f0482aea --- /dev/null +++ b/docs/api-reference/python/PyTryCatchStatement.mdx @@ -0,0 +1,517 @@ +--- +title: "PyTryCatchStatement" +sidebarTitle: "PyTryCatchStatement" +icon: "" +description: "Abstract representation of the try/catch/finally block in Python. + +Attributes: +except_clauses: The exception handlers. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyBlockStatement](/api-reference/python/PyBlockStatement), [TryCatchStatement](/api-reference/core/TryCatchStatement), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### except_clauses + +list[ PyCatchStatement [ PyTryCatchStatement ]] } description="The exception handlers." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### finalizer + +BlockStatement | None } description="The code block executed regardless of if an exception is thrown or not" /> + +### function_calls + +list[ FunctionCall ] } description="Gets a list of all function calls contained within the try-catch statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### nested_code_blocks + +list[ PyCodeBlock ] } description="Returns all CodeBlocks nested within this try-catch statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyTryCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyTryCatchStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/python/PyUnionType.mdx b/docs/api-reference/python/PyUnionType.mdx new file mode 100644 index 000000000..0a09e8fb8 --- /dev/null +++ b/docs/api-reference/python/PyUnionType.mdx @@ -0,0 +1,400 @@ +--- +title: "PyUnionType" +sidebarTitle: "PyUnionType" +icon: "" +description: "Union type + +Examples: +str | int +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[UnionType](/api-reference/core/UnionType), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Get the source code content of the node." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Edit the source for this Collection instance. + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyUnionType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### index +Return the index of the first occurrence of value. + + + +int } description=""/> + + +### insert +Adds `value` to the container that this node represents + + + +None } description=""/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes an element from a Collection. + + + +Editable | None } + description="The element to remove from the Collection. If None, delegates to parent class." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/python/PyWhileStatement.mdx b/docs/api-reference/python/PyWhileStatement.mdx new file mode 100644 index 000000000..cb7da01ad --- /dev/null +++ b/docs/api-reference/python/PyWhileStatement.mdx @@ -0,0 +1,517 @@ +--- +title: "PyWhileStatement" +sidebarTitle: "PyWhileStatement" +icon: "" +description: "An abstract representation of a python while statement. + +Attributes: +else_statement (PyIfBlockStatement | None): the statement that will run if the while loop completes, if any. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[PyHasBlock](/api-reference/python/PyHasBlock), [WhileStatement](/api-reference/core/WhileStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description=" +" /> + +### condition + +Expression [ TSWhileStatement ] } description="The condition expression of the while loop." /> + +### decorators + +list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +PyCommentGroup | None } description="Gets the function's docstring." /> + +### else_statement + +PyIfBlockStatement [ PyCodeBlock [ PyWhileStatement ]] | None } description="the statement that will run if the while loop completes, if any." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the while statement and its else block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Returns whether the symbol is decorated with decorators." /> + +### nested_code_blocks + +list[ PyCodeBlock ] } description="Returns a list of all code blocks nested within the while statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ PyWhileStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ PyWhileStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a Python function or class. + + + +str } + description="The docstring content to set." + defaultValue="" +/> +bool, optional } + description="Whether to format the text into a proper docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean and normalize the docstring format before insertion. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/JSXElement.mdx b/docs/api-reference/typescript/JSXElement.mdx new file mode 100644 index 000000000..cb22ff1e6 --- /dev/null +++ b/docs/api-reference/typescript/JSXElement.mdx @@ -0,0 +1,542 @@ +--- +title: "JSXElement" +sidebarTitle: "JSXElement" +icon: "" +description: "Abstract representation of TSX/JSX elements, e.g. ``. This allows for many React-specific modifications, like adding props, changing the name, etc." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### attributes + +list[ JSXProp ] } description="Returns all JSXProp on this JSXElement, an alias for JSXElement.props." /> + +### expressions + +list[ JSXExpression ] } description="Gets all JSX expressions within the JSX element." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### jsx_elements + +list[ JSXElement ] } description="Returns a list of JSX elements nested within the current element." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### props + +list[ JSXProp ] } description="Retrieves all JSXProps (attributes) from a JSX element." /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_prop +Adds a new prop to a JSXElement. + + + +str } + description="The name of the prop to add." + defaultValue="" +/> +str } + description="The value of the prop to add." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ JSXElement ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_prop +Returns the JSXProp with the given name from the JSXElement. + + + +str } + description="The name of the prop to find." + defaultValue="" +/> + + + +JSXProp | None } description="The matching JSXProp object if found, None if not found."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a JSXElement by modifying both opening and closing tags. + + + +str } + description="The new name to set for the JSX element." + defaultValue="" +/> + + + +None } description="The method modifies the JSXElement in place."/> + + +### wrap +Wraps the current JSXElement with the provided opening and closing tags, properly handling indentation. + + + +str } + description="The opening JSX tag to wrap around the current element (e.g. `
`)" + defaultValue="" +/> +str } + description="The closing JSX tag to wrap around the current element (e.g. `
`)" + defaultValue="" +/> +
+ + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/JSXExpression.mdx b/docs/api-reference/typescript/JSXExpression.mdx new file mode 100644 index 000000000..7693abe94 --- /dev/null +++ b/docs/api-reference/typescript/JSXExpression.mdx @@ -0,0 +1,426 @@ +--- +title: "JSXExpression" +sidebarTitle: "JSXExpression" +icon: "" +description: "Abstract representation of TSX/JSX expression" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Unwrappable](/api-reference/core/Unwrappable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement + +Editable [ JSXExpression ] | None } description="Returns the editable component of this JSX expression." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ JSXExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a JSX expression by reducing it based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/JSXProp.mdx b/docs/api-reference/typescript/JSXProp.mdx new file mode 100644 index 000000000..e33e65274 --- /dev/null +++ b/docs/api-reference/typescript/JSXProp.mdx @@ -0,0 +1,488 @@ +--- +title: "JSXProp" +sidebarTitle: "JSXProp" +icon: "" +description: "Abstract representation of TSX/JSX prop, e.g ``." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### expression + +JSXExpression | None } description="Retrieves the JSX expression associated with this JSX prop." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ JSXProp ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts source code after a JSX prop in a TypeScript/JSX file. + + + +str } + description="The source code to insert after the prop." + defaultValue="" +/> +bool, optional } + description="Whether to fix the indentation of the inserted code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of the insertion. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Insert a new source code string before a JSX prop in a React component. + + + +str } + description="The source code string to insert before the prop." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of this insertion relative to others. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to avoid duplicate insertions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSArrayType.mdx b/docs/api-reference/typescript/TSArrayType.mdx new file mode 100644 index 000000000..75a123be5 --- /dev/null +++ b/docs/api-reference/typescript/TSArrayType.mdx @@ -0,0 +1,466 @@ +--- +title: "TSArrayType" +sidebarTitle: "TSArrayType" +icon: "" +description: "Array type +Examples: +string[] +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSNamedType](/api-reference/typescript/TSNamedType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSArrayType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSAssignment.mdx b/docs/api-reference/typescript/TSAssignment.mdx new file mode 100644 index 000000000..b02a08bc3 --- /dev/null +++ b/docs/api-reference/typescript/TSAssignment.mdx @@ -0,0 +1,812 @@ +--- +title: "TSAssignment" +sidebarTitle: "TSAssignment" +icon: "" +description: "A class representing TypeScript assignments, including variable declarations and property assignments. + +Handles various types of TypeScript assignments including variable declarators, assignment expressions, +augmented assignments, property signatures, and public field definitions. It provides functionality +for manipulating assignments and managing their associated types and comments. + +Attributes: +assignment_types (list[str]): List of valid TypeScript assignment node types that this class can handle. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSSymbol](/api-reference/typescript/TSSymbol), [Assignment](/api-reference/core/Assignment), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [HasValue](/api-reference/core/HasValue), [Typeable](/api-reference/core/Typeable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### assignment_types + +list[str] } description="List of valid TypeScript assignment node types that this class can handle." /> + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### index + +int } description="Returns the index of the assignment statement in its parent's code block." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_local_variable + +bool } description="Determines if an assignment represents a local variable in the current scope." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### is_typed + +bool } description="Indicates if a node has an explicit type annotation." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type + +Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSAssignment ] } description=""/> + + +### from_named_expression +Creates a MultiExpression object from a TypeScript named expression node. + + + +TSNode } + description="The TypeScript node representing the named expression." + defaultValue="" +/> +NodeId } + description="The unique identifier for the file containing this node." + defaultValue="" +/> +CodebaseGraph } + description="The graph representation of the codebase." + defaultValue="" +/> +Editable } + description="The parent node containing this expression." + defaultValue="" +/> + + + +MultiExpression [ TSAssignmentStatement , TSAssignment ] } description="A MultiExpression object containing the constructed assignments."/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### local_usages +Retrieves all usages of the assigned variable within its code block scope. + + + +list[ Editable [ Statement ]] } description="A sorted list of statement nodes where the variable is used."/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies an assignment expression by reducing it based on a boolean condition and updating all the usages. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment for an assignment node. + + + +str } + description="The comment text to set." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the comment. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_type_annotation +Adds or updates a type annotation for the current assignment. + + + +str } + description="The type annotation to be added or updated." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of an assignment expression. + + + +str } + description="The source code string representing the new value to be assigned." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSAssignmentStatement.mdx b/docs/api-reference/typescript/TSAssignmentStatement.mdx new file mode 100644 index 000000000..2004b29f8 --- /dev/null +++ b/docs/api-reference/typescript/TSAssignmentStatement.mdx @@ -0,0 +1,476 @@ +--- +title: "TSAssignmentStatement" +sidebarTitle: "TSAssignmentStatement" +icon: "" +description: "A class that represents a TypeScript assignment statement in a codebase, such as `const x = 1` or `const { a: b } = myFunc()`. + +This includes potentially multiple Assignments via `statement.assignments`, which represent each assignment of a value to a variable within this statement. + +For example, assigning to a destructured object, or assigning multiple values to multiple variables in a single statement. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[AssignmentStatement](/api-reference/core/AssignmentStatement), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### assignment_types + + } description=" +" /> + +### assignments + +list[ Assignment ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### left + +Expression [ Assignment ] } description=" +" /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSAssignmentStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ Assignment ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSAssignmentStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSAttribute.mdx b/docs/api-reference/typescript/TSAttribute.mdx new file mode 100644 index 000000000..010d3e506 --- /dev/null +++ b/docs/api-reference/typescript/TSAttribute.mdx @@ -0,0 +1,572 @@ +--- +title: "TSAttribute" +sidebarTitle: "TSAttribute" +icon: "" +description: "Typescript implementation of Attribute detached symbol." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSAssignmentStatement](/api-reference/typescript/TSAssignmentStatement), [Attribute](/api-reference/core/Attribute), [AssignmentStatement](/api-reference/core/AssignmentStatement), [Usable](/api-reference/core/Usable), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### assignment + +Assignment } description=" +" /> + +### assignment_types + + } description=" +" /> + +### assignments + +list[ Assignment ] } description=" +" /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_optional + +bool } description="Returns True if this attribute is marked as optional in TypeScript." /> + +### is_private + +bool } description="Determines if this attribute has a private accessibility modifier." /> + +### left + +Expression [ Assignment ] } description=" +" /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSAttribute ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +Expression [ Assignment ] | None } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSAttribute ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### local_usages +Returns local usages of a TypeScript attribute within its code block. + + + +TSAttribute[TSHasBlock, TSCodeBlock] } + description="The TypeScript attribute instance." + defaultValue="" +/> + + + +list[ Editable ] } description="A sorted list of unique Editable instances representing local usages of the attribute, ordered by their position in the source code."/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of a node's assignment. + + + +str } + description="The new value to set for the assignment." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSBlockStatement.mdx b/docs/api-reference/typescript/TSBlockStatement.mdx new file mode 100644 index 000000000..64d7e14f2 --- /dev/null +++ b/docs/api-reference/typescript/TSBlockStatement.mdx @@ -0,0 +1,532 @@ +--- +title: "TSBlockStatement" +sidebarTitle: "TSBlockStatement" +icon: "" +description: "Statement which contains a block." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### jsx_elements + +list[ JSXElement [ TSBlockStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSBlockStatement ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSBlockStatement ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSCatchStatement.mdx b/docs/api-reference/typescript/TSCatchStatement.mdx new file mode 100644 index 000000000..1008db674 --- /dev/null +++ b/docs/api-reference/typescript/TSCatchStatement.mdx @@ -0,0 +1,541 @@ +--- +title: "TSCatchStatement" +sidebarTitle: "TSCatchStatement" +icon: "" +description: "Typescript catch clause. + +Attributes: +code_block: The code block that may trigger an exception +condition: The condition which triggers this clause +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [CatchStatement](/api-reference/core/CatchStatement), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### condition + +Expression [ PyCatchStatement ] | None } description="The condition which triggers this clause" /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### jsx_elements + +list[ JSXElement [ TSCatchStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSCatchStatement ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSCatchStatement ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSChainedAttribute.mdx b/docs/api-reference/typescript/TSChainedAttribute.mdx new file mode 100644 index 000000000..8ca13a20f --- /dev/null +++ b/docs/api-reference/typescript/TSChainedAttribute.mdx @@ -0,0 +1,430 @@ +--- +title: "TSChainedAttribute" +sidebarTitle: "TSChainedAttribute" +icon: "" +description: "A TypeScript chained attribute class representing member access expressions. + +This class handles the representation and analysis of chained attribute access expressions in TypeScript, +such as 'object.property' or 'object.method()'. It provides functionality for accessing the object +and property components of the expression, as well as analyzing function calls made on the object. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[ChainedAttribute](/api-reference/core/ChainedAttribute), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### attribute + +Attribute } description="Gets the attribute being accessed in a chained attribute expression." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str } description="Returns the full name of the attribute, including the object expression." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of function calls associated with this chained attribute's object." /> + +### node_type + +NodeType } description=" +" /> + +### object + +Object } description="Returns the object that contains the attribute being looked up." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSChainedAttribute ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSClass.mdx b/docs/api-reference/typescript/TSClass.mdx new file mode 100644 index 000000000..69db3459a --- /dev/null +++ b/docs/api-reference/typescript/TSClass.mdx @@ -0,0 +1,1159 @@ +--- +title: "TSClass" +sidebarTitle: "TSClass" +icon: "" +description: "A class representing a TypeScript/JavaScript class with enhanced functionality for class manipulation. + +The TSClass provides comprehensive functionality for working with TypeScript/JavaScript classes, +including handling class methods, attributes, JSX components, and inheritance relationships. +It supports operations like adding source code to class bodies, managing class attributes, +and handling React JSX components. + +Attributes: +parent_classes (Parents | None): The parent classes that this class extends or implements. +constructor_keyword (str): The keyword used to identify the constructor method. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [Class](/api-reference/core/Class), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### constructor + +Function | None } description="Returns the constructor method for this class." /> + +### constructor_keyword + + } description="The keyword used to identify the constructor method." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_jsx + +bool } description="Determine if the class is a React JSX component." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### is_subclass + +bool } description="Indicates whether the current class is a subclass of another class." /> + +### jsx_elements + +list[ JSXElement [ TSClass ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_classes + +list[ TSClass ] } description="Retrieves the nested classes defined within this class." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parameters + +SymbolGroup [ Parameter , TSClass ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_class_names + +list[ Name | ChainedAttribute ] } description="Returns a list of the parent class names that this class inherits from." /> + +### parent_classes + +Parents[ Type , PyClass ] | None } description=" +" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_attribute +Adds an attribute to a class from another class. + + + +Attribute } + description="The attribute to add to the class." + defaultValue="" +/> +bool, optional } + description="Whether to include the attribute's dependencies. If True, adds any necessary imports to the class's file. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### add_attribute_from_source +Adds a class attribute from source code to a TypeScript/JavaScript class. + + + +str } + description="The source code of the attribute to add to the class." + defaultValue="" +/> + + + +None } description=""/> + + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_source +Adds source code to a class body. + + + +str } + description="The source code to be added to the class body." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### attributes +Retrieves all attributes from this Class including those from its superclasses up to a + + + +int | None } + description="The maximum depth of superclass traversal. None means no limit, 0 means only this class." + defaultValue="0" +/> +bool } + description="Whether to include private attributes. Defaults to True." + defaultValue="True" +/> + + + +list[ Attribute ] } description="A list of unique attributes from this class and its superclasses. If an attribute is defined in multiple classes, the first definition encountered is used."/> + + +### class_component_to_function_component +Converts a class component to a function component. + + + +None } description=""/> + + +### convert_props_to_interface +Converts React component props to TypeScript interfaces. + + + +None } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSClass ] } description=""/> + + +### get_attribute +Returns a specific attribute by name. + + + +str } + description="The name of the attribute to search for." + defaultValue="" +/> + + + +Attribute | None } description="The matching attribute if found, None otherwise. If multiple attributes with the same name exist in the inheritance hierarchy, returns the first one found."/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSClass ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_method +Returns a specific method by name from the class or any of its superclasses. + + + +str } + description="The name of the method to find." + defaultValue="" +/> + + + +Function | None } description="The method if found, None otherwise."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_nested_class +Returns a nested class by name from the current class. + + + +str } + description="The name of the nested class to find." + defaultValue="" +/> + + + +TSClass | None } description="The nested class if found, None otherwise."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_parent_class +Returns the parent class node with the specified name. + + + +str } + description="The name of the parent class to find." + defaultValue="" +/> + + + +Editable | None } description="The matching parent class node, or None if no match is found."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_subclass_of +Checks if the class inherits from a specified parent class. + + + +str | Class } + description="The parent class to check for. Can be specified either as a class name string or Class object." + defaultValue="" +/> +int | None } + description="Maximum inheritance depth to search. None means no limit." + defaultValue="None" +/> + + + +bool } description="True if this class inherits from the parent class, False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### methods +Retrieves all methods that exist on this Class, including methods from superclasses, with + + + +int | None, optional } + description="Include parent classes up to max_depth. None means no limit, 0 means only current class. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to include private methods. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include magic methods. Defaults to False." + defaultValue="True" +/> + + + +list[ Function ] | MultiLineCollection [ Function , TSClass ] } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text as a comment." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the comment format before inserting." + defaultValue="True" +/> +TSNode | None, optional } + description="The specific node to attach the comment to." + defaultValue="None" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### subclasses +Returns all classes which subclass this class. + + + +int | None, optional } + description="Maximum inheritance depth to search. If None, searches all depths. Defaults to None." + defaultValue="None" +/> + + + +list[ Class ] } description="A list of Class objects that inherit from this class."/> + + +### superclasses +Returns a list of all classes that this class extends, up to max_depth. + + + +int | None } + description="The maximum depth to traverse up the inheritance tree. If None, traverses the entire tree." + defaultValue="None" +/> + + + +list[ Class | ExternalModule | Interface] } description="A list of all superclass symbols in MRO order, up to max_depth. Returns an empty list if the class has no parent classes."/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSCodeBlock.mdx b/docs/api-reference/typescript/TSCodeBlock.mdx new file mode 100644 index 000000000..4445711e4 --- /dev/null +++ b/docs/api-reference/typescript/TSCodeBlock.mdx @@ -0,0 +1,585 @@ +--- +title: "TSCodeBlock" +sidebarTitle: "TSCodeBlock" +icon: "" +description: "Extends the CodeBlock class to provide TypeScript-specific functionality." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[CodeBlock](/api-reference/core/CodeBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### assignment_statements + +list[ AssignmentStatement [ TSCodeBlock , Assignment ]] } description="Returns list of top level assignment statements in the code block." /> + +### assignments + +list[ Assignment [ Editable , TSCodeBlock ]] } description="Returns all assignments in the code block across all nesting levels." /> + +### attributes + +list[ Attribute [ Editable , TSCodeBlock ]] } description="Returns a list of top level class attribute statements in the code block." /> + +### comments + +list[ Comment [ Editable , TSCodeBlock ]] } description="Gets list of top level comments in the code block." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls in the code block." /> + +### if_blocks + +list[ IfBlockStatement [ TSCodeBlock ]] } description="Returns a list of top level if statements in the code block." /> + +### level + +int } description=" +" /> + +### local_var_assignments + +list[ Assignment [ Editable , TSCodeBlock ]] } description="Returns all local variable assignment in the code block, for all nest levels." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_block + +CodeBlock | None } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_statements + +list[ ReturnStatement [ TSCodeBlock ]] } description="Gets all return statements at the top level of the code block." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statements + +MultiLineCollection [ Statement , TSCodeBlock ] } description="Gets a view of the top-level statements in the code block." /> + +### symbol_statements + +list[ SymbolStatement ] } description="Returns list of top level symbol statements in the code block." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSCodeBlock ] } description=""/> + + +### get_assignments +Returns a list of assignments with the specified variable name. + + + +str } + description="The name of the variable to find assignments for." + defaultValue="" +/> + + + +list[ Assignment [ Editable , TSCodeBlock ]] } description="A list of Assignment objects that match the variable name."/> + + +### get_attributes +Returns attributes from the code block, with the option to include or exclude private + + + +bool } + description="Whether to include private attributes in the returned list. If True, returns both private and" + defaultValue="" +/> + + + +list[ Attribute [ Editable , TSCodeBlock ]] } description="A list of attribute statements matching the privacy criteria."/> + + +### get_comment +Gets the first comment statement containing a specific text string. + + + +str } + description="The text string to search for within comment statements." + defaultValue="" +/> + + + +Comment [ Editable , TSCodeBlock ] | None } description="The first comment statement containing the search text, or None if no matching comment is found."/> + + +### get_local_var_assignment +Returns the first code statement that assigns a local variable with the specified name. + + + +str } + description="The name of the local variable to search for." + defaultValue="" +/> + + + +Assignment [ Editable , TSCodeBlock ] | None } description="The first matching local variable assignment, or None if no match is found."/> + + +### get_local_var_assignments +Returns all instances of local variable assignments that match the specified variable + + + +str } + description="The name of the local variable to search for." + defaultValue="" +/> +bool, optional } + description="If True, matches variables whose names contain var_name." + defaultValue="False" +/> + + + +list[ Assignment [ Editable , TSCodeBlock ]] } description="List of Assignment objects representing local variable assignments that match the specified name criteria."/> + + +### get_statements +Returns all statements of a given type up to the specified block level. + + + +StatementType | None } + description="The type of statements to return. If None, returns all statement types." + defaultValue="None" +/> +int | None } + description="The maximum block depth level to search. If None, searches all levels." + defaultValue="None" +/> + + + +list[ Statement [ TSCodeBlock ]] } description=""/> + + +### get_variable_usages +Returns all instances of variable usages in a code block. + + + +str } + description="The name of the variable to search for." + defaultValue="" +/> +bool } + description="When True, matches on variable names that contain var_name. When False (default), only matches exact variable names." + defaultValue="False" +/> + + + +list[ Editable [ TSCodeBlock ]] } description="A sorted list of variable usage instances as Editable objects."/> + + +### indent +Adjusts the indentation level of the entire code block. + + + +int } + description="The number of indentation levels to adjust. Positive values indent right, negative values indent left." + defaultValue="" +/> + + + +None } description=""/> + + +### insert_before +Inserts new source code at the top of the code block. + + + +str } + description="The source code to insert at the top of the code block." + defaultValue="" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename_variable_usages +Renames all instances of variable usages in the code block. + + + +str } + description="The current name of the variable to rename." + defaultValue="" +/> +str } + description="The new name to give the variable." + defaultValue="" +/> +bool } + description="When True, matches variables containing old_var_name. When False, only exact matches. Defaults to False." + defaultValue="False" +/> + + + +None } description="This method mutates the code block in place."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### unwrap +Unwraps a code block by removing its opening and closing braces. + + + +None } description=""/> + + +### wrap +Wraps a code block with a statement and indents it. + + + +str } + description="The source code to insert before the block." + defaultValue="" +/> +str } + description="The source code to insert after the block. Defaults to an empty string." + defaultValue="""" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSComment.mdx b/docs/api-reference/typescript/TSComment.mdx new file mode 100644 index 000000000..8f33d9ca6 --- /dev/null +++ b/docs/api-reference/typescript/TSComment.mdx @@ -0,0 +1,507 @@ +--- +title: "TSComment" +sidebarTitle: "TSComment" +icon: "" +description: "Abstract representation of typescript comments" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Comment](/api-reference/core/Comment), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### comment_type + +TSCommentType } description="Determines the type of comment in a TypeScript source code." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns a list of nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSComment ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### text + +str } description="Returns the text content of the comment." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### clean_comment +Cleans comment markers and whitespace from a comment string. + + + +str } + description="The raw comment string to be cleaned." + defaultValue="" +/> + + + +str } description="The cleaned comment text with comment markers and excess whitespace removed."/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### edit_text +Replace the text of a comment with new text. + + + +str } + description="The new text content to replace the existing comment text." + defaultValue="" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSComment ] } description=""/> + + +### generate_comment +Generates a TypeScript comment block from the given text content. + + + +str } + description="The text content to be converted into a comment." + defaultValue="" +/> +TSCommentType } + description="The type of comment to generate (DOUBLE_SLASH or SLASH_STAR)." + defaultValue="" +/> +bool, optional } + description="Whether to add leading "*" to each line in multi-line comments. Defaults to True." + defaultValue="" +/> +bool, optional } + description="Whether to force multi-line format for single-line content. Defaults to False." + defaultValue="" +/> + + + +str } description="The formatted comment block as a string."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSCommentGroup.mdx b/docs/api-reference/typescript/TSCommentGroup.mdx new file mode 100644 index 000000000..145c14183 --- /dev/null +++ b/docs/api-reference/typescript/TSCommentGroup.mdx @@ -0,0 +1,445 @@ +--- +title: "TSCommentGroup" +sidebarTitle: "TSCommentGroup" +icon: "" +description: "A group of related symbols that represent a comment or docstring in TypeScript + +For example: +``` +// Comment 1 +// Comment 2 +// Comment 3 +``` +would be 3 individual comments (accessible via `symbols`), but together they form a `CommentGroup` (accessible via `self). +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[CommentGroup](/api-reference/core/CommentGroup), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### source + +str } description="Returns the concatenated source code of all symbols in the group." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### text + +str } description="Return the text content of all comments in the comment block." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new text. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool, optional } + description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Prevents duplicate edits at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### edit_text +Replace the text content of a comment group with new text. + + + +str } + description="The new text content to replace the existing comment text." + defaultValue="" +/> + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSCommentGroup ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes this node and its related extended nodes from the codebase. + + + +bool, optional } + description="Whether to delete related extended nodes like decorators and comments. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level of the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/typescript/TSCommentType.mdx b/docs/api-reference/typescript/TSCommentType.mdx new file mode 100644 index 000000000..047c6b888 --- /dev/null +++ b/docs/api-reference/typescript/TSCommentType.mdx @@ -0,0 +1,42 @@ +--- +title: "TSCommentType" +sidebarTitle: "TSCommentType" +icon: "" +description: "An enumeration representing different types of comments in TypeScript. + +Represents the possible types of comments that can be used in TypeScript code, +including double slash comments (//), slash star comments (/* */), and unknown +comment types. + +Attributes: +DOUBLE_SLASH (str): Represents a single-line comment starting with //. +SLASH_STAR (str): Represents a multi-line comment enclosed in /* */. +UNKNOWN (str): Represents an unknown or unrecognized comment type. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### DOUBLE_SLASH + + } description="Represents a single-line comment starting with //." /> + +### SLASH_STAR + + } description="Represents a multi-line comment enclosed in /* */." /> + +### UNKNOWN + + } description="Represents an unknown or unrecognized comment type." /> + + + diff --git a/docs/api-reference/typescript/TSConditionalType.mdx b/docs/api-reference/typescript/TSConditionalType.mdx new file mode 100644 index 000000000..20cecea4d --- /dev/null +++ b/docs/api-reference/typescript/TSConditionalType.mdx @@ -0,0 +1,437 @@ +--- +title: "TSConditionalType" +sidebarTitle: "TSConditionalType" +icon: "" +description: "Conditional Type + +Examples: +typeof s +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### alternative + +TSType[ TSConditionalType ] } description=" +" /> + +### consequence + +TSType[ TSConditionalType ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### left + +TSType[ TSConditionalType ] } description=" +" /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### right + +TSType[ TSConditionalType ] } description=" +" /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSConditionalType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSConfig.mdx b/docs/api-reference/typescript/TSConfig.mdx new file mode 100644 index 000000000..b0047a7b9 --- /dev/null +++ b/docs/api-reference/typescript/TSConfig.mdx @@ -0,0 +1,115 @@ +--- +title: "TSConfig" +sidebarTitle: "TSConfig" +icon: "" +description: "TypeScript configuration file specified in tsconfig.json, used for import resolution and computing dependencies." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + + +## Attributes + +### base_config + +TSConfig | None } description="Returns the base TSConfig that this config inherits from." /> + +### base_url + +str | None } description="Returns the base URL defined in the TypeScript configuration." /> + +### config + +dict } description=" +" /> + +### config_file + +File } description=" +" /> + +### config_parser + +TSConfigParser } description=" +" /> + +### out_dir + +str | None } description="Returns the outDir defined in the TypeScript configuration." /> + +### path_import_aliases + +dict[str, list[str]] } description="Returns a formatted version of the paths property from a TypeScript configuration file." /> + +### paths + +dict[str, list[str]] } description="Returns all custom module path mappings defined in the tsconfig file." /> + +### reference_import_aliases + +dict[str, list[str]] } description="Returns a formatted version of the references property from a TypeScript configuration file." /> + +### references + +list[ Directory | File ] } description="Returns a list of directories that this TypeScript configuration file depends on." /> + +### root_dir + +str | None } description="Returns the rootDir defined in the TypeScript configuration." /> + +### root_dirs + +list[str] } description="Returns the rootDirs defined in the TypeScript configuration." /> + + +## Methods + +### resolve_base_url +Resolves an import path with the base url. + + + +str } description=""/> + + +### translate_absolute_path +Translates an absolute path to an import path using the tsconfig paths. + + + +str } + description="The absolute path to translate." + defaultValue="" +/> + + + +str } description="The translated import path."/> + + +### translate_import_path +Translates an import path to an absolute path using the tsconfig paths. + + + +str } + description="The import path to translate." + defaultValue="" +/> + + + +str } description="The translated absolute path. If no matching path alias is found, returns the original import path unchanged."/> + + + diff --git a/docs/api-reference/typescript/TSDecorator.mdx b/docs/api-reference/typescript/TSDecorator.mdx new file mode 100644 index 000000000..47e7aaeff --- /dev/null +++ b/docs/api-reference/typescript/TSDecorator.mdx @@ -0,0 +1,467 @@ +--- +title: "TSDecorator" +sidebarTitle: "TSDecorator" +icon: "" +description: "Abstract representation of a Decorator" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Decorator](/api-reference/core/Decorator), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### call + +FunctionCall | None } description="Retrieves the function call expression associated with the decorator." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSDecorator ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSDict.mdx b/docs/api-reference/typescript/TSDict.mdx new file mode 100644 index 000000000..0d184699b --- /dev/null +++ b/docs/api-reference/typescript/TSDict.mdx @@ -0,0 +1,418 @@ +--- +title: "TSDict" +sidebarTitle: "TSDict" +icon: "" +description: "A typescript dict object. You can use standard operations to operate on this dict (IE len, del, set, get, etc)" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Dict](/api-reference/core/Dict), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### unpack + +Unpack [ TSObjectType ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSDict ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSEnum.mdx b/docs/api-reference/typescript/TSEnum.mdx new file mode 100644 index 000000000..3aa97a7a7 --- /dev/null +++ b/docs/api-reference/typescript/TSEnum.mdx @@ -0,0 +1,828 @@ +--- +title: "TSEnum" +sidebarTitle: "TSEnum" +icon: "" +description: "Representation of an Enum in TypeScript" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### attributes + +list[ TSAttribute [ TSEnum , None]] } description="Property that retrieves the attributes of a TypeScript enum." /> + +### body + +Expression [ TSEnum ] } description=" +" /> + +### code_block + +TSCodeBlock } description=" +" /> + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### jsx_elements + +list[ JSXElement [ TSEnum ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSEnum ] } description=""/> + + +### get_attribute +Returns an attribute from the TypeScript enum by its name. + + + +str } + description="The name of the attribute to retrieve." + defaultValue="" +/> + + + +TSAttribute | None } description="The attribute with the given name if it exists, None otherwise."/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSEnum ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text as a comment." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the comment format before inserting." + defaultValue="True" +/> +TSNode | None, optional } + description="The specific node to attach the comment to." + defaultValue="None" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSExport.mdx b/docs/api-reference/typescript/TSExport.mdx new file mode 100644 index 000000000..500f11d57 --- /dev/null +++ b/docs/api-reference/typescript/TSExport.mdx @@ -0,0 +1,687 @@ +--- +title: "TSExport" +sidebarTitle: "TSExport" +icon: "" +description: "Represents a single exported symbol. There is a 1:M relationship between an ExportStatement and an Export" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasValue](/api-reference/core/HasValue), [Export](/api-reference/core/Export), [Editable](/api-reference/core/Editable), [Exportable](/api-reference/core/Exportable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### declared_symbol + +TSSymbol | TSImport | None } description="Returns the symbol that was defined in this export." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### descendant_symbols + +list[ Importable ] } description="Returns a list of all descendant symbols from this export's declared symbol." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### export_statement + +ExportStatement } description=" +" /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### exported_symbol + +Exportable | None } description="Returns the symbol, file, or import being exported from this export object." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_external_export + +bool } description="Determines if this export is exporting a symbol from an external (non-relative) module." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.EXPORT] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_symbol + +Exportable | None } description="Returns the Symbol, SourceFile or External module that this export resolves to." /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSExport ] } description=""/> + + +### get_import_string +Returns the import string for this export. + + + +str | None } + description="Optional alias to use when importing the symbol." + defaultValue="None" +/> +str | None } + description="Optional module name to import from." + defaultValue="None" +/> +ImportType } + description="The type of import to generate." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type-only import." + defaultValue="False" +/> + + + +str } description="The formatted import string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_aliased +Determines if the Export object is aliased. + + + +bool } description="True if the exported symbol has a different name than the name it is exported as, False otherwise."/> + + +### is_default_export +Determines if an export is the default export for a file. + + + +bool } description="True if this is a default export, False otherwise."/> + + +### is_default_symbol_export +Returns True if this is exporting a default symbol, as opposed to a default object export. + + + +TSExport } + description="The export object being checked." + defaultValue="" +/> + + + +bool } description="True if this is a default symbol export, False otherwise."/> + + +### is_module_export +Determines if the export is exporting a module rather than a symbol. + + + +bool } description="True if the export represents a module export, False otherwise."/> + + +### is_named_export +Determines whether this export is a named export. + + + +bool } description="True if this is a named export, False if it is a default export."/> + + +### is_reexport +Returns whether the export is re-exporting an import or export. + + + +TSExport } + description="The export node being checked." + defaultValue="" +/> + + + +bool } description="True if this export re-exports an imported/exported symbol or entire module, False otherwise."/> + + +### is_type_export +Determines if this export is exclusively exporting a type. + + + +bool } description="True if this is a type-only export, False otherwise."/> + + +### is_wildcard_export +Determines if the export is a wildcard export. + + + +bool } description="True if the export is a wildcard export (e.g. 'export * from "./module"'), False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### make_non_default +Converts the export to a named export. + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### reexport_symbol +Returns the import object that is re-exporting this symbol. + + + +TSImport | None } description="The import object being re-exported, or None if this is not a re-export or no import was found."/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### to_import_string +Converts this export into its equivalent import string representation. + + + +str } description="The import string representation of this export. Examples: - For `export { foo } from './bar'` -> `import { foo } from './bar'` - For `export * from './bar'` -> `import * as _namespace from './bar'` - For `export { default as foo } from './bar'` -> `import foo from './bar'`"/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSExpressionType.mdx b/docs/api-reference/typescript/TSExpressionType.mdx new file mode 100644 index 000000000..5406d14d0 --- /dev/null +++ b/docs/api-reference/typescript/TSExpressionType.mdx @@ -0,0 +1,471 @@ +--- +title: "TSExpressionType" +sidebarTitle: "TSExpressionType" +icon: "" +description: "Type defined by evaluation of an expression + +Attributes: +expression: The expression to evaluate that yields the type +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSNamedType](/api-reference/typescript/TSNamedType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### expression + +Expression [ TSExpressionType [ Editable ]] } description="The expression to evaluate that yields the type" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSExpressionType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSFile.mdx b/docs/api-reference/typescript/TSFile.mdx new file mode 100644 index 000000000..79ce00d47 --- /dev/null +++ b/docs/api-reference/typescript/TSFile.mdx @@ -0,0 +1,1053 @@ +--- +title: "TSFile" +sidebarTitle: "TSFile" +icon: "" +description: "Extends the SourceFile class to provide TypeScript-specific functionality." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Exportable](/api-reference/core/Exportable), [TSHasBlock](/api-reference/typescript/TSHasBlock), [SourceFile](/api-reference/core/SourceFile), [Usable](/api-reference/core/Usable), [HasBlock](/api-reference/core/HasBlock), [File](/api-reference/core/File), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [HasName](/api-reference/core/HasName) + +## Attributes + +### classes + +list[ Class ] } description="Returns all Classes in the file." /> + +### code_block + +CodeBlock } description=" +" /> + +### content + +str } description="Returns the content of the file as a UTF-8 encoded string." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### default_exports + +list[ TSExport ] } description="Returns all default export symbols from the file." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### directory + +Directory | None } description="Returns the directory that contains this file." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### export_statements + +list[ ExportStatement [ TSExport ]] } description="Returns a list of all export statements in the file." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### exports + +list[ TSExport ] } description="Returns all Export symbols in the file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### extension + +str } description="Returns the file extension." /> + +### file + +TSFile } description="A property that returns the file object for non-source files." /> + +### file_node_id + +NodeId } description=" +" /> + +### file_path + +str } description=" +" /> + +### filepath + +str } description="Retrieves the file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### functions + +list[ Function ] } description="Returns all Functions in the file." /> + +### global_vars + +list[ Assignment ] } description="Returns all GlobalVars in the file." /> + +### import_module_name + +str } description="Returns the module name that this file gets imported as." /> + +### import_statements + +list[ ImportStatement ] } description="Returns all ImportStatements in the file, where each import statement can contain" /> + +### importers + +list[ Import ] } description="Returns all imports that directly imports this file as a module." /> + +### imports + +list[ Import ] } description="List of all Imports in this file." /> + +### inbound_imports + +list[ Import ] } description="Returns all imports that are importing symbols contained in this file." /> + +### interfaces + +list[ TSInterface ] } description="Returns all Interfaces in the file." /> + +### is_binary + +bool } description="Indicates whether the file contains binary data." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### jsx_elements + +list[ JSXElement [ TSFile ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### named_exports + +list[ TSExport ] } description="Returns the named exports declared in the file." /> + +### node_type + +Literal[NodeType.FILE] } description=" +" /> + +### owners + +set[str] } description="Returns the CODEOWNERS of the file." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### path + +Path } description=" +" /> + +### programming_language + + } description=" +" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### start_byte + +int } description="Returns the starting byte position of a file in its content." /> + +### symbols_sorted_topologically + +list[ Symbol ] } description="Returns all Symbols in the file, sorted topologically (parents first). Robust to" /> + +### ts_config + +TSConfig | None } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### types + +list[ TSTypeAlias ] } description="Returns all type aliases in the file." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_export_to_symbol +Adds an export keyword to a symbol in a TypeScript file. + + + +TSSymbol } + description="The TypeScript symbol (function, class, interface, etc.) to be exported." + defaultValue="" +/> + + + +None } description=""/> + + +### add_import_from_import_string +Adds import to the file from a string representation of an import statement. + + + +str } + description="The string representation of the import statement to add." + defaultValue="" +/> + + + +None } description=""/> + + +### add_symbol_from_source +Adds a symbol to a file from a string representation. + + + +str } + description="String representation of the symbol to be added. This should be valid source code for" + defaultValue="" +/> + + + +None } description="The symbol is added directly to the file's content."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_by_byte_range +Finds all editable objects that overlap with the given byte range in the file. + + + +Range } + description="The byte range to search within the file." + defaultValue="" +/> + + + +list[ Editable ] } description="A list of all Editable objects that overlap with the given range."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSFile ] } description=""/> + + +### get_class +Returns a specific Class by full name. Returns None if not found. + + + +str } + description="The full name of the class to search for." + defaultValue="" +/> + + + +Class | None } description="The matching Class object if found, None otherwise."/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSFile ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_config +Returns the nearest tsconfig.json applicable to this file. + + + +TSConfig | None } description="The TypeScript configuration object if found, None otherwise."/> + + +### get_export +Returns an export object with the specified name from the file. + + + +str } + description="The name of the export to find." + defaultValue="" +/> + + + +TSExport | None } description="The export object if found, None otherwise."/> + + +### get_export_statement_for_path +Gets the first export of specified type that contains the given path in single or double quotes. + + + +str } + description="The path to check for in export statements" + defaultValue="" +/> +str } + description="Type of export to get - "WILDCARD", "TYPE", or "EXPORT" (default)" + defaultValue=""EXPORT"" +/> + + + +ExportStatement | None } description="The first matching export if found, None otherwise."/> + + +### get_extensions +Returns a list of file extensions that this class can parse. + + + +list[str] } description="A list of file extensions including '.tsx', '.ts', '.jsx', and '.js'."/> + + +### get_function +Returns a specific Function by name. + + + +str } + description="The name of the function to find." + defaultValue="" +/> + + + +Function | None } description="The matching Function object if found, None otherwise."/> + + +### get_global_var +Returns a specific global var by name. Returns None if not found. + + + +str } + description="The name of the global variable to find." + defaultValue="" +/> + + + +Assignment | None } description="The global variable if found, None otherwise."/> + + +### get_import +Returns the import with matching alias. Returns None if not found. + + + +str } + description="The alias name to search for. This can match either the direct import name or the aliased name." + defaultValue="" +/> + + + +Import | None } description="The import statement with the matching alias if found, None otherwise."/> + + +### get_import_string +Generates and returns an import statement for the file. + + + +str | None } + description="Alternative name for the imported module. Defaults to None." + defaultValue="None" +/> +str | None } + description="Module path to import from. If None, uses file's default module name." + defaultValue="None" +/> +ImportType } + description="The type of import statement. Defaults to ImportType.UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string importing all exports from the module."/> + + +### get_interface +Retrieves a specific interface from the file by its name. + + + +str } + description="The name of the interface to find." + defaultValue="" +/> + + + +TSInterface | None } description="The interface with the specified name if found, None otherwise."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_namespace +Returns a specific namespace by name from the file's namespaces. + + + +str } + description="The name of the namespace to find." + defaultValue="" +/> + + + +TSNamespace | None } description="The namespace with the specified name if found, None otherwise."/> + + +### get_symbol +Gets a symbol by its name from the file. + + + +str } + description="The name of the symbol to find." + defaultValue="" +/> + + + +Symbol | None } description="The found symbol, or None if not found."/> + + +### get_type +Returns a specific Type by name from the file's types. + + + +str } + description="The name of the type alias to retrieve." + defaultValue="" +/> + + + +TSTypeAlias | None } description="The TypeScript type alias with the matching name, or None if not found."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### has_export_statement_for_path +Checks if the file has exports of specified type that contains the given path in single or double quotes. + + + +str } + description="The path to check for in export statements" + defaultValue="" +/> +str } + description="Type of export to check for - "WILDCARD", "TYPE", or "EXPORT" (default)" + defaultValue=""EXPORT"" +/> + + + +bool } description="True if there exists an export of specified type with the exact relative path (quoted) in its source, False otherwise."/> + + +### has_import +Returns True if the file has an import with the given alias. + + + +str } + description="The alias to check for in the import statements." + defaultValue="" +/> + + + +bool } description="True if an import with the given alias exists, False otherwise."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes the file from the file system and graph. + + + +None } description=""/> + + +### remove_unused_exports +Removes unused exports from the file. + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_can_be_added +Determines if a TypeScript symbol can be added to this file based on its type and JSX compatibility. + + + +TSSymbol } + description="The TypeScript symbol to be checked." + defaultValue="" +/> + + + +bool } description="True if the symbol can be added to this file, False otherwise."/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### symbols +Returns all Symbols in the file, sorted by position in the file. + + + +list[ Symbol | Class | Function | Assignment | TInterface] } description="A list of all top-level symbols in the file, sorted by their position in the file. Symbols can be one of the following types: - Symbol: Base symbol class - TClass: Class definition - TFunction: Function definition - TGlobalVar: Global variable assignment - TInterface: Interface definition"/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSForLoopStatement.mdx b/docs/api-reference/typescript/TSForLoopStatement.mdx new file mode 100644 index 000000000..f428f9eed --- /dev/null +++ b/docs/api-reference/typescript/TSForLoopStatement.mdx @@ -0,0 +1,565 @@ +--- +title: "TSForLoopStatement" +sidebarTitle: "TSForLoopStatement" +icon: "" +description: "Abstract representation of the for loop in TypeScript. + +Attributes: +item: An item in the iterable object. Only applicable for `for...of` loops. +iterable: The iterable that is being iterated over. Only applicable for `for...of` loops. + +initializer: The counter variable. Applicable for traditional for loops. +condition: The condition for the loop. Applicable for traditional for loops. +increment: The increment expression. Applicable for traditional for loops. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [ForLoopStatement](/api-reference/core/ForLoopStatement), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### condition + +Expression [ TSForLoopStatement ] | None } description="The condition for the loop. Applicable for traditional for loops." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Retrieves all function calls within a for loop statement." /> + +### increment + +Expression [ TSForLoopStatement ] | None } description="The increment expression. Applicable for traditional for loops." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### initializer + +Expression [ TSForLoopStatement ] | None } description="The counter variable. Applicable for traditional for loops." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_for_in_loop + +bool } description="Determines whether the current for loop is a `for...in` loop." /> + +### item + +Expression [ TSForLoopStatement ] | None } description="An item in the iterable object. Only applicable for `for...of` loops." /> + +### iterable + +Expression [ TSForLoopStatement ] | None } description="The iterable that is being iterated over. Only applicable for `for...of` loops." /> + +### jsx_elements + +list[ JSXElement [ TSForLoopStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSForLoopStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSForLoopStatement ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSForLoopStatement ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSFunction.mdx b/docs/api-reference/typescript/TSFunction.mdx new file mode 100644 index 000000000..0776c2e37 --- /dev/null +++ b/docs/api-reference/typescript/TSFunction.mdx @@ -0,0 +1,1060 @@ +--- +title: "TSFunction" +sidebarTitle: "TSFunction" +icon: "" +description: "Representation of a Function in JavaScript/TypeScript" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [Function](/api-reference/core/Function), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### call_sites + +list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the function and its parameters." /> + +### function_signature + +str } description="Returns a string representation of the function's signature." /> + +### function_type + +TSFunctionTypeNames } description="Gets the type of function from its TreeSitter node." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### inferred_return_type + +str | None } description="Gets the inferred type of the function from the language's native language engine / compiler." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_anonymous + +bool } description="Property indicating whether a function is anonymous." /> + +### is_arrow + +bool } description="Returns True iff the function is an arrow function." /> + +### is_async + +bool } description="Determines if the function is asynchronous." /> + +### is_constructor + +bool } description="Determines if the current function is a constructor method." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_jsx + +bool } description="Determines if the function is a React component by checking if it returns a JSX element." /> + +### is_magic + +bool } description="Returns whether this method is a magic method." /> + +### is_method + +bool } description="Returns whether the function is a method of a class." /> + +### is_overload + +bool } description="Indicates whether the function is an overloaded function in a multi-function definition." /> + +### is_private + +bool } description="Determines if a function is private based on its accessibility modifier." /> + +### is_property + +bool } description="Determines if the function is a property." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### jsx_elements + +list[ JSXElement [ TSFunction ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_functions + +list[ Function ] } description="Returns a list of nested functions defined within this function's code block." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parameters + +SymbolGroup [ Parameter , TSFunction ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_statements + +list[ ReturnStatement ] } description="Returns a list of all return statements within this function's body." /> + +### return_type + +Type | Placeholder[ ExternalModule ] } description=" +" /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### add_statements +Adds statements to the end of a function body. + + + +str } + description="The lines of code to be added at the end of the function body." + defaultValue="" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### arrow_to_named +Converts an arrow function to a named function in TypeScript/JavaScript. + + + +str | None } + description="The name for the converted function. If None, uses the name of the variable" + defaultValue="None" +/> + + + +None } description=""/> + + +### asyncify +Modifies the function to be asynchronous, if it is not already. + + + +None } description=""/> + + +### convert_props_to_interface +Converts React component props to TypeScript interfaces. + + + +None } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSFunction ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSFunction ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_parameter +Gets a specific parameter from the callable's parameters list by name. + + + +str } + description="The name of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> + + +### get_parameter_by_index +Returns the parameter at the given index. + + + +int } + description="The index of the parameter to retrieve." + defaultValue="" +/> + + + +Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> + + +### get_parameter_by_type +Retrieves a parameter from the callable by its type. + + + +Symbol } + description="The type to search for." + defaultValue="" +/> + + + +Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_valid_node +Determines if a given tree-sitter node corresponds to a valid function type. + + + +TSNode } + description="The tree-sitter node to validate." + defaultValue="" +/> + + + +bool } description="True if the node's type is a valid function type, False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### prepend_statements +Prepends the provided code to the beginning of the function body. + + + +str } + description="The code to be prepended to the function body." + defaultValue="" +/> + + + +None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename_local_variable +Renames a local variable and all its usages within a function body. + + + +str } + description="The current name of the local variable to be renamed." + defaultValue="" +/> +str } + description="The new name to give to the local variable." + defaultValue="" +/> +bool, optional } + description="If True, matches variable names that contain old_var_name. Defaults to False." + defaultValue="False" +/> + + + +None } description="The method modifies the AST in place."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text as a comment." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the comment format before inserting." + defaultValue="True" +/> +TSNode | None, optional } + description="The specific node to attach the comment to." + defaultValue="None" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_return_type +Sets the return type annotation for the function. + + + +str } + description="The new return type annotation to be set. Use an empty string to remove" + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSFunctionType.mdx b/docs/api-reference/typescript/TSFunctionType.mdx new file mode 100644 index 000000000..e5fcf922a --- /dev/null +++ b/docs/api-reference/typescript/TSFunctionType.mdx @@ -0,0 +1,441 @@ +--- +title: "TSFunctionType" +sidebarTitle: "TSFunctionType" +icon: "" +description: "Function type definition. + +Attributes: +return_type: Return type of the function. + +Examples: +a: (a: number) => number +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +None } description=" +" /> + +### node_type + +NodeType } description=" +" /> + +### parameters + +Collection[ TSParameter , TSFunctionType ] } description="Retrieves the parameters of a function type." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### return_type + +TSType[ TSFunctionType ] | TSReturnTypePlaceholder [ TSFunctionType ] } description="Return type of the function." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### asyncify +Modifies the function type to be asynchronous by wrapping its return type in a Promise. + + + +None } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSFunctionType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSGenericType.mdx b/docs/api-reference/typescript/TSGenericType.mdx new file mode 100644 index 000000000..42452c7a7 --- /dev/null +++ b/docs/api-reference/typescript/TSGenericType.mdx @@ -0,0 +1,471 @@ +--- +title: "TSGenericType" +sidebarTitle: "TSGenericType" +icon: "" +description: "Generic type + +Examples: +`Array` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[GenericType](/api-reference/core/GenericType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parameters + +Collection[ Type , TSGenericType ] } description="Retrieves the generic type parameters associated with this type." /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSGenericType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSHasBlock.mdx b/docs/api-reference/typescript/TSHasBlock.mdx new file mode 100644 index 000000000..4de6b8777 --- /dev/null +++ b/docs/api-reference/typescript/TSHasBlock.mdx @@ -0,0 +1,520 @@ +--- +title: "TSHasBlock" +sidebarTitle: "TSHasBlock" +icon: "" +description: "A TypeScript base class that provides block-level code organization and decorator handling capabilities. + +This class extends the concept of block scoping for TypeScript code elements like classes and functions. +It provides functionality for managing code blocks, decorators, JSX elements, and documentation within +those blocks. The class supports operations such as retrieving and manipulating docstrings, +handling JSX components, and managing TypeScript decorators. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description="The code block that may trigger an exception" /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### jsx_elements + +list[ JSXElement [ TSHasBlock ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSHasBlock ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSHasBlock ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSIfBlockStatement.mdx b/docs/api-reference/typescript/TSIfBlockStatement.mdx new file mode 100644 index 000000000..d32c53741 --- /dev/null +++ b/docs/api-reference/typescript/TSIfBlockStatement.mdx @@ -0,0 +1,485 @@ +--- +title: "TSIfBlockStatement" +sidebarTitle: "TSIfBlockStatement" +icon: "" +description: "Typescript implementation of the if/elif/else statement block. +For example, if there is a code block like: +if (condition1) { +block1 +} else if (condition2) { +block2 +} else { +block3 +} +This class represents the entire block, including the conditions and nested code blocks. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[IfBlockStatement](/api-reference/core/IfBlockStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### alternative_blocks + +list[ IfBlockStatement ] } description="Returns a list of alternative if/elif/else blocks for the current block." /> + +### condition + +Expression [ PyIfBlockStatement ] | None } description="The condition expression for the if block. None if the block is an else block." /> + +### consequence_block + +CodeBlock } description="The code block that is executed if the condition is True." /> + +### else_statement + +IfBlockStatement | None } description="Returns the else block within the if-statement." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the if block statement and its alternative blocks." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_elif_statement + +bool } description="Determines if the current block is an elif block." /> + +### is_else_statement + +bool } description="Determines if the current block is an else block." /> + +### is_if_statement + +bool } description="Determines if the current block is a standalone 'if' statement." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested code blocks within an if/elif/else statement block." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSIfBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### elif_statements +Returns all elif blocks within the if block. + + + +list[ IfBlockStatement ] } description="A list of elif block statements. Empty list if no elif blocks exist."/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSIfBlockStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a conditional block by reducing its condition to a boolean value. + + + +bool } + description="The boolean value to reduce the condition to." + defaultValue="" +/> + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSImport.mdx b/docs/api-reference/typescript/TSImport.mdx new file mode 100644 index 000000000..004f48c3b --- /dev/null +++ b/docs/api-reference/typescript/TSImport.mdx @@ -0,0 +1,739 @@ +--- +title: "TSImport" +sidebarTitle: "TSImport" +icon: "" +description: "Extends Import for TypeScript codebases." +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Exportable](/api-reference/core/Exportable), [Import](/api-reference/core/Import), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) + +## Attributes + +### alias + +Editable | None } description=" +" /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### from_file + +SourceFile | None } description="Returns the SourceFile that an Import is importing from." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### import_specifier + +Editable } description="Retrieves the import specifier node for this import." /> + +### import_statement + +ImportStatement } description="the ImportStatement that this import belongs to" /> + +### import_type + +ImportType } description=" +" /> + +### imported_exports + +list[ Exportable ] } description="Returns the enumerated list of exports imported from a module import." /> + +### imported_symbol + +Symbol | ExternalModule | SourceFile | Import | None } description="Returns the symbol directly being imported, including an indirect import and an External" /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### module + +Editable | None } description=" +" /> + +### name + +str | None } description="Returns the name or alias of the symbol being imported." /> + +### namespace + +str | None } description="If import is a module import, returns any namespace prefix that must be used with import reference." /> + +### node_type + +Literal[NodeType.IMPORT] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_symbol + +Symbol | ExternalModule | TSFile | None } description="Returns the resolved symbol that the import is referencing." /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### symbol_name + +Editable | None } description="The name of the symbol being imported. For instance import a as b has a symbol_name of a." /> + +### to_file + +SourceFile } description="SourceFile that this import resides in." /> + +### to_file_id + +NodeId } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSImport ] } description=""/> + + +### get_import_string +Generates an import string for an import statement. + + + +str | None } + description="Alias name for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None } + description="Module name to import from. Defaults to None. If not provided, uses the file's import module name." + defaultValue="None" +/> +ImportType } + description="Type of import (e.g. WILDCARD, NAMED_EXPORT). Defaults to ImportType.UNKNOWN." + defaultValue="ImportType.UNKNOWN" +/> +bool } + description="Whether this is a type import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A string representation of the import statement."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_aliased_import +Returns True if this import is aliased. + + + +bool } description="True if the import has an alias different from its original name, False otherwise."/> + + +### is_default_import +Determines whether the import is a default export import. + + + +TSImport } + description="The import instance." + defaultValue="" +/> + + + +bool } description="True if the import is a default export import, False otherwise."/> + + +### is_module_import +Determines if an import represents a module-level import. + + + +TSImport } + description="The import object to check." + defaultValue="" +/> + + + +bool } description="True if the import is a module-level import, False otherwise. Returns True for: - Imports of type MODULE, WILDCARD, or DEFAULT_EXPORT - Side effect imports that are not type imports"/> + + +### is_reexport +Returns true if the Import object is also an Export object. + + + +bool } description="True if the import is re-exported, False otherwise."/> + + +### is_symbol_import +Returns True if this import is importing a symbol rather than a module. + + + +bool } description="True if this import is a symbol import, False if it is a module import."/> + + +### is_type_import +Checks if an import is a type import. + + + +bool } description="True if the import is a type import, False otherwise."/> + + +### is_wildcard_import +Returns True if the import symbol is a wildcard import. + + + +bool } description="True if this is a wildcard import, False otherwise."/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Remove this import from the import statement. + + + +bool, optional } + description="Whether to delete any associated formatting. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of the operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate imports. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Renames the import symbol and updates all its usages throughout the codebase. + + + +str } + description="The new name to give the imported symbol." + defaultValue="" +/> +int, optional } + description="Priority of the rename operation. Defaults to 0." + defaultValue="0" +/> + + + +tuple[NodeId, NodeId] } description="A tuple containing (file_node_id, new_import_node_id)."/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### resolve_import +Resolves an import statement to its target file and symbol. + + + +str | None } + description="The base path to resolve imports from. If None, uses the codebase's base path" + defaultValue="None" +/> + + + +ImportResolution[ TSFile ] | None } description="An ImportResolution object containing the resolved file and symbol, or None if the import could not be resolved (treated as an external module). The ImportResolution contains: - from_file: The file being imported from - symbol: The specific symbol being imported (None for module imports) - imports_file: True if importing the entire file/module"/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_import_module +Sets the module of an import. + + + +str } + description="The new module path to import from." + defaultValue="" +/> + + + +None } description=""/> + + +### set_import_symbol_alias +Sets alias or name of an import at the declaration level. + + + +str } + description="The new name to use for the imported symbol." + defaultValue="" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSImportStatement.mdx b/docs/api-reference/typescript/TSImportStatement.mdx new file mode 100644 index 000000000..6b23f29cf --- /dev/null +++ b/docs/api-reference/typescript/TSImportStatement.mdx @@ -0,0 +1,443 @@ +--- +title: "TSImportStatement" +sidebarTitle: "TSImportStatement" +icon: "" +description: "A class representing an import statement in TypeScript, managing both static and dynamic imports. + +This class handles various types of TypeScript imports including regular import statements, +dynamic imports, and export statements. It provides functionality to manage and track imports +within a TypeScript file, enabling operations like analyzing dependencies, moving imports, +and modifying import statements. + +Attributes: +imports (Collection): A collection of TypeScript imports contained within the statement. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[ImportStatement](/api-reference/core/ImportStatement), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### imports + +Collection[ Import , PyImportStatement ] } description="A collection of the individual imports this statement represents" /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSImportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSImportStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSInterface.mdx b/docs/api-reference/typescript/TSInterface.mdx new file mode 100644 index 000000000..bf8a0e53d --- /dev/null +++ b/docs/api-reference/typescript/TSInterface.mdx @@ -0,0 +1,843 @@ +--- +title: "TSInterface" +sidebarTitle: "TSInterface" +icon: "" +description: "Representation of an Interface in TypeScript + +Attributes: +parent_interfaces: All the interfaces that this interface extends. +code_block: The code block that contains the interface's body. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### attributes + +list[ TSAttribute ] } description="Retrieves the list of attributes defined in the TypeScript interface." /> + +### code_block + +CodeBlock } description="The code block that contains the interface's body." /> + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### jsx_elements + +list[ JSXElement [ TSInterface ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_interfaces + +Parents[ Type , TSInterface ] | None } description="All the interfaces that this interface extends." /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### extends +Returns True if the interface implements the given parent interface. + + + +bool } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSInterface ] } description=""/> + + +### get_attribute +Returns the attribute with the given name, if it exists. + + + +Attribute | None } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSInterface ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### implementations +Returns all classes and interfaces that implement a given interface. + + + +list[Interface | Class ] } description=""/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text as a comment." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the comment format before inserting." + defaultValue="True" +/> +TSNode | None, optional } + description="The specific node to attach the comment to." + defaultValue="None" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSLabeledStatement.mdx b/docs/api-reference/typescript/TSLabeledStatement.mdx new file mode 100644 index 000000000..2f1ae6a52 --- /dev/null +++ b/docs/api-reference/typescript/TSLabeledStatement.mdx @@ -0,0 +1,505 @@ +--- +title: "TSLabeledStatement" +sidebarTitle: "TSLabeledStatement" +icon: "" +description: "Statement with a named label. It resolves to various types of statements like loops, switch cases, etc. + +Examples: +``` +outerLoop: for (let i = 0; i < 5; i++) { +innerLoop: for (let j = 0; j < 5; j++) { +if (i === 2 && j === 2) { +break outerLoop; // This will break out of the outer loop +} +console.log(`i: ${i}, j: ${j}`); +} +} +``` +``` +emptyStatement: { pass } +``` +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasName](/api-reference/core/HasName), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### body + +Expression | None } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### label + +str } description="Returns the label of the labeled statement." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### nested_code_blocks + +list[ Editable ] } description="Returns all nested code blocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSLabeledStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSLabeledStatement ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSLookupType.mdx b/docs/api-reference/typescript/TSLookupType.mdx new file mode 100644 index 000000000..b11733bc2 --- /dev/null +++ b/docs/api-reference/typescript/TSLookupType.mdx @@ -0,0 +1,430 @@ +--- +title: "TSLookupType" +sidebarTitle: "TSLookupType" +icon: "" +description: "Type lookup +Examples: +a[\"key\"] +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### lookup + +Expression } description=" +" /> + +### name + +str | None } description="Retrieves the name of the type object." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### type + +TSType[ TSLookupType ] } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSLookupType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSNamedType.mdx b/docs/api-reference/typescript/TSNamedType.mdx new file mode 100644 index 000000000..869907188 --- /dev/null +++ b/docs/api-reference/typescript/TSNamedType.mdx @@ -0,0 +1,466 @@ +--- +title: "TSNamedType" +sidebarTitle: "TSNamedType" +icon: "" +description: "Named type +Examples: +string +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSNamedType ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSNamespace.mdx b/docs/api-reference/typescript/TSNamespace.mdx new file mode 100644 index 000000000..a0c915660 --- /dev/null +++ b/docs/api-reference/typescript/TSNamespace.mdx @@ -0,0 +1,895 @@ +--- +title: "TSNamespace" +sidebarTitle: "TSNamespace" +icon: "" +description: "Representation of a namespace module in TypeScript" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[HasName](/api-reference/core/HasName), [TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable) + +## Attributes + +### classes + +list[ TSClass ] } description="Get all classes defined in this namespace." /> + +### code_block + +TSCodeBlock } description=" +" /> + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### functions + +list[ TSFunction ] } description="Get all functions defined in this namespace." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### jsx_elements + +list[ JSXElement [ TSNamespace ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### symbols + +list[ Symbol ] } description="Returns all symbols defined within this namespace, including nested ones." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSNamespace ] } description=""/> + + +### get_class +Get a class by name from this namespace. + + + +TSClass | None } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSNamespace ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_enum +Get an enum by name from this namespace. + + + +TSEnum | None } description=""/> + + +### get_function +Get a function by name from this namespace. + + + +TSFunction | None } description="The found function, or None if not found"/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_interface +Get an interface by name from this namespace. + + + +TSInterface | None } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_namespace +Get a namespace by name from this namespace. + + + +TSNamespace | None } description="The found namespace, or None if not found"/> + + +### get_nested_namespaces +Get all nested namespaces within this namespace. + + + +list[ TSNamespace ] } description="List of all nested namespace objects"/> + + +### get_symbol +Get a symbol by name from this namespace. + + + +Symbol | None } description="The found symbol, or None if not found"/> + + +### get_type +Get a type alias by name from this namespace. + + + +TSTypeAlias | None } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Sets the name of an object and updates all its usages. + + + +str } + description="The new name to assign to the object." + defaultValue="" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text as a comment." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the comment format before inserting." + defaultValue="True" +/> +TSNode | None, optional } + description="The specific node to attach the comment to." + defaultValue="None" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSObjectType.mdx b/docs/api-reference/typescript/TSObjectType.mdx new file mode 100644 index 000000000..e2cdde7e0 --- /dev/null +++ b/docs/api-reference/typescript/TSObjectType.mdx @@ -0,0 +1,424 @@ +--- +title: "TSObjectType" +sidebarTitle: "TSObjectType" +icon: "" +description: "A class representing a TypeScript object type with type annotations and dependencies. + +A specialized class extending `TSDict` and implementing `Type` for handling TypeScript object type annotations. +This class handles object type definitions including nested type structures and manages their dependencies. +It provides functionality for computing dependencies within the type structure and handling type relationships +in TypeScript code. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [TSDict](/api-reference/typescript/TSDict), [Expression](/api-reference/core/Expression), [Dict](/api-reference/core/Dict), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### unpack + +Unpack [ TSObjectType ] | None } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSObjectType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSPair.mdx b/docs/api-reference/typescript/TSPair.mdx new file mode 100644 index 000000000..889f52065 --- /dev/null +++ b/docs/api-reference/typescript/TSPair.mdx @@ -0,0 +1,452 @@ +--- +title: "TSPair" +sidebarTitle: "TSPair" +icon: "" +description: "A TypeScript pair node that represents key-value pairs in object literals. + +A specialized class extending `Pair` for handling TypeScript key-value pairs, +particularly in object literals. It provides functionality for handling both +regular key-value pairs and shorthand property identifiers, with support for +reducing boolean conditions. + +Attributes: +shorthand (bool): Indicates whether this pair uses shorthand property syntax. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Pair](/api-reference/core/Pair), [HasValue](/api-reference/core/HasValue), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### key + +Expression } description=" +" /> + +### name + +str } description="Returns the source text of the key expression in the pair." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### shorthand + +bool } description="Indicates whether this pair uses shorthand property syntax." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSPair ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSParameter.mdx b/docs/api-reference/typescript/TSParameter.mdx new file mode 100644 index 000000000..c13970ec5 --- /dev/null +++ b/docs/api-reference/typescript/TSParameter.mdx @@ -0,0 +1,589 @@ +--- +title: "TSParameter" +sidebarTitle: "TSParameter" +icon: "" +description: "A class representing a TypeScript function parameter with extensive type analysis capabilities. + +This class provides functionality to inspect and manipulate TypeScript function parameters, +including support for destructured parameters, optional parameters, variadic parameters, +default values, and type annotations. + +Attributes: +type (TSType): The TypeScript type annotation of the parameter. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Parameter](/api-reference/core/Parameter), [HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Typeable](/api-reference/core/Typeable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### default + +str | None } description="Returns the default value of a parameter." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### index + +int } description="Returns the 0-based index of this parameter within its parent function's parameter list." /> + +### is_destructured + +bool } description="Determines if a parameter is part of an object destructuring pattern." /> + +### is_optional + +bool } description="Determines if a parameter is marked as optional in TypeScript." /> + +### is_typed + +bool } description="Indicates if a node has an explicit type annotation." /> + +### is_variadic + +bool } description="Determines if a parameter is variadic (using the rest operator)." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### type + +Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### convert_to_interface +Converts a parameter's inline type definition to an interface. + + + +None } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSParameter ] } description=""/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes the parameter from the function definition and all its call sites. + + + +bool, optional } + description="Whether to delete formatting around the parameter. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority level for the removal operation. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate removal operations. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### rename +Renames a parameter in a function definition and updates all related references. + + + +str } + description="The new name for the parameter." + defaultValue="" +/> +int, optional } + description="The priority of the edit operation. Defaults to 0." + defaultValue="0" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_type_annotation +Sets the type annotation for this parameter. + + + +str } + description="The type annotation to set for the parameter." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSQueryType.mdx b/docs/api-reference/typescript/TSQueryType.mdx new file mode 100644 index 000000000..68633618a --- /dev/null +++ b/docs/api-reference/typescript/TSQueryType.mdx @@ -0,0 +1,426 @@ +--- +title: "TSQueryType" +sidebarTitle: "TSQueryType" +icon: "" +description: "Type query + +Examples: +typeof s +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Returns the name of the query type." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### query + +TSType[ TSQueryType ] } description=" +" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSQueryType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSReadonlyType.mdx b/docs/api-reference/typescript/TSReadonlyType.mdx new file mode 100644 index 000000000..87ab2b774 --- /dev/null +++ b/docs/api-reference/typescript/TSReadonlyType.mdx @@ -0,0 +1,426 @@ +--- +title: "TSReadonlyType" +sidebarTitle: "TSReadonlyType" +icon: "" +description: "Readonly type + +Examples: +readonly s +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### name + +str | None } description="Retrieves the name of the type." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### type + +TSType[ TSReadonlyType ] } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSReadonlyType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSReturnTypePlaceholder.mdx b/docs/api-reference/typescript/TSReturnTypePlaceholder.mdx new file mode 100644 index 000000000..3e33c12db --- /dev/null +++ b/docs/api-reference/typescript/TSReturnTypePlaceholder.mdx @@ -0,0 +1,70 @@ +--- +title: "TSReturnTypePlaceholder" +sidebarTitle: "TSReturnTypePlaceholder" +icon: "" +description: "A placeholder class for function return type annotations in TypeScript. + +This class represents a placeholder for function return type annotations, allowing for modification +and addition of return type annotations after the parameter list. It provides functionality to +add or modify return type annotations with proper formatting. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Placeholder](/api-reference/core/Placeholder) + + +## Methods + +### edit +Modifies the return type annotation of a function. + + + +str } + description="The return type annotation to add. If it doesn't start with ':', a ':' will be prepended." + defaultValue="" +/> +bool, optional } + description="Whether to fix the indentation of the added code. Defaults to False." + defaultValue="False" +/> +int, optional } + description="The priority of this edit. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to remove duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### remove +Removes this element from its parent container. + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSString.mdx b/docs/api-reference/typescript/TSString.mdx new file mode 100644 index 000000000..3de32a01c --- /dev/null +++ b/docs/api-reference/typescript/TSString.mdx @@ -0,0 +1,439 @@ +--- +title: "TSString" +sidebarTitle: "TSString" +icon: "" +description: "A TypeScript string node representing both literal strings and template strings. + +This class handles both regular string literals and template strings in TypeScript, +providing functionality to parse and manage template string expressions. It extends +the base String class with TypeScript-specific capabilities. + +Attributes: +expressions (list): A list of parsed expressions from template string substitutions. +Empty for regular string literals. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[String](/api-reference/core/String), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### content + +str } description="The content of the string" /> + +### content_nodes + +Collection[ Expression [ Editable ], PyString ] } description=" +" /> + +### expressions + +list[ Expression [ Editable ]] } description="embedded expressions in the string, only applicable for templated or formatted strings" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + +### with_quotes + +str } description="Retrieves the string representation with quotation marks." /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSString ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSSwitchCase.mdx b/docs/api-reference/typescript/TSSwitchCase.mdx new file mode 100644 index 000000000..e042246b8 --- /dev/null +++ b/docs/api-reference/typescript/TSSwitchCase.mdx @@ -0,0 +1,544 @@ +--- +title: "TSSwitchCase" +sidebarTitle: "TSSwitchCase" +icon: "" +description: "Typescript switch case. + +Attributes: +default: is this a default case? +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [SwitchCase](/api-reference/core/SwitchCase), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock | None } description=" +" /> + +### condition + +Expression [ PyMatchCase ] | None } description="The condition which triggers this case" /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### default + +bool } description="is this a default case?" /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### jsx_elements + +list[ JSXElement [ TSSwitchCase ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSSwitchCase ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + +StatementType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSSwitchCase ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSSwitchCase ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSSwitchStatement.mdx b/docs/api-reference/typescript/TSSwitchStatement.mdx new file mode 100644 index 000000000..3c6557a48 --- /dev/null +++ b/docs/api-reference/typescript/TSSwitchStatement.mdx @@ -0,0 +1,439 @@ +--- +title: "TSSwitchStatement" +sidebarTitle: "TSSwitchStatement" +icon: "" +description: "Typescript switch statement" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[SwitchStatement](/api-reference/core/SwitchStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### cases + +list[ SwitchCase ] } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the switch statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the switch statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSSwitchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### value + +Expression [ PyMatchStatement ] } description="The value to switch on" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSSwitchStatement ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSSymbol.mdx b/docs/api-reference/typescript/TSSymbol.mdx new file mode 100644 index 000000000..4cb3c1698 --- /dev/null +++ b/docs/api-reference/typescript/TSSymbol.mdx @@ -0,0 +1,709 @@ +--- +title: "TSSymbol" +sidebarTitle: "TSSymbol" +icon: "" +description: "A TypeScript symbol representing a code element with advanced manipulation capabilities. + +This class extends Symbol and Exportable to provide TypeScript-specific functionality for managing +code symbols. It offers methods for handling imports, comments, code refactoring, and file operations +like moving symbols between files while maintaining their dependencies and references. + +The class provides functionality for managing both inline and block comments, setting and retrieving +import strings, and maintaining semicolon presence. It includes capabilities for moving symbols between +files with options to handle dependencies and import strategy selection. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) + +## Attributes + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + +SymbolType } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSSymbol ] } description=""/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text as a comment." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the comment format before inserting." + defaultValue="True" +/> +TSNode | None, optional } + description="The specific node to attach the comment to." + defaultValue="None" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSTernaryExpression.mdx b/docs/api-reference/typescript/TSTernaryExpression.mdx new file mode 100644 index 000000000..bb03710a1 --- /dev/null +++ b/docs/api-reference/typescript/TSTernaryExpression.mdx @@ -0,0 +1,443 @@ +--- +title: "TSTernaryExpression" +sidebarTitle: "TSTernaryExpression" +icon: "" +description: "Any ternary expression in the code where a condition will determine branched execution" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TernaryExpression](/api-reference/core/TernaryExpression), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### alternative + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### condition + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### consequence + +Expression [ PyConditionalExpression ] | None } description=" +" /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSTernaryExpression ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Simplifies a ternary expression based on a boolean condition. + + + +bool } + description="The boolean value to reduce the condition to. If True, keeps the consequence branch. If False, keeps the alternative branch." + defaultValue="" +/> +Editable | None, optional } + description="The node to be edited. Defaults to None." + defaultValue="None" +/> + + + +None } description="Modifies the ternary expression in place."/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSTryCatchStatement.mdx b/docs/api-reference/typescript/TSTryCatchStatement.mdx new file mode 100644 index 000000000..45cfa2578 --- /dev/null +++ b/docs/api-reference/typescript/TSTryCatchStatement.mdx @@ -0,0 +1,544 @@ +--- +title: "TSTryCatchStatement" +sidebarTitle: "TSTryCatchStatement" +icon: "" +description: "Abstract representation of the try/catch/finally block in TypeScript. + +Attributes: +catch: The catch block. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [TryCatchStatement](/api-reference/core/TryCatchStatement), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### catch + +TSCatchStatement [ TSTryCatchStatement ] | None } description="The catch block." /> + +### code_block + +CodeBlock | None } description=" +" /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### finalizer + +BlockStatement | None } description="The code block executed regardless of if an exception is thrown or not" /> + +### function_calls + +list[ FunctionCall ] } description="Gets all function calls within a try-catch-finally statement." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### jsx_elements + +list[ JSXElement [ TSTryCatchStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### nested_code_blocks + +list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSTryCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSTryCatchStatement ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSTryCatchStatement ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/docs/api-reference/typescript/TSTypeAlias.mdx b/docs/api-reference/typescript/TSTypeAlias.mdx new file mode 100644 index 000000000..f8675b5d7 --- /dev/null +++ b/docs/api-reference/typescript/TSTypeAlias.mdx @@ -0,0 +1,849 @@ +--- +title: "TSTypeAlias" +sidebarTitle: "TSTypeAlias" +icon: "" +description: "Representation of an Interface in TypeScript" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSHasBlock](/api-reference/typescript/TSHasBlock), [TypeAlias](/api-reference/core/TypeAlias), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [HasValue](/api-reference/core/HasValue), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) + +## Attributes + +### attributes + +list[ TSAttribute ] } description="Retrieves all attributes belonging to this type alias." /> + +### code_block + +CodeBlock } description=" +" /> + +### comment + +TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### dependencies + +list[Union[ Symbol , Import ]] } description="Returns a list of symbols that this symbol depends on." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### export + +Export | None } description="Returns the export object that exports this symbol." /> + +### exported_name + +str | None } description="Retrieves the exported name of a symbol from its file." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_nodes + +list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### full_name + +str | None } description="Returns the full name of the object, including the namespace path." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> + +### has_semicolon + +bool } description="Checks whether the current symbol has a semicolon at the end." /> + +### inline_comment + +TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### is_exported + +bool } description="Indicates if the symbol is exported from its defining file." /> + +### is_reexported + +bool } description="Determines if the symbol is re-exported from a different file." /> + +### jsx_elements + +list[ JSXElement [ TSTypeAlias ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### name + +str | None } description="Retrieves the base name of the object without namespace prefixes." /> + +### node_type + +Literal[NodeType.SYMBOL] } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### semicolon_node + +Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> + +### source + +str } description="Returns the source code of the symbol." /> + +### symbol_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### type_parameters + +TypeParameters[ Type , TSTypeAlias ] | None } description=" +" /> + +### value + +Expression | None } description="Gets the value node of the object." /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_comment +Adds a new comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool } + description="Whether to automatically format the text into a comment style. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to clean the format of the comment before inserting. Defaults to True." + defaultValue="True" +/> +TSCommentType } + description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this node with new_src. + + + +str } + description="The new source code to replace the current source with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, prevents duplicate edits. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSTypeAlias ] } description=""/> + + +### get_attribute +Retrieves a specific attribute from a TypeScript type alias by its name. + + + +str } + description="The name of the attribute to retrieve." + defaultValue="" +/> + + + +TSAttribute | None } description="The attribute with the specified name if found, None otherwise."/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSTypeAlias ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_import_string +Generates the appropriate import string for a symbol. + + + +str | None, optional } + description="The alias to use for the imported symbol. Defaults to None." + defaultValue="None" +/> +str | None, optional } + description="The module to import from. If None, uses the file's import module name." + defaultValue="None" +/> +ImportType, optional } + description="The type of import to generate (e.g., WILDCARD). Defaults to" + defaultValue="ImportType.UNKNOWN" +/> +bool, optional } + description="Whether this is a type-only import. Defaults to False." + defaultValue="False" +/> + + + +str } description="A formatted import statement string."/> + + +### get_name +Returns the name node of the object. + + + +Name | ChainedAttribute | None } description="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."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before the current symbol node in the Abstract Syntax Tree. + + + +str } + description="The source code text to insert." + defaultValue="" +/> +bool } + description="Whether to adjust the indentation of new_src to match current text. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after insertion. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to remove duplicate insertions. Defaults to True." + defaultValue="True" +/> +bool } + description="Whether to insert before extended nodes like comments and decorators. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### move_to_file +Moves the given symbol to a new file and updates its imports and references. + + + +SourceFile } + description="The destination file to move the symbol to." + defaultValue="" +/> +bool } + description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." + defaultValue="True" +/> +str } + description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." + defaultValue=""update_all_imports"" +/> + + + +None } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_comment +Sets a comment to the symbol. + + + +str } + description="The comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a comment syntax." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the format of the comment before inserting." + defaultValue="True" +/> +TSCommentType , optional } + description="The style of comment to add." + defaultValue="TSCommentType.DOUBLE_SLASH" +/> + + + +None } description=""/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + +### set_inline_comment +Sets an inline comment to the symbol. + + + +str } + description="The inline comment text to be added." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text as a comment." + defaultValue="True" +/> +bool, optional } + description="Whether to clean the comment format before inserting." + defaultValue="True" +/> +TSNode | None, optional } + description="The specific node to attach the comment to." + defaultValue="None" +/> + + + +None } description=""/> + + +### set_name +Sets the name of a code element. + + + +str } + description="The new name to set for the object." + defaultValue="" +/> + + + +None } description=""/> + + +### set_value +Sets the value of the node's value Expression. + + + +str } + description="The new value to set." + defaultValue="" +/> + + + +None } description=""/> + + +### symbol_usages +Returns a list of symbols that use or import the exportable object. + + + +UsageType | None } + description="The types of usages to search for. Defaults to any." + defaultValue="None" +/> + + + +list[ Import | Symbol | Export ] } description="A list of symbols that use or import the exportable object."/> + + +### usages +Returns a list of usages of the exportable object. + + + +UsageType | None } + description="Specifies which types of usages to include in the results. Default is any usages." + defaultValue="None" +/> + + + +list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> + + + diff --git a/docs/api-reference/typescript/TSUndefinedType.mdx b/docs/api-reference/typescript/TSUndefinedType.mdx new file mode 100644 index 000000000..61c41cf5b --- /dev/null +++ b/docs/api-reference/typescript/TSUndefinedType.mdx @@ -0,0 +1,416 @@ +--- +title: "TSUndefinedType" +sidebarTitle: "TSUndefinedType" +icon: "" +description: "Undefined type. Represents the undefined keyword +Examples: +undefined +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSUndefinedType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + + diff --git a/docs/api-reference/typescript/TSUnionType.mdx b/docs/api-reference/typescript/TSUnionType.mdx new file mode 100644 index 000000000..96ac925c4 --- /dev/null +++ b/docs/api-reference/typescript/TSUnionType.mdx @@ -0,0 +1,400 @@ +--- +title: "TSUnionType" +sidebarTitle: "TSUnionType" +icon: "" +description: "Union type + +Examples: +string | number +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[UnionType](/api-reference/core/UnionType), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) + +## Attributes + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> + +### next_named_sibling + +Editable | None } description="Returns the next named sibling of the last symbol in the group." /> + +### next_sibling + +Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Get the source code content of the node." /> + +### symbols + +list[ Editable ] } description="Returns the list of symbols in the group." /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Edit the source for this Collection instance. + + + +None } description=""/> + + +### find +Search for substrings in the given symbols that match `strings_to_match`. + + + +list[str] | str } + description="The string or list of strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes that exactly match the query." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing each match found."/> + + +### find_string_literals +Search for string literals matching given strings in the SymbolGroup. + + + +list[str] } + description="List of strings to search for in string literals." + defaultValue="" +/> +bool, optional } + description="If True, performs fuzzy matching instead of exact matching." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSUnionType ] } description=""/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### index +Return the index of the first occurrence of value. + + + +int } description=""/> + + +### insert +Adds `value` to the container that this node represents + + + +None } description=""/> + + +### insert_after +Inserts source code after this node in the codebase. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Adjust indentation to match current text." + defaultValue="False" +/> +bool, optional } + description="Add a newline before the inserted code." + defaultValue="True" +/> +int, optional } + description="Priority of the edit operation." + defaultValue="0" +/> +bool, optional } + description="Deduplicate identical edits." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts source code before this symbol group. + + + +str } + description="The source code to insert." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline after the inserted code. Defaults to True." + defaultValue="True" +/> +int, optional } + description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to prevent duplicate insertions of the same code. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Removes an element from a Collection. + + + +Editable | None } + description="The element to remove from the Collection. If None, delegates to parent class." + defaultValue="" +/> + + + +None } description="This method doesn't return anything."/> + + +### replace +Replaces all instances of a string with a new string in all symbols within the group. + + + +str } + description="The string to be replaced." + defaultValue="" +/> +str } + description="The string to replace with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="Number of replacements made."/> + + +### search +Searches for regex matches in the codebase. + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool, optional } + description="Whether to include string literals in the search. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to include comments in the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> + + + diff --git a/docs/api-reference/typescript/TSWhileStatement.mdx b/docs/api-reference/typescript/TSWhileStatement.mdx new file mode 100644 index 000000000..cc067e7cb --- /dev/null +++ b/docs/api-reference/typescript/TSWhileStatement.mdx @@ -0,0 +1,544 @@ +--- +title: "TSWhileStatement" +sidebarTitle: "TSWhileStatement" +icon: "" +description: "A TypeScript while statement class that represents while loops and manages their condition and code block. + +This class provides functionality for handling while statements in TypeScript code, +including managing the loop's condition and associated code block. It extends the base +WhileStatement class with TypeScript-specific behavior. + +Attributes: +condition (str | None): The condition expression of the while loop. +" +--- +import {Parameter} from '/snippets/Parameter.mdx'; +import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; +import {Return} from '/snippets/Return.mdx'; +import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; +import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; +import {Attribute} from '/snippets/Attribute.mdx'; + + + +### Inherits from +[TSHasBlock](/api-reference/typescript/TSHasBlock), [WhileStatement](/api-reference/core/WhileStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) + +## Attributes + +### code_block + +CodeBlock } description=" +" /> + +### condition + +Expression [ TSWhileStatement ] } description="The condition expression of the while loop." /> + +### decorators + +list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> + +### docstring + +TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> + +### extended + +SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> + +### extended_source + +str } description="Returns the source text representation of all extended nodes." /> + +### file + +SourceFile } description="The file object that this Editable instance belongs to." /> + +### file_node_id + +NodeId } description=" +" /> + +### filepath + +str } description="The file path of the file that this Editable instance belongs to." /> + +### function_calls + +list[ FunctionCall ] } description="Returns all function calls within the while statement block." /> + +### index + +int } description="The 0-based index of the statement in the parent code block." /> + +### is_decorated + +bool } description="Checks if the current symbol has a decorator." /> + +### jsx_elements + +list[ JSXElement [ TSWhileStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> + +### nested_code_blocks + +list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> + +### nested_statements + +list[ MultiLineCollection [ Statement [ TSWhileStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> + +### node_type + +NodeType } description=" +" /> + +### parent + +Editable } description=" +" /> + +### parent_class + +Class | None } description="Find the class this node is contained in" /> + +### parent_function + +Function | None } description="Find the function this node is contained in" /> + +### parent_statement + +Statement | None } description="Find the statement this node is contained in" /> + +### resolved_value + +Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> + +### source + +str } description="Text representation of the Editable instance." /> + +### statement_type + + } description=" +" /> + +### ts_node + +TSNode } description=" +" /> + +### variable_usages + +list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> + + +## Methods + +### add_decorator +Adds a decorator to a function or method. + + + +str } + description="The decorator to add, including the '@' symbol." + defaultValue="" +/> +bool, optional } + description="If True, skips adding if the decorator exists." + defaultValue="False" +/> + + + +bool } description="True if the decorator was added, False if skipped."/> + + +### ancestors +Find all ancestors of the node of the given type. Does not return itself + + + +list[ Editable ] } description=""/> + + +### edit +Replace the source of this `Editable` with `new_src`. + + + +str } + description="The new source text to replace the current text with." + defaultValue="" +/> +bool } + description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." + defaultValue="False" +/> +int } + description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." + defaultValue="0" +/> +bool } + description="If True, deduplicates identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### find +Find and return matching nodes or substrings within an Editable instance. + + + +Union[list[str], str] } + description="One or more strings to search for." + defaultValue="" +/> +bool } + description="If True, only return nodes whose source exactly matches one of the strings_to_match." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable instances that match the search criteria."/> + + +### find_string_literals +Returns a list of string literals within this node's source that match any of the given + + + +list[str] } + description="A list of strings to search for in string literals." + defaultValue="" +/> +bool } + description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="A list of Editable objects representing the matching string literals."/> + + +### flag +Adds a visual flag comment to the end of this Editable's source text. + + + +CodeFlag[ TSWhileStatement ] } description=""/> + + +### get_component +Returns a specific JSX element from within this symbol's JSX elements. + + + +str } + description="The name of the JSX component to find." + defaultValue="" +/> + + + +JSXElement [ TSWhileStatement ] | None } description="The matching JSX element if found, None otherwise."/> + + +### get_variable_usages +Returns Editables for all TreeSitter nodes corresponding to instances of variable usage + + + +str } + description="The variable name to search for." + defaultValue="" +/> +bool } + description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." + defaultValue="False" +/> + + + +list[ Editable ] } description="List of Editable objects representing variable usage nodes matching the given name."/> + + +### insert_after +Inserts code after this node. + + + +str } + description="The source code to insert after this node." + defaultValue="" +/> +bool, optional } + description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool, optional } + description="Whether to add a newline before the new_src. Defaults to True." + defaultValue="True" +/> +int, optional } + description="Priority of the insertion transaction. Defaults to 0." + defaultValue="0" +/> +bool, optional } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### insert_before +Inserts text before this node's source with optional indentation and newline handling. + + + +str } + description="The text to insert before this node." + defaultValue="" +/> +bool } + description="Whether to fix the indentation of new_src to match the current node. Defaults to False." + defaultValue="False" +/> +bool } + description="Whether to add a newline after new_src. Defaults to True." + defaultValue="True" +/> +int } + description="Transaction priority for managing multiple edits. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate identical transactions. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### is_wrapped_in +Check if this node is contained another node of the given class + + + +bool } description=""/> + + +### parent_of_type +Find the first ancestor of the node of the given type. Does not return itself + + + +Editable | None } description=""/> + + +### reduce_condition +Reduces an editable to the following condition + + + +None } description=""/> + + +### remove +Deletes this Node and its related extended nodes (e.g. decorators, comments). + + + +bool } + description="Whether to delete surrounding whitespace and formatting. Defaults to True." + defaultValue="True" +/> +int } + description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." + defaultValue="0" +/> +bool } + description="Whether to deduplicate removal transactions at the same location. Defaults to True." + defaultValue="True" +/> + + + +None } description=""/> + + +### replace +Search and replace occurrences of text within this node's source and its extended nodes. + + + +str } + description="The text or pattern to search for." + defaultValue="" +/> +str } + description="The text to replace matches with." + defaultValue="" +/> +int, optional } + description="Maximum number of replacements to make. Defaults to -1 (replace all)." + defaultValue="-1" +/> +bool, optional } + description="Whether to treat 'old' as a regex pattern. Defaults to False." + defaultValue="False" +/> +int, optional } + description="Priority of the replacement operation. Defaults to 0." + defaultValue="0" +/> + + + +int } description="The total number of replacements made."/> + + +### search +Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). + + + +str } + description="The regular expression pattern to search for." + defaultValue="" +/> +bool } + description="When False, excludes the contents of string literals from the search. Defaults to True." + defaultValue="True" +/> +bool } + description="When False, excludes the contents of comments from the search. Defaults to True." + defaultValue="True" +/> + + + +list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> + + +### set_docstring +Sets or updates a docstring for a code element. + + + +str } + description="The docstring text to be added or updated." + defaultValue="" +/> +bool, optional } + description="Whether to automatically format the text into a docstring format. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to add leading "*" to each line of the comment block. Defaults to True." + defaultValue="True" +/> +bool, optional } + description="Whether to force single line comments to be multi-line. Defaults to False." + defaultValue="False" +/> + + + +None } description=""/> + + + diff --git a/uv.lock b/uv.lock index 5b7e2988b..ac201ae52 100644 --- a/uv.lock +++ b/uv.lock @@ -419,6 +419,7 @@ dependencies = [ { name = "termcolor" }, { name = "tiktoken" }, { name = "toml" }, + { name = "tqdm" }, { name = "tree-sitter" }, { name = "tree-sitter-javascript" }, { name = "tree-sitter-python" }, @@ -515,6 +516,7 @@ requires-dist = [ { name = "termcolor", specifier = ">=2.4.0" }, { name = "tiktoken", specifier = ">=0.5.1,<1.0.0" }, { name = "toml", specifier = ">=0.10.2" }, + { name = "tqdm", specifier = ">=4.67.1" }, { name = "tree-sitter", specifier = ">=0.23.1" }, { name = "tree-sitter-javascript", specifier = ">=0.23.1" }, { name = "tree-sitter-python", specifier = ">=0.23.4" },