From d606ef573baecd82c068c2209d9640b39b95a9e3 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Mon, 22 Sep 2025 22:33:35 +0200 Subject: [PATCH] ListDirTool: Do not skip ignored paths by default --- src/serena/tools/file_tools.py | 7 ++++--- src/serena/util/file_system.py | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/serena/tools/file_tools.py b/src/serena/tools/file_tools.py index e5b1467a..432e9b9f 100644 --- a/src/serena/tools/file_tools.py +++ b/src/serena/tools/file_tools.py @@ -87,12 +87,13 @@ class ListDirTool(Tool): Lists files and directories in the given directory (optionally with recursion). """ - def apply(self, relative_path: str, recursive: bool, max_answer_chars: int = -1) -> str: + def apply(self, relative_path: str, recursive: bool, skip_ignored_files: bool = False, max_answer_chars: int = -1) -> str: """ Lists all non-gitignored files and directories in the given directory (optionally with recursion). :param relative_path: the relative path to the directory to list; pass "." to scan the project root :param recursive: whether to scan subdirectories recursively + :param skip_ignored_files: whether to skip files and directories that are ignored :param max_answer_chars: if the output is longer than this number of characters, no content will be returned. -1 means the default value from the config will be used. Don't adjust unless there is really no other way to get the content required for the task. @@ -113,8 +114,8 @@ class ListDirTool(Tool): os.path.join(self.get_project_root(), relative_path), relative_to=self.get_project_root(), recursive=recursive, - is_ignored_dir=self.project.is_ignored_path, - is_ignored_file=self.project.is_ignored_path, + is_ignored_dir=self.project.is_ignored_path if skip_ignored_files else None, + is_ignored_file=self.project.is_ignored_path if skip_ignored_files else None, ) result = json.dumps({"dirs": dirs, "files": files}) diff --git a/src/serena/util/file_system.py b/src/serena/util/file_system.py index 15ba3ba3..784fc2cf 100644 --- a/src/serena/util/file_system.py +++ b/src/serena/util/file_system.py @@ -23,8 +23,8 @@ def scan_directory( path: str, recursive: bool = False, relative_to: str | None = None, - is_ignored_dir: Callable[[str], bool] = lambda x: False, - is_ignored_file: Callable[[str], bool] = lambda x: False, + is_ignored_dir: Callable[[str], bool] | None = None, + is_ignored_file: Callable[[str], bool] | None = None, ) -> ScanResult: """ :param path: the path to scan @@ -34,6 +34,11 @@ def scan_directory( :param is_ignored_file: a function with which to determine whether the given file (abs. path) shall be ignored :return: the list of directories and files """ + if is_ignored_file is None: + is_ignored_file = lambda x: False + if is_ignored_dir is None: + is_ignored_dir = lambda x: False + files = [] directories = []