Skip to content

Commit

Permalink
Merge pull request #34 from hanjinliu/collection-one-of
Browse files Browse the repository at this point in the history
completion of ListOf[EnumOf]
  • Loading branch information
hanjinliu authored Jun 21, 2024
2 parents d532a9e + 244259f commit 57ad730
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/completion/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ def complete_keyword_name_or_value(
type="keyword-value",
keyword_type=cmd_desc._keyword[last_pref],
)
elif is_listof_enumof(last_annot):
last_word = last_word.split(",")[-1]
values = to_list_of_str(
last_annot.annotation.values,
startswith=last_word
)
if len(values) == 1 and last_word == values[0]:
values = []
valid_values = [v for v in values if v.startswith(last_word)]
print(last_word, valid_values)
return CompletionState(
text=last_word,
completions=valid_values,
command=current_command,
info=["<i>enum</i>"] * len(values),
type="keyword-value",
keyword_type=cmd_desc._keyword[last_pref],
)
else:
if (
is_spec(next(iter(cmd_desc._required.values()), None))
Expand Down Expand Up @@ -147,6 +165,9 @@ def is_enumof(annotation) -> bool:
def is_dynamic_enum(annotation) -> bool:
return type(annotation).__name__ == "DynamicEnum"

def is_listof_enumof(annotation) -> bool:
return type(annotation).__name__ == "ListOf" and is_enumof(annotation.annotation)

def is_boolean(annotation) -> bool:
return getattr(annotation, "name", "") == "true or false"

Expand Down

0 comments on commit 57ad730

Please sign in to comment.