Better error message on missing language in autogenerated config

Also comment in template
This commit is contained in:
Michael Panchenko committed 2025-05-28 19:06:03 +02:00
1 parent d289ce2f77
commit bcbdf79534
2 files changed
+13 -9

No files matched your search

+7 -9
View File
@@ -24,14 +24,12 @@ gui_log_level: 20
# minimum log level for the GUI log window (10 = debug, 20 = info, 30 = warning, 40 = error)
# Add your list of projects here (which you can switch between using "activate_project").
# Every list item must be a path to the project's root directory (e.g. "/path/to/myproject"), with the
# configuration file being located in "/path/to/myproject/.serena/project.yml", or a dict mapping
# project_name to project_path (to avoid name collisions).
# You can activate a project by its name using the "activate_project" command.
# If the name is not explicitly set, the name of the project will be the name of the directory
# ("myproject" in the example above).
# Note: comments in the block below are not preserved when saving the config file,
# so we recommend to not have any comments directly below the "projects" key.
# The list of registered projects (which you can switch between using "activate_project").
# MANAGED BY SERENA, KEEP AT THE BOTTOM OF THE YAML AND DON'T ADJUST WITHOUT NEED (you may add paths though)
# Whenever a project is activated (either by using the tool or by starting the server with --project),
# the project's path will be added here and you will be able to activate it by its name in the future.
# By default, the project's name will be the name of the directory containing the project, but you may change it
# by changing the entry in the (autogenerated) `.serena/project.yml` file.
# Note: make sure there are no name collisions in the names of registered projects
projects:
- /path/to/myproject
+6
View File
@@ -109,6 +109,12 @@ class ProjectConfig(ToStringMixin):
raise FileNotFoundError(f"Project root not found: {project_root}")
project_name = project_name or project_root.name
language_composition = determine_programming_language_composition(str(project_root))
if len(language_composition) == 0:
raise ValueError(
f"Failed to autogenerate project.yaml: no programming language detected in project {project_root}. "
f"You can either add some files that correspond to one of the supported programming languages, "
f"or create the file {os.path.join(project_root, cls.rel_path_to_project_yml())} manually and specify the language there."
)
# find the language with the highest percentage
dominant_language = max(language_composition.keys(), key=lambda lang: language_composition[lang])
result = cls(