mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 08:18:36 +00:00
Move flag indicating new project creation into Project representation
This commit is contained in:
1 parent
0def7aaecc
commit
4506c87d99
4 files changed
+7
-8
No files matched your search
+2
-4
@@ -399,7 +399,7 @@ class SerenaAgent:
|
||||
if self._project_activation_callback is not None:
|
||||
self._project_activation_callback()
|
||||
|
||||
def activate_project_from_path_or_name(self, project_root_or_name: str) -> tuple[Project, bool]:
|
||||
def activate_project_from_path_or_name(self, project_root_or_name: str) -> Project:
|
||||
"""
|
||||
Activate a project from a path or a name.
|
||||
If the project was already registered, it will just be activated. If it was not registered,
|
||||
@@ -409,7 +409,6 @@ class SerenaAgent:
|
||||
:return: a tuple of the project instance and a Boolean indicating whether the project was newly
|
||||
created
|
||||
"""
|
||||
new_project_generated = False
|
||||
project_instance: Project | None = self.serena_config.get_project(project_root_or_name)
|
||||
if project_instance is not None:
|
||||
log.info(f"Found registered project {project_instance.project_name} at path {project_instance.project_root}.")
|
||||
@@ -420,10 +419,9 @@ class SerenaAgent:
|
||||
f"Existing project names: {self.serena_config.project_names}"
|
||||
)
|
||||
project_instance = self.serena_config.add_project_from_path(project_root_or_name)
|
||||
new_project_generated = True
|
||||
log.info(f"Added new project {project_instance.project_name} for path {project_instance.project_root}.")
|
||||
self._activate_project(project_instance)
|
||||
return project_instance, new_project_generated
|
||||
return project_instance
|
||||
|
||||
def get_active_tool_classes(self) -> list[type["Tool"]]:
|
||||
"""
|
||||
|
||||
@@ -462,7 +462,7 @@ class SerenaConfig(ToolInclusionDefinition, ToStringMixin):
|
||||
|
||||
project_config = ProjectConfig.load(project_root, autogenerate=True)
|
||||
|
||||
new_project = Project(project_root=str(project_root), project_config=project_config)
|
||||
new_project = Project(project_root=str(project_root), project_config=project_config, is_newly_created=True)
|
||||
self.projects.append(new_project)
|
||||
self.save()
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Project:
|
||||
def __init__(self, project_root: str, project_config: ProjectConfig):
|
||||
def __init__(self, project_root: str, project_config: ProjectConfig, is_newly_created: bool = False):
|
||||
self.project_root = project_root
|
||||
self.project_config = project_config
|
||||
self.is_newly_created = is_newly_created
|
||||
|
||||
# gather ignored paths from the project configuration and gitignore files
|
||||
ignored_patterns = project_config.ignored_paths
|
||||
|
||||
@@ -15,8 +15,8 @@ class ActivateProjectTool(Tool, ToolMarkerDoesNotRequireActiveProject):
|
||||
|
||||
:param project: the name of a registered project to activate or a path to a project directory
|
||||
"""
|
||||
active_project, new_project_generated = self.agent.activate_project_from_path_or_name(project)
|
||||
if new_project_generated:
|
||||
active_project = self.agent.activate_project_from_path_or_name(project)
|
||||
if active_project.is_newly_created:
|
||||
result_str = (
|
||||
f"Created and activated a new project with name '{active_project.project_name}' at {active_project.project_root}, language: {active_project.project_config.language.value}. "
|
||||
"You can activate this project later by name.\n"
|
||||
|
||||
Reference in new issue
Block a user