feat(tools/tcl_command_completion): support def symbols and value completions
This commit is contained in:
@@ -24,6 +24,10 @@ class DynamicCompletionKind(Enum):
|
||||
PROCEDURE = "procedure"
|
||||
NAMESPACE = "namespace"
|
||||
PATH = "path"
|
||||
BLOCK_TEMPLATE = "block_template"
|
||||
ADDRESS = "address"
|
||||
# A variable substituted as a value, inserted with a leading "$".
|
||||
VALUE = "value"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -424,6 +428,8 @@ for _string_class in STRING_CLASSES:
|
||||
|
||||
VALUES_BY_POSITION: dict[tuple[tuple[str, ...], int], tuple[str, ...]] = {
|
||||
(("array", "names"), 3): ("-exact", "-glob", "-regexp"),
|
||||
(("MOM_force",), 1): ("Always", "Once", "Off"),
|
||||
(("MOM_suppress",), 1): ("Always", "Once", "Off"),
|
||||
(("close",), 2): ("read", "write"),
|
||||
(("open",), 2): ("r", "r+", "w", "w+", "a", "a+"),
|
||||
(("package", "prefer"), 2): ("latest", "stable"),
|
||||
@@ -468,6 +474,12 @@ DYNAMIC_COMPLETION_RULES = (
|
||||
DynamicCompletionRule(("namespace", "origin"), frozenset({2}), DynamicCompletionKind.PROCEDURE),
|
||||
DynamicCompletionRule(("rename",), frozenset({1}), DynamicCompletionKind.PROCEDURE),
|
||||
# Namespace-taking commands.
|
||||
DynamicCompletionRule(("MOM_do_template",), frozenset({1}), DynamicCompletionKind.BLOCK_TEMPLATE),
|
||||
DynamicCompletionRule(("MOM_ask_address_value",), frozenset({1}), DynamicCompletionKind.ADDRESS),
|
||||
DynamicCompletionRule(("MOM_force",), frozenset({1}), DynamicCompletionKind.VALUE),
|
||||
DynamicCompletionRule(("MOM_force",), _REPEATED_SUBCOMMAND_ARGUMENTS, DynamicCompletionKind.ADDRESS),
|
||||
DynamicCompletionRule(("MOM_suppress",), frozenset({1}), DynamicCompletionKind.VALUE),
|
||||
DynamicCompletionRule(("MOM_suppress",), _REPEATED_SUBCOMMAND_ARGUMENTS, DynamicCompletionKind.ADDRESS),
|
||||
DynamicCompletionRule(("namespace", "children"), frozenset({2}), DynamicCompletionKind.NAMESPACE),
|
||||
DynamicCompletionRule(
|
||||
("namespace", "delete"),
|
||||
@@ -685,13 +697,14 @@ def tcl_argument_completion(source_lines: Sequence[str], position: Position) ->
|
||||
|
||||
for (path, argument_index), values in VALUES_BY_POSITION.items():
|
||||
if active_index == argument_index and tuple(words[: len(path)]) == path:
|
||||
return TclArgumentCompletion(
|
||||
items=_completion_items(
|
||||
return _merge_dynamic_completion(
|
||||
_completion_items(
|
||||
values,
|
||||
CompletionItemKind.Value,
|
||||
f"{' '.join(path)} value",
|
||||
),
|
||||
active_prefix=active_prefix,
|
||||
dynamic_completion,
|
||||
active_prefix,
|
||||
)
|
||||
|
||||
for path in sorted(OPTIONS_BY_PATH, key=len, reverse=True):
|
||||
|
||||
Reference in New Issue
Block a user