mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 12:15:10 +00:00
transfer_missing_yaml_comments_by_index: Also transfer source comment if target comment is effectively empty
This commit is contained in:
1 parent
a58a1c2f16
commit
7c7f100d75
1 file changed
+19
-2
+19
-2
@@ -2,7 +2,7 @@ import os
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
from ruamel.yaml import YAML, CommentToken
|
||||
from ruamel.yaml.comments import CommentedMap
|
||||
|
||||
from serena.constants import SERENA_FILE_ENCODING
|
||||
@@ -89,6 +89,23 @@ def transfer_missing_yaml_comments_by_index(source: CommentedMap, target: Commen
|
||||
:param target: the target map, whose comments will be updated
|
||||
:param indices: list of comment indices to transfer
|
||||
"""
|
||||
|
||||
def is_empty(comment_entry: Any) -> bool:
|
||||
if comment_entry is None:
|
||||
return True
|
||||
elif isinstance(comment_entry, list):
|
||||
for item in comment_entry:
|
||||
if isinstance(item, CommentToken):
|
||||
if item.value.strip() != "":
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
elif isinstance(comment_entry, CommentToken):
|
||||
return comment_entry.value.strip() == ""
|
||||
else:
|
||||
return False
|
||||
|
||||
for key in target.keys():
|
||||
if key in source:
|
||||
source_comment = source.ca.items.get(key)
|
||||
@@ -97,7 +114,7 @@ def transfer_missing_yaml_comments_by_index(source: CommentedMap, target: Commen
|
||||
target_comment = target.ca.items.get(key, [None, None, None, None])
|
||||
target.ca.items[key] = target_comment
|
||||
for index in indices:
|
||||
if target_comment[index] is None:
|
||||
if is_empty(target_comment[index]):
|
||||
target_comment[index] = source_comment[index]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user