Allowed add_language to be issued asynchronously

This commit is contained in:
MischaPanch committed 2025-10-29 16:12:54 +01:00
1 parent 24a79899e8
commit 2c2fcc6a07
2 files changed
+12 -6

No files matched your search

+9 -2
View File
@@ -540,15 +540,22 @@ class SerenaAgent:
ls_specific_settings=self.serena_config.ls_specific_settings,
)
def add_language(self, language: Language) -> None:
def add_language(self, language: Language, wait_for_ls_startup: bool = False) -> None:
"""
Adds a new language to the active project, spawning the respective language server and updating the project configuration.
The addition is scheduled via the agent's task executor and executed synchronously, i.e. the method returns
when the addition is complete.
:param language: the language to add
:param wait_for_ls_startup: whether to wait for the language server to start up before returning (synchronous execution)
or to just issue the addition task and return immediately (asynchronous execution)
"""
self.execute_task(lambda: self.get_active_project_or_raise().add_language(language), name=f"AddLanguage:{language.value}")
task = lambda: self.get_active_project_or_raise().add_language(language)
task_name = f"AddLanguage:{language.value}"
if wait_for_ls_startup:
self.execute_task(task, name=task_name)
else:
self.issue_task(task, name=task_name)
def get_tool(self, tool_class: type[TTool]) -> TTool:
return self._all_tools[tool_class] # type: ignore
+3 -4
View File
@@ -405,6 +405,9 @@ class Project(ToStringMixin):
if language in self.project_config.languages:
log.info(f"Language {language.value} is already present in the project configuration.")
return
# update the project configuration
self.project_config.languages.append(language)
self.save_config()
# start the language server (if the LS manager is active)
if self.language_server_manager is None:
@@ -413,10 +416,6 @@ class Project(ToStringMixin):
log.info("Adding and starting the language server for new language %s ...", language.value)
self.language_server_manager.add_language_server(language)
# update the project configuration
self.project_config.languages.append(language)
self.save_config()
def shutdown(self) -> None:
if self.language_server_manager is not None:
self.language_server_manager.stop_all(save_cache=True)