From f30b3cc1e8b371220521ae90d86dfbd617ba8ab7 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Sat, 11 Apr 2026 20:35:50 +0200 Subject: [PATCH] JBRename: add options for renaming in comments and text occurrences, defaults to True --- CHANGELOG.md | 7 +++++-- src/serena/tools/jetbrains_tools.py | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceda84be..3a06de16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,11 @@ Status of the `main` branch. Changes prior to the next official version change will appear here. +* JetBrains: + - `JetBrainsRenameTool` can now also rename occurrences in comments and text. + * Language Servers: - - Fix Dart LSP returning only symbol name as body instead of full method body + - Fix Dart LSP returning only symbol name as body instead of full method body. # 1.1.0 @@ -287,4 +290,4 @@ Fixes: # 2025-04-01 -Initial public version \ No newline at end of file +Initial public version diff --git a/src/serena/tools/jetbrains_tools.py b/src/serena/tools/jetbrains_tools.py index 6db26e0b..a94d5c99 100644 --- a/src/serena/tools/jetbrains_tools.py +++ b/src/serena/tools/jetbrains_tools.py @@ -512,16 +512,33 @@ class JetBrainsRenameTool(Tool, ToolMarkerSymbolicEdit, ToolMarkerOptional): Renames a symbol, file or directory throughout the codebase using the JetBrains backend. """ - def apply(self, relative_path: str, new_name: str, name_path: str | None = None) -> str: + def apply( + self, + relative_path: str, + new_name: str, + name_path: str | None = None, + rename_in_comments: bool = False, + rename_in_text_occurrences: bool = False, + ) -> str: """ Renames a symbol, file or directory throughout the codebase. + Note: renaming in comments/text is on a best-effort basis by the IDE; if the symbol name is non-unique, further + verification is recommended. :param relative_path: if `name_path` is passed, the relative path of the file containing the symbol. Otherwise, the path to the directory or file to rename. :param new_name: the new name :param name_path: the name path of the symbol to rename or None if renaming a file or directory. + :param rename_in_comments: whether to also rename occurrences in comments. Default True. + :param rename_in_text_occurrences: whether to also rename occurrences in text. Default True. :return: a status message """ code_editor = JetBrainsCodeEditor(self.project) - result = code_editor.rename_symbol(name_path=name_path, relative_path=relative_path, new_name=new_name) + result = code_editor.rename_symbol( + name_path=name_path, + relative_path=relative_path, + new_name=new_name, + rename_in_comments=rename_in_comments, + rename_in_text_occurrences=rename_in_text_occurrences, + ) return self._to_json(result)