Fix mypy issues

This commit is contained in:
James Westman 2022-01-28 14:07:29 -06:00
parent 1150ae1a09
commit cb35acad17
3 changed files with 19 additions and 15 deletions

View file

@ -19,7 +19,8 @@
import typing as T
from . import gir
from . import gir, language
from .ast_utils import AstNode
from .completions_utils import *
from .lsp_utils import Completion, CompletionItemKind
from .parser import SKIP_TOKENS
@ -28,7 +29,7 @@ from .tokenizer import TokenType, Token
Pattern = T.List[T.Tuple[TokenType, T.Optional[str]]]
def _complete(ast_node: ast.AstNode, tokens: T.List[Token], idx: int, token_idx: int) -> T.Iterator[Completion]:
def _complete(ast_node: AstNode, tokens: T.List[Token], idx: int, token_idx: int) -> T.Iterator[Completion]:
for child in ast_node.children:
if child.group.start <= idx and (idx < child.group.end or (idx == child.group.end and child.incomplete)):
yield from _complete(child, tokens, idx, token_idx)
@ -47,7 +48,7 @@ def _complete(ast_node: ast.AstNode, tokens: T.List[Token], idx: int, token_idx:
yield from completer(prev_tokens, ast_node)
def complete(ast_node: ast.AstNode, tokens: T.List[Token], idx: int) -> T.Iterator[Completion]:
def complete(ast_node: AstNode, tokens: T.List[Token], idx: int) -> T.Iterator[Completion]:
token_idx = 0
# find the current token
for i, token in enumerate(tokens):
@ -62,24 +63,24 @@ def complete(ast_node: ast.AstNode, tokens: T.List[Token], idx: int) -> T.Iterat
yield from _complete(ast_node, tokens, idx, token_idx)
@completer([ast.GtkDirective])
@completer([language.GtkDirective])
def using_gtk(ast_node, match_variables):
yield Completion("using Gtk 4.0;", CompletionItemKind.Keyword)
@completer(
applies_in=[ast.UI, ast.ObjectContent, ast.Template],
applies_in=[language.UI, language.ObjectContent, language.Template],
matches=new_statement_patterns
)
def namespace(ast_node, match_variables):
yield Completion("Gtk", CompletionItemKind.Module, text="Gtk.")
for ns in ast_node.root.children[ast.Import]:
for ns in ast_node.root.children[language.Import]:
if ns.gir_namespace is not None:
yield Completion(ns.gir_namespace.name, CompletionItemKind.Module, text=ns.gir_namespace.name + ".")
@completer(
applies_in=[ast.UI, ast.ObjectContent, ast.Template],
applies_in=[language.UI, language.ObjectContent, language.Template],
matches=[
[(TokenType.IDENT, None), (TokenType.OP, "."), (TokenType.IDENT, None)],
[(TokenType.IDENT, None), (TokenType.OP, ".")],
@ -93,7 +94,7 @@ def object_completer(ast_node, match_variables):
@completer(
applies_in=[ast.ObjectContent],
applies_in=[language.ObjectContent],
matches=new_statement_patterns,
)
def property_completer(ast_node, match_variables):
@ -103,7 +104,7 @@ def property_completer(ast_node, match_variables):
@completer(
applies_in=[ast.Property, ast.BaseTypedAttribute],
applies_in=[language.Property, language.BaseTypedAttribute],
matches=[
[(TokenType.IDENT, None), (TokenType.OP, ":")]
],
@ -119,13 +120,13 @@ def prop_value_completer(ast_node, match_variables):
@completer(
applies_in=[ast.ObjectContent],
applies_in=[language.ObjectContent],
matches=new_statement_patterns,
)
def signal_completer(ast_node, match_variables):
if ast_node.gir_class:
for signal in ast_node.gir_class.signals:
if not isinstance(ast_node.parent, ast.Object):
if not isinstance(ast_node.parent, language.Object):
name = "on"
else:
name = "on_" + (ast_node.parent.tokens["id"] or ast_node.parent.tokens["class_name"].lower())
@ -133,7 +134,7 @@ def signal_completer(ast_node, match_variables):
@completer(
applies_in=[ast.UI],
applies_in=[language.UI],
matches=new_statement_patterns
)
def template_completer(ast_node, match_variables):