From 316357ab91936d44ec02f79c64d8056217c4d8e3 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Mon, 7 Apr 2025 16:47:50 +0200 Subject: [PATCH] Serena: option to use gitignore for ignoring, defaulting to true --- myproject.template.yml | 9 +++++++-- src/serena/agent.py | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/myproject.template.yml b/myproject.template.yml index 907f2311..5aca9627 100644 --- a/myproject.template.yml +++ b/myproject.template.yml @@ -7,8 +7,13 @@ project_root: /path/to/project # * csharp: Requires the presence of a .sln file in the project folder. language: python -# list of directories to ignore: either names (e.g. "temp") or relative paths (e.g. "build/foo") -ignored_dirs: [".git", "temp"] +# whether to use the project's gitignore file to ignore files +ignore_all_files_in_gitignore: true + +# list of additional paths to ignore +# same syntax as gitignore, so you can use * and ** +ignored_paths: [] + # list of tool names to exclude. We recommend not excluding any tools, see the readme for more details. # Below is the complete list of tools for convenience. diff --git a/src/serena/agent.py b/src/serena/agent.py index e84b7c04..c0e8245d 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -47,8 +47,12 @@ class ProjectConfig(ToStringMixin): if project_root is None: project_root = Path(config_dict["project_root"]) self.project_root: str = str(project_root.resolve()) - self.ignored_dirs: list[str] = config_dict.get("ignored_dirs", []) + self.ignored_paths: list[str] = config_dict.get("ignored_paths", []) self.excluded_tools: set[str] = set(config_dict.get("excluded_tools", [])) + self.ignore_all_files_in_gitignore = config_dict.get("ignore_all_files_in_gitignore", True) + + # backwards compatibility + self.ignored_paths.extend(config_dict.get("ignored_dirs", [])) @classmethod def from_yml(cls, yml_path: Path) -> Self: @@ -251,9 +255,14 @@ class SerenaAgent: # instantiate and start the language server assert self.project_config is not None - multilspy_config = MultilspyConfig(code_language=self.project_config.language) + multilspy_config = MultilspyConfig(code_language=self.project_config.language, ignored_paths=self.project_config.ignored_paths) ls_logger = MultilspyLogger() - self.language_server = SyncLanguageServer.create(multilspy_config, ls_logger, self.project_config.project_root) + self.language_server = SyncLanguageServer.create( + multilspy_config, + ls_logger, + self.project_config.project_root, + add_gitignore_content_to_config=self.project_config.ignore_all_files_in_gitignore, + ) self.language_server.start() if not self.language_server.is_running(): raise RuntimeError(f"Failed to start the language server for {self.project_config}") @@ -544,7 +553,7 @@ class ListDirTool(Tool): os.path.join(self.project_root, relative_path), relative_to=self.project_root, recursive=recursive, - ignored_dirs=self.project_config.ignored_dirs, + ignored_dirs=self.project_config.ignored_paths, ) result = json.dumps({"dirs": dirs, "files": files}) return self._limit_length(result, max_answer_chars)