mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
completions: Sort completion items
This commit is contained in:
parent
860580e560
commit
d0394136cf
12 changed files with 135 additions and 22 deletions
|
@ -110,6 +110,7 @@ def using(ctx: CompletionContext):
|
||||||
f"using {ns} {version}",
|
f"using {ns} {version}",
|
||||||
CompletionItemKind.Module,
|
CompletionItemKind.Module,
|
||||||
text=f"using {ns} {version};",
|
text=f"using {ns} {version};",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.NAMESPACE, ns),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,6 +131,7 @@ def translation_domain(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"translation-domain",
|
"translation-domain",
|
||||||
CompletionItemKind.Keyword,
|
CompletionItemKind.Keyword,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.KEYWORD, "translation-domain"),
|
||||||
snippet='translation-domain "$0";',
|
snippet='translation-domain "$0";',
|
||||||
docs=get_docs_section("Syntax TranslationDomain"),
|
docs=get_docs_section("Syntax TranslationDomain"),
|
||||||
)
|
)
|
||||||
|
@ -146,6 +148,7 @@ def _ns_prefix_completions(ctx: CompletionContext):
|
||||||
ns,
|
ns,
|
||||||
CompletionItemKind.Module,
|
CompletionItemKind.Module,
|
||||||
text=ns + ".",
|
text=ns + ".",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.IMPORT_NAMESPACE, ns),
|
||||||
signature=f" using {ns} {version}",
|
signature=f" using {ns} {version}",
|
||||||
additional_text_edits=[
|
additional_text_edits=[
|
||||||
TextEdit(
|
TextEdit(
|
||||||
|
@ -168,6 +171,9 @@ def namespace(ctx: CompletionContext):
|
||||||
ns.gir_namespace.name,
|
ns.gir_namespace.name,
|
||||||
CompletionItemKind.Module,
|
CompletionItemKind.Module,
|
||||||
text=ns.gir_namespace.name + ".",
|
text=ns.gir_namespace.name + ".",
|
||||||
|
sort_text=get_sort_key(
|
||||||
|
CompletionPriority.NAMESPACE, ns.gir_namespace.name
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from _ns_prefix_completions(ctx)
|
yield from _ns_prefix_completions(ctx)
|
||||||
|
@ -191,6 +197,7 @@ def object_completer(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
c.name,
|
c.name,
|
||||||
CompletionItemKind.Class,
|
CompletionItemKind.Class,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.CLASS, c.name),
|
||||||
snippet=snippet,
|
snippet=snippet,
|
||||||
docs=c.doc,
|
docs=c.doc,
|
||||||
detail=c.detail,
|
detail=c.detail,
|
||||||
|
@ -212,6 +219,7 @@ def gtk_object_completer(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
c.name,
|
c.name,
|
||||||
CompletionItemKind.Class,
|
CompletionItemKind.Class,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.CLASS, c.name),
|
||||||
snippet=snippet,
|
snippet=snippet,
|
||||||
docs=c.doc,
|
docs=c.doc,
|
||||||
detail=c.detail,
|
detail=c.detail,
|
||||||
|
@ -254,7 +262,7 @@ def property_completer(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
prop_name,
|
prop_name,
|
||||||
CompletionItemKind.Property,
|
CompletionItemKind.Property,
|
||||||
sort_text=f"0 {prop_name}",
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, prop_name),
|
||||||
snippet=snippet,
|
snippet=snippet,
|
||||||
docs=prop.doc,
|
docs=prop.doc,
|
||||||
detail=prop.detail,
|
detail=prop.detail,
|
||||||
|
@ -272,6 +280,7 @@ def prop_value_completer(ctx: CompletionContext):
|
||||||
CompletionItemKind.Keyword,
|
CompletionItemKind.Keyword,
|
||||||
snippet="bind $0",
|
snippet="bind $0",
|
||||||
docs=get_docs_section("Syntax Binding"),
|
docs=get_docs_section("Syntax Binding"),
|
||||||
|
sort_text=get_sort_key(CompletionPriority.KEYWORD, "bind"),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert isinstance(ctx.ast_node, language.Property) or isinstance(
|
assert isinstance(ctx.ast_node, language.Property) or isinstance(
|
||||||
|
@ -286,11 +295,20 @@ def prop_value_completer(ctx: CompletionContext):
|
||||||
CompletionItemKind.EnumMember,
|
CompletionItemKind.EnumMember,
|
||||||
docs=member.doc,
|
docs=member.doc,
|
||||||
detail=member.detail,
|
detail=member.detail,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.ENUM_MEMBER, name),
|
||||||
)
|
)
|
||||||
|
|
||||||
elif isinstance(vt.value_type, gir.BoolType):
|
elif isinstance(vt.value_type, gir.BoolType):
|
||||||
yield Completion("true", CompletionItemKind.Constant)
|
yield Completion(
|
||||||
yield Completion("false", CompletionItemKind.Constant)
|
"true",
|
||||||
|
CompletionItemKind.Constant,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.ENUM_MEMBER, "true"),
|
||||||
|
)
|
||||||
|
yield Completion(
|
||||||
|
"false",
|
||||||
|
CompletionItemKind.Constant,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.ENUM_MEMBER, "false"),
|
||||||
|
)
|
||||||
|
|
||||||
elif isinstance(vt.value_type, gir.Class) or isinstance(
|
elif isinstance(vt.value_type, gir.Class) or isinstance(
|
||||||
vt.value_type, gir.Interface
|
vt.value_type, gir.Interface
|
||||||
|
@ -298,6 +316,7 @@ def prop_value_completer(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"null",
|
"null",
|
||||||
CompletionItemKind.Constant,
|
CompletionItemKind.Constant,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.KEYWORD, "null"),
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from _ns_prefix_completions(ctx)
|
yield from _ns_prefix_completions(ctx)
|
||||||
|
@ -309,7 +328,8 @@ def prop_value_completer(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
id,
|
id,
|
||||||
CompletionItemKind.Variable,
|
CompletionItemKind.Variable,
|
||||||
detail=obj.signature,
|
signature=" " + obj.signature,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.NAMED_OBJECT, id),
|
||||||
)
|
)
|
||||||
|
|
||||||
for ns in ctx.ast_node.root.gir.namespaces.values():
|
for ns in ctx.ast_node.root.gir.namespaces.values():
|
||||||
|
@ -322,6 +342,7 @@ def prop_value_completer(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
name,
|
name,
|
||||||
CompletionItemKind.Class,
|
CompletionItemKind.Class,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.CLASS, name),
|
||||||
snippet=snippet,
|
snippet=snippet,
|
||||||
detail=c.detail,
|
detail=c.detail,
|
||||||
docs=c.doc,
|
docs=c.doc,
|
||||||
|
@ -355,7 +376,7 @@ def signal_completer(ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
signal_name,
|
signal_name,
|
||||||
CompletionItemKind.Event,
|
CompletionItemKind.Event,
|
||||||
sort_text=f"1 {signal_name}",
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, signal_name),
|
||||||
snippet=snippet,
|
snippet=snippet,
|
||||||
docs=signal.doc,
|
docs=signal.doc,
|
||||||
detail=signal.detail,
|
detail=signal.detail,
|
||||||
|
|
|
@ -20,12 +20,28 @@
|
||||||
|
|
||||||
import typing as T
|
import typing as T
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
from .ast_utils import AstNode
|
from .ast_utils import AstNode
|
||||||
from .lsp_utils import Completion
|
from .lsp_utils import Completion
|
||||||
from .tokenizer import Token, TokenType
|
from .tokenizer import Token, TokenType
|
||||||
|
|
||||||
|
|
||||||
|
class CompletionPriority(Enum):
|
||||||
|
ENUM_MEMBER = "00"
|
||||||
|
NAMED_OBJECT = "01"
|
||||||
|
OBJECT_MEMBER = "02"
|
||||||
|
CLASS = "03"
|
||||||
|
NAMESPACE = "04"
|
||||||
|
KEYWORD = "05"
|
||||||
|
# An available namespace that hasn't been imported yet
|
||||||
|
IMPORT_NAMESPACE = "99"
|
||||||
|
|
||||||
|
|
||||||
|
def get_sort_key(priority: CompletionPriority, name: str):
|
||||||
|
return f"{priority.value} {name}"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CompletionContext:
|
class CompletionContext:
|
||||||
client_supports_completion_choice: bool
|
client_supports_completion_choice: bool
|
||||||
|
|
|
@ -156,7 +156,10 @@ def complete_adw_message_dialog(_ctx: CompletionContext):
|
||||||
)
|
)
|
||||||
def complete_adw_alert_dialog(_ctx: CompletionContext):
|
def complete_adw_alert_dialog(_ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"responses", CompletionItemKind.Keyword, snippet="responses [\n\t$0\n]"
|
"responses",
|
||||||
|
CompletionItemKind.Keyword,
|
||||||
|
snippet="responses [\n\t$0\n]",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "responses"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,10 @@ class ExtAccessibility(AstNode):
|
||||||
)
|
)
|
||||||
def a11y_completer(_ctx: CompletionContext):
|
def a11y_completer(_ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"accessibility", CompletionItemKind.Snippet, snippet="accessibility {\n $0\n}"
|
"accessibility",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="accessibility {\n $0\n}",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "accessibility"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,12 @@ class ExtComboBoxItems(AstNode):
|
||||||
matches=new_statement_patterns,
|
matches=new_statement_patterns,
|
||||||
)
|
)
|
||||||
def items_completer(_ctx: CompletionContext):
|
def items_completer(_ctx: CompletionContext):
|
||||||
yield Completion("items", CompletionItemKind.Snippet, snippet="items [$0]")
|
yield Completion(
|
||||||
|
"items",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="items [$0]",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "items"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@decompiler("items", parent_type="Gtk.ComboBoxText")
|
@decompiler("items", parent_type="Gtk.ComboBoxText")
|
||||||
|
|
|
@ -103,10 +103,23 @@ ext_file_filter_suffixes = create_node("suffixes", "suffix")
|
||||||
)
|
)
|
||||||
def file_filter_completer(_ctx: CompletionContext):
|
def file_filter_completer(_ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"mime-types", CompletionItemKind.Snippet, snippet='mime-types ["$0"]'
|
"mime-types",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet='mime-types ["$0"]',
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "mime-types"),
|
||||||
|
)
|
||||||
|
yield Completion(
|
||||||
|
"patterns",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet='patterns ["$0"]',
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "patterns"),
|
||||||
|
)
|
||||||
|
yield Completion(
|
||||||
|
"suffixes",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet='suffixes ["$0"]',
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "suffixes"),
|
||||||
)
|
)
|
||||||
yield Completion("patterns", CompletionItemKind.Snippet, snippet='patterns ["$0"]')
|
|
||||||
yield Completion("suffixes", CompletionItemKind.Snippet, snippet='suffixes ["$0"]')
|
|
||||||
|
|
||||||
|
|
||||||
@decompiler("mime-types")
|
@decompiler("mime-types")
|
||||||
|
|
|
@ -94,7 +94,12 @@ class ExtLayout(AstNode):
|
||||||
matches=new_statement_patterns,
|
matches=new_statement_patterns,
|
||||||
)
|
)
|
||||||
def layout_completer(_ctx: CompletionContext):
|
def layout_completer(_ctx: CompletionContext):
|
||||||
yield Completion("layout", CompletionItemKind.Snippet, snippet="layout {\n $0\n}")
|
yield Completion(
|
||||||
|
"layout",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="layout {\n $0\n}",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "layout"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@decompiler("layout")
|
@decompiler("layout")
|
||||||
|
|
|
@ -253,21 +253,48 @@ def menu_completer(_ctx: CompletionContext):
|
||||||
)
|
)
|
||||||
def menu_content_completer(_ctx: CompletionContext):
|
def menu_content_completer(_ctx: CompletionContext):
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"submenu", CompletionItemKind.Snippet, snippet="submenu {\n $0\n}"
|
"submenu",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="submenu {\n $0\n}",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.CLASS, "1 submenu"),
|
||||||
)
|
)
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"section", CompletionItemKind.Snippet, snippet="section {\n $0\n}"
|
"section",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="section {\n $0\n}",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.CLASS, "1 section"),
|
||||||
|
)
|
||||||
|
yield Completion(
|
||||||
|
"item",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="item {\n $0\n}",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.CLASS, "1 item"),
|
||||||
)
|
)
|
||||||
yield Completion("item", CompletionItemKind.Snippet, snippet="item {\n $0\n}")
|
|
||||||
yield Completion(
|
yield Completion(
|
||||||
"item (shorthand)",
|
"item (shorthand)",
|
||||||
CompletionItemKind.Snippet,
|
CompletionItemKind.Snippet,
|
||||||
snippet='item (_("${1:Label}"), "${2:action-name}", "${3:icon-name}")',
|
snippet='item (_("${1:Label}"), "${2:action-name}", "${3:icon-name}")',
|
||||||
|
sort_text=get_sort_key(CompletionPriority.CLASS, "0 item (shorthand)"),
|
||||||
)
|
)
|
||||||
|
|
||||||
yield Completion("label", CompletionItemKind.Snippet, snippet="label: $0;")
|
yield Completion(
|
||||||
yield Completion("action", CompletionItemKind.Snippet, snippet='action: "$0";')
|
"label",
|
||||||
yield Completion("icon", CompletionItemKind.Snippet, snippet='icon: "$0";')
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="label: $0;",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "label"),
|
||||||
|
)
|
||||||
|
yield Completion(
|
||||||
|
"action",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet='action: "$0";',
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "action"),
|
||||||
|
)
|
||||||
|
yield Completion(
|
||||||
|
"icon",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet='icon: "$0";',
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "icon"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@decompiler("menu")
|
@decompiler("menu")
|
||||||
|
|
|
@ -138,7 +138,12 @@ class ExtScaleMarks(AstNode):
|
||||||
matches=new_statement_patterns,
|
matches=new_statement_patterns,
|
||||||
)
|
)
|
||||||
def complete_marks(_ctx: CompletionContext):
|
def complete_marks(_ctx: CompletionContext):
|
||||||
yield Completion("marks", CompletionItemKind.Keyword, snippet="marks [\n\t$0\n]")
|
yield Completion(
|
||||||
|
"marks",
|
||||||
|
CompletionItemKind.Keyword,
|
||||||
|
snippet="marks [\n\t$0\n]",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "marks"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@completer(
|
@completer(
|
||||||
|
|
|
@ -105,7 +105,12 @@ class ExtSizeGroupWidgets(AstNode):
|
||||||
matches=new_statement_patterns,
|
matches=new_statement_patterns,
|
||||||
)
|
)
|
||||||
def size_group_completer(_ctx: CompletionContext):
|
def size_group_completer(_ctx: CompletionContext):
|
||||||
yield Completion("widgets", CompletionItemKind.Snippet, snippet="widgets [$0]")
|
yield Completion(
|
||||||
|
"widgets",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="widgets [$0]",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "widgets"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@decompiler("widgets")
|
@decompiler("widgets")
|
||||||
|
|
|
@ -76,7 +76,12 @@ class ExtStringListStrings(AstNode):
|
||||||
matches=new_statement_patterns,
|
matches=new_statement_patterns,
|
||||||
)
|
)
|
||||||
def strings_completer(_ctx: CompletionContext):
|
def strings_completer(_ctx: CompletionContext):
|
||||||
yield Completion("strings", CompletionItemKind.Snippet, snippet="strings [$0]")
|
yield Completion(
|
||||||
|
"strings",
|
||||||
|
CompletionItemKind.Snippet,
|
||||||
|
snippet="strings [$0]",
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "strings"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@decompiler("items", parent_type="Gtk.StringList")
|
@decompiler("items", parent_type="Gtk.StringList")
|
||||||
|
|
|
@ -81,7 +81,12 @@ class ExtStyles(AstNode):
|
||||||
matches=new_statement_patterns,
|
matches=new_statement_patterns,
|
||||||
)
|
)
|
||||||
def style_completer(_ctx: CompletionContext):
|
def style_completer(_ctx: CompletionContext):
|
||||||
yield Completion("styles", CompletionItemKind.Keyword, snippet='styles ["$0"]')
|
yield Completion(
|
||||||
|
"styles",
|
||||||
|
CompletionItemKind.Keyword,
|
||||||
|
snippet='styles ["$0"]',
|
||||||
|
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "styles"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@decompiler("style")
|
@decompiler("style")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue