lsp: Support completions

This commit is contained in:
James Westman 2021-10-30 17:47:31 -05:00
parent afecd744ca
commit 408f3ebce5
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
8 changed files with 460 additions and 106 deletions

View file

@ -22,6 +22,8 @@ import typing as T
from .ast_utils import *
from .errors import assert_true, AlreadyCaughtError, CompileError, CompilerBugError, MultipleErrors
from .gir import GirContext, get_namespace
from .lsp_utils import Completion, CompletionItemKind
from .tokenizer import Token
from .utils import lazy_prop
from .xml_emitter import XmlEmitter
@ -29,11 +31,16 @@ from .xml_emitter import XmlEmitter
class AstNode:
""" Base class for nodes in the abstract syntax tree. """
completers: T.List = []
def __init__(self):
self.group = None
self.parent = None
self.child_nodes = None
def __init_subclass__(cls):
cls.completers = []
@lazy_prop
def root(self):
if self.parent is None:
@ -263,6 +270,17 @@ class ObjectContent(AstNode):
self.children = children
self.style = style
@validate()
def gir_class(self):
parent = self.parent
if isinstance(parent, Template):
return parent.gir_parent
elif isinstance(parent, Object):
return parent.gir_class
else:
raise CompilerBugError()
@validate()
def only_one_style_class(self):
if len(self.style) > 1: