mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 08:15:59 +00:00
ListDirTool: Ignore files that are explicitly ignored by the user's configuration
(but skip the 'is source file' filter of the language server)
This commit is contained in:
1 parent
e3ed9c1067
commit
9e00803387
2 files changed
+8
-4
No files matched your search
+4
-3
@@ -597,15 +597,16 @@ class ListDirTool(Tool):
|
||||
:return: a JSON object with the names of directories and files within the given directory
|
||||
"""
|
||||
|
||||
def is_ignored_dir(abs_path: str):
|
||||
def is_ignored_path(abs_path: str):
|
||||
rel_path = os.path.relpath(abs_path, self.project_root)
|
||||
return self.language_server.is_ignored_path(rel_path)
|
||||
return self.language_server.is_ignored_path(rel_path, ignore_unsupported_files=False)
|
||||
|
||||
dirs, files = scan_directory(
|
||||
os.path.join(self.project_root, relative_path),
|
||||
relative_to=self.project_root,
|
||||
recursive=recursive,
|
||||
is_ignored_dir=is_ignored_dir,
|
||||
is_ignored_dir=is_ignored_path,
|
||||
is_ignored_file=is_ignored_path,
|
||||
)
|
||||
|
||||
result = json.dumps({"dirs": dirs, "files": files})
|
||||
|
||||
@@ -7,12 +7,14 @@ def scan_directory(
|
||||
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,
|
||||
) -> tuple[list[str], list[str]]:
|
||||
"""
|
||||
:param path: the path to scan
|
||||
:param recursive: whether to recursively scan subdirectories
|
||||
:param relative_to: the path to which the results should be relative to; if None, provide absolute paths
|
||||
:param is_ignored_dir: a function with which to determine whether the given directory (abs. path) shall be ignored
|
||||
: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
|
||||
"""
|
||||
files = []
|
||||
@@ -31,7 +33,8 @@ def scan_directory(
|
||||
result_path = entry_path
|
||||
|
||||
if entry.is_file():
|
||||
files.append(result_path)
|
||||
if not is_ignored_file(entry_path):
|
||||
files.append(result_path)
|
||||
elif entry.is_dir():
|
||||
if not is_ignored_dir(entry_path):
|
||||
directories.append(result_path)
|
||||
|
||||
Reference in new issue
Block a user