completions: Add types in typeof<> and as<>

This commit is contained in:
James Westman 2025-05-03 13:30:55 -05:00
parent d5b2ee3589
commit e9206809d6
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
10 changed files with 124 additions and 39 deletions

View file

@ -57,14 +57,21 @@ new_statement_patterns = [
[(TokenType.PUNCTUATION, "}")],
[(TokenType.PUNCTUATION, "]")],
[(TokenType.PUNCTUATION, ";")],
[(TokenType.OP, "<")],
]
completers = []
def completer(applies_in: T.List, matches: T.List = [], applies_in_subclass=None):
def decorator(func: T.Callable[[CompletionContext], T.Generator[Completion]]):
def inner(
prev_tokens: T.List[Token], next_token: Token, ast_node, lsp, idx: int
):
if not any(isinstance(ast_node, rule) for rule in applies_in):
return
# For completers that apply in ObjectContent nodes, we can further
# check that the object is the right class
if applies_in_subclass is not None:
@ -118,8 +125,7 @@ def completer(applies_in: T.List, matches: T.List = [], applies_in_subclass=None
)
yield from func(context)
for c in applies_in:
c.completers.append(inner)
completers.append(inner)
return inner
return decorator