From 2204eaf92d951298dc4f626d3c3d83944b975b95 Mon Sep 17 00:00:00 2001 From: James Westman Date: Sat, 4 Jan 2025 16:29:10 -0600 Subject: [PATCH] completions: Add completer for import statements --- blueprintcompiler/completions.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/blueprintcompiler/completions.py b/blueprintcompiler/completions.py index cdd8d7d..c2186dd 100644 --- a/blueprintcompiler/completions.py +++ b/blueprintcompiler/completions.py @@ -90,6 +90,29 @@ def using_gtk(_ctx: CompletionContext): ) +@completer([language.UI]) +def using(ctx: CompletionContext): + imported_namespaces = set( + [import_.namespace for import_ in ctx.ast_node.root.using] + ) + + # Import statements must be before any content + for i in ctx.ast_node.root.children: + if not isinstance(i, language.GtkDirective) and not isinstance( + i, language.Import + ): + if ctx.index >= i.range.end: + return + + for ns, version in gir.get_available_namespaces(): + if ns not in imported_namespaces and ns != "Gtk": + yield Completion( + f"using {ns} {version}", + CompletionItemKind.Module, + text=f"using {ns} {version};", + ) + + @completer([language.UI]) def translation_domain(ctx: CompletionContext): if ctx.ast_node.root.translation_domain is not None: