mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
lsp: Show better info on IdentLiteral hover
Instead of showing the documentation for the expected type, show the signature of the referenced object.
This commit is contained in:
parent
9ff76b65cc
commit
cb1eb9ba44
5 changed files with 41 additions and 6 deletions
|
@ -55,6 +55,13 @@ class Object(AstNode):
|
|||
def content(self) -> ObjectContent:
|
||||
return self.children[ObjectContent][0]
|
||||
|
||||
@property
|
||||
def signature(self) -> str:
|
||||
if self.id:
|
||||
return f"{self.class_name.gir_type.full_name} {self.id}"
|
||||
else:
|
||||
return f"{self.class_name.gir_type.full_name}"
|
||||
|
||||
@property
|
||||
def gir_class(self) -> GirType:
|
||||
if self.class_name is None:
|
||||
|
|
|
@ -9,6 +9,14 @@ from .types import TypeName
|
|||
class ExtListItemFactory(AstNode):
|
||||
grammar = [UseExact("id", "template"), Optional(TypeName), ObjectContent]
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
return "template"
|
||||
|
||||
@property
|
||||
def signature(self) -> str:
|
||||
return f"template {self.gir_class.full_name}"
|
||||
|
||||
@property
|
||||
def type_name(self) -> T.Optional[TypeName]:
|
||||
if len(self.children[TypeName]) == 1:
|
||||
|
|
|
@ -35,6 +35,13 @@ class Menu(AstNode):
|
|||
def id(self) -> str:
|
||||
return self.tokens["id"]
|
||||
|
||||
@property
|
||||
def signature(self) -> str:
|
||||
if self.id:
|
||||
return f"Gio.Menu {self.id}"
|
||||
else:
|
||||
return "Gio.Menu"
|
||||
|
||||
@property
|
||||
def tag(self) -> str:
|
||||
return self.tokens["tag"]
|
||||
|
|
|
@ -44,6 +44,13 @@ class Template(Object):
|
|||
def id(self) -> str:
|
||||
return "template"
|
||||
|
||||
@property
|
||||
def signature(self) -> str:
|
||||
if self.parent_type:
|
||||
return f"template {self.gir_class.full_name} : {self.parent_type.gir_type.full_name}"
|
||||
else:
|
||||
return f"template {self.gir_class.full_name}"
|
||||
|
||||
@property
|
||||
def gir_class(self) -> GirType:
|
||||
if isinstance(self.class_name.gir_type, ExternType):
|
||||
|
|
|
@ -312,14 +312,20 @@ class IdentLiteral(AstNode):
|
|||
|
||||
@docs()
|
||||
def docs(self) -> T.Optional[str]:
|
||||
type = self.context[ValueTypeCtx].value_type
|
||||
if isinstance(type, gir.Enumeration):
|
||||
if member := type.members.get(self.ident):
|
||||
expected_type = self.context[ValueTypeCtx].value_type
|
||||
if isinstance(expected_type, gir.BoolType):
|
||||
return None
|
||||
elif isinstance(expected_type, gir.Enumeration):
|
||||
if member := expected_type.members.get(self.ident):
|
||||
return member.doc
|
||||
else:
|
||||
return type.doc
|
||||
elif isinstance(type, gir.GirNode):
|
||||
return type.doc
|
||||
return expected_type.doc
|
||||
elif self.ident == "null" and self.context[ValueTypeCtx].allow_null:
|
||||
return None
|
||||
elif object := self.context[ScopeCtx].objects.get(self.ident):
|
||||
return f"```\n{object.signature}\n```"
|
||||
elif self.root.is_legacy_template(self.ident):
|
||||
return f"```\n{self.root.template.signature}\n```"
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue