lsp: Add code action to add missing imports

This commit is contained in:
James Westman 2023-07-25 20:02:03 -05:00
parent 3bcc9f4cbd
commit 35ee058192
3 changed files with 47 additions and 3 deletions

View file

@ -99,6 +99,18 @@ class UI(AstNode):
and self.template.class_name.glib_type_name == id
)
def import_code_action(self, ns: str, version: str) -> CodeAction:
if len(self.children[Import]):
pos = self.children[Import][-1].range.end
else:
pos = self.children[GtkDirective][0].range.end
return CodeAction(
f"Import {ns} {version}",
f"\nusing {ns} {version};",
Range(pos, pos, self.group.text),
)
@context(ScopeCtx)
def scope_ctx(self) -> ScopeCtx:
return ScopeCtx(node=self)