mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
lsp: Add code actions
"Did you mean" hints are automatically converted into code actions.
This commit is contained in:
parent
d89f2356b4
commit
d511b3f1e3
5 changed files with 82 additions and 16 deletions
|
@ -167,11 +167,21 @@ class Template(AstNode):
|
|||
|
||||
|
||||
class Object(AstNode):
|
||||
@validate("namespace", "class_name")
|
||||
def gir_class_exists(self):
|
||||
@validate("namespace")
|
||||
def gir_ns_exists(self):
|
||||
if not self.tokens["ignore_gir"]:
|
||||
self.root.gir.validate_ns(self.tokens["namespace"])
|
||||
|
||||
@validate("class_name")
|
||||
def gir_class_exists(self):
|
||||
if not self.tokens["ignore_gir"] and self.gir_ns is not None:
|
||||
self.root.gir.validate_class(self.tokens["class_name"], self.tokens["namespace"])
|
||||
|
||||
@property
|
||||
def gir_ns(self):
|
||||
if not self.tokens["ignore_gir"]:
|
||||
return self.root.gir.namespaces.get(self.tokens["namespace"])
|
||||
|
||||
@property
|
||||
def gir_class(self):
|
||||
if not self.tokens["ignore_gir"]:
|
||||
|
@ -180,7 +190,8 @@ class Object(AstNode):
|
|||
|
||||
@docs("namespace")
|
||||
def namespace_docs(self):
|
||||
return self.root.gir.namespaces[self.tokens["namespace"]].doc
|
||||
if ns := self.root.gir.namespaces.get(self.tokens["namespace"]):
|
||||
return ns.doc
|
||||
|
||||
|
||||
@docs("class_name")
|
||||
|
@ -398,17 +409,17 @@ class IdentValue(Value):
|
|||
if self.tokens["value"] not in type.members:
|
||||
raise CompileError(
|
||||
f"{self.tokens['value']} is not a member of {type.full_name}",
|
||||
did_you_mean=type.members.keys(),
|
||||
did_you_mean=(self.tokens['value'], type.members.keys()),
|
||||
)
|
||||
|
||||
elif isinstance(type, gir.BoolType):
|
||||
# would have been parsed as a LiteralValue if it was correct
|
||||
raise CompileError(
|
||||
f"Expected 'true' or 'false' for boolean value",
|
||||
did_you_mean=["true", "false"],
|
||||
did_you_mean=(self.tokens['value'], ["true", "false"]),
|
||||
)
|
||||
|
||||
else:
|
||||
elif type is not None:
|
||||
object = self.root.objects_by_id.get(self.tokens["value"])
|
||||
if object is None:
|
||||
raise CompileError(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue