TSCommentGroup
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).
Inherits from
CommentGroup, SymbolGroup, Editable
Attributes
extended
Returns a SymbolGroup of all extended nodes associated with this element.
extended_source
str
Returns the source text representation of all extended nodes.
file
The file object that this Editable instance belongs to.
file_node_id
NodeId
filepath
str
The file path of the file that this Editable instance belongs to.
function_calls
Returns a list of all function calls contained within this expression.
next_named_sibling
Returns the next named sibling of the last symbol in the group.
next_sibling
Returns the next sibling of the last symbol in the symbol group.
node_type
NodeType
parent
parent_class
Find the class this node is contained in
parent_function
Find the function this node is contained in
parent_statement
Find the statement this node is contained in
source
str
Returns the concatenated source code of all symbols in the group.
symbols
Returns the list of symbols in the group.
text
str
Return the text content of all comments in the comment block.
ts_node
TSNode
variable_usages
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
Returns
edit
Replace the source of this node with new text.
Parameters
str
The new source text to replace the current text with.
bool, optional
Adjusts the indentation of new_src to match the current text's indentation. Defaults to False.
int, optional
Priority of the edit operation. Higher priority edits take precedence. Defaults to 0.
bool, optional
Prevents duplicate edits at the same location. Defaults to True.
Returns
None
edit_text
Replace the text content of a comment group with new text.
Parameters
str
The new text content to replace the existing comment text.
Returns
None
find
Search for substrings in the given symbols that match strings_to_match
.
Parameters
list[str] | str
The string or list of strings to search for.
bool
If True, only return nodes that exactly match the query.
Returns
A list of Editable objects representing each match found.
find_string_literals
Search for string literals matching given strings in the SymbolGroup.
Parameters
list[str]
List of strings to search for in string literals.
bool, optional
If True, performs fuzzy matching instead of exact matching.
Returns
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.
Returns
get_variable_usages
Returns Editables for all TreeSitter nodes corresponding to instances of variable usage
Parameters
str
The variable name to search for.
bool
If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False.
Returns
List of Editable objects representing variable usage nodes matching the given name.
insert_after
Inserts source code after this node in the codebase.
Parameters
str
The source code to insert.
bool, optional
Adjust indentation to match current text.
bool, optional
Add a newline before the inserted code.
int, optional
Priority of the edit operation.
bool, optional
Deduplicate identical edits.
Returns
None
insert_before
Inserts source code before this symbol group.
Parameters
str
The source code to insert.
bool, optional
Whether to adjust the indentation of the inserted code to match the current code. Defaults to False.
bool, optional
Whether to add a newline after the inserted code. Defaults to True.
int, optional
The priority of this edit operation. Higher priority edits are applied first. Defaults to 0.
bool, optional
Whether to prevent duplicate insertions of the same code. Defaults to True.
Returns
None
is_wrapped_in
Check if this node is contained another node of the given class
Returns
bool
parent_of_type
Find the first ancestor of the node of the given type. Does not return itself
Returns
reduce_condition
Reduces an editable to the following condition
Returns
None
remove
Removes this node and its related extended nodes from the codebase.
Parameters
bool, optional
Whether to delete related extended nodes like decorators and comments. Defaults to True.
int, optional
Priority level of the removal operation. Defaults to 0.
bool, optional
Whether to deduplicate removal operations. Defaults to True.
Returns
None
replace
Replaces all instances of a string with a new string in all symbols within the group.
Parameters
str
The string to be replaced.
str
The string to replace with.
int, optional
Maximum number of replacements to make. Defaults to -1 (replace all).
int, optional
Priority of the replacement operation. Defaults to 0.
Returns
int
Number of replacements made.
search
Searches for regex matches in the codebase.
Parameters
str
The regular expression pattern to search for.
bool, optional
Whether to include string literals in the search. Defaults to True.
bool, optional
Whether to include comments in the search. Defaults to True.
Returns
A list of Editable objects representing matched text nodes in the codebase.
Was this page helpful?