mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 06:15:43 +00:00
transfer_missing_yaml_comments: Remove obsolete parameter fully_missing_only
This commit is contained in:
1 parent
f0cb06eb4b
commit
754d7e5108
2 files changed
+12
-22
No files matched your search
@@ -786,7 +786,7 @@ class SerenaConfig(ToolInclusionDefinition, ModeSelectionDefinition, ToStringMix
|
||||
# so we apply a conversion, which detects the old style and transforms it.
|
||||
normalise_yaml_comments(commented_yaml, YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING)
|
||||
template_yaml = load_yaml(SERENA_CONFIG_TEMPLATE_FILE, comment_normalisation=YamlCommentNormalisation.LEADING)
|
||||
transfer_missing_yaml_comments(template_yaml, commented_yaml, YamlCommentNormalisation.LEADING, fully_missing_only=False)
|
||||
transfer_missing_yaml_comments(template_yaml, commented_yaml, YamlCommentNormalisation.LEADING)
|
||||
|
||||
save_yaml(self.config_file_path, commented_yaml)
|
||||
|
||||
|
||||
+11
-21
@@ -201,14 +201,11 @@ def yaml_comment_entry_is_empty(comment_entry: Any) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def transfer_missing_yaml_comments_by_index(
|
||||
source: CommentedMap, target: CommentedMap, indices: list[int], fully_missing_only: bool = False
|
||||
) -> None:
|
||||
def transfer_missing_yaml_comments_by_index(source: CommentedMap, target: CommentedMap, indices: list[int]) -> None:
|
||||
"""
|
||||
:param source: the source, from which to transfer missing comments
|
||||
:param target: the target map, whose comments will be updated
|
||||
:param indices: list of comment indices to transfer
|
||||
:param fully_missing_only: if True, only transfer comments for keys that have no comment definition at all (newly added)
|
||||
"""
|
||||
for key in target.keys():
|
||||
if key in source:
|
||||
@@ -216,35 +213,28 @@ def transfer_missing_yaml_comments_by_index(
|
||||
if source_comment is None:
|
||||
continue
|
||||
target_comment = target.ca.items.get(key)
|
||||
if target_comment is None and fully_missing_only:
|
||||
# transfer full comment and we're done
|
||||
target.ca.items[key] = source_comment
|
||||
else:
|
||||
# initialise target comment if needed
|
||||
if target_comment is None:
|
||||
target_comment = [None] * 4
|
||||
target.ca.items[key] = target_comment
|
||||
# transfer missing comments at specified indices
|
||||
for index in indices:
|
||||
if yaml_comment_entry_is_empty(target_comment[index]):
|
||||
target_comment[index] = source_comment[index]
|
||||
# initialise target comment if needed
|
||||
if target_comment is None:
|
||||
target_comment = [None] * 4
|
||||
target.ca.items[key] = target_comment
|
||||
# transfer missing comments at specified indices
|
||||
for index in indices:
|
||||
if yaml_comment_entry_is_empty(target_comment[index]):
|
||||
target_comment[index] = source_comment[index]
|
||||
|
||||
|
||||
def transfer_missing_yaml_comments(
|
||||
source: CommentedMap, target: CommentedMap, comment_normalisation: YamlCommentNormalisation, fully_missing_only: bool = False
|
||||
) -> None:
|
||||
def transfer_missing_yaml_comments(source: CommentedMap, target: CommentedMap, comment_normalisation: YamlCommentNormalisation) -> None:
|
||||
"""
|
||||
Transfers missing comments from source to target YAML.
|
||||
|
||||
:param source: the source, from which to transfer missing comments
|
||||
:param target: the target map, whose comments will be updated.
|
||||
:param comment_normalisation: the comment normalisation to assume; if NONE, no comments are transferred
|
||||
:param fully_missing_only: if True, only transfer comments for keys that have no comment definition at all (newly added)
|
||||
"""
|
||||
match comment_normalisation:
|
||||
case YamlCommentNormalisation.NONE:
|
||||
pass
|
||||
case YamlCommentNormalisation.LEADING | YamlCommentNormalisation.LEADING_WITH_CONVERSION_FROM_TRAILING:
|
||||
transfer_missing_yaml_comments_by_index(source, target, [ITEM_COMMENT_INDEX_BEFORE], fully_missing_only=fully_missing_only)
|
||||
transfer_missing_yaml_comments_by_index(source, target, [ITEM_COMMENT_INDEX_BEFORE])
|
||||
case _:
|
||||
raise ValueError(f"Unhandled comment normalisation: {comment_normalisation}")
|
||||
Reference in new issue
Block a user