mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
completions: Object names in signal handlers
This commit is contained in:
parent
1205fc42ea
commit
67983aee2e
3 changed files with 31 additions and 16 deletions
|
@ -23,13 +23,14 @@ from . import annotations, gir, language
|
||||||
from .ast_utils import AstNode
|
from .ast_utils import AstNode
|
||||||
from .completions_utils import (
|
from .completions_utils import (
|
||||||
CompletionContext,
|
CompletionContext,
|
||||||
completers,
|
|
||||||
completer,
|
|
||||||
get_sort_key,
|
|
||||||
new_statement_patterns,
|
|
||||||
get_property_completion,
|
|
||||||
CompletionItemKind,
|
CompletionItemKind,
|
||||||
CompletionPriority,
|
CompletionPriority,
|
||||||
|
completer,
|
||||||
|
completers,
|
||||||
|
get_object_id_completions,
|
||||||
|
get_property_completion,
|
||||||
|
get_sort_key,
|
||||||
|
new_statement_patterns,
|
||||||
)
|
)
|
||||||
from .language.types import ClassName
|
from .language.types import ClassName
|
||||||
from .lsp_utils import Completion, CompletionItemKind, TextEdit, get_docs_section
|
from .lsp_utils import Completion, CompletionItemKind, TextEdit, get_docs_section
|
||||||
|
@ -350,16 +351,7 @@ def prop_value_completer(ctx: CompletionContext):
|
||||||
sort_text=get_sort_key(CompletionPriority.KEYWORD, "null"),
|
sort_text=get_sort_key(CompletionPriority.KEYWORD, "null"),
|
||||||
)
|
)
|
||||||
|
|
||||||
for id, obj in ctx.ast_node.root.context[language.ScopeCtx].objects.items():
|
yield from get_object_id_completions(ctx, vt.value_type)
|
||||||
if obj.gir_class is not None and obj.gir_class.assignable_to(
|
|
||||||
vt.value_type
|
|
||||||
):
|
|
||||||
yield Completion(
|
|
||||||
id,
|
|
||||||
CompletionItemKind.Variable,
|
|
||||||
signature=" " + obj.signature,
|
|
||||||
sort_text=get_sort_key(CompletionPriority.NAMED_OBJECT, id),
|
|
||||||
)
|
|
||||||
|
|
||||||
if isinstance(ctx.ast_node, language.Property):
|
if isinstance(ctx.ast_node, language.Property):
|
||||||
yield from _available_namespace_completions(ctx)
|
yield from _available_namespace_completions(ctx)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import typing as T
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from . import gir
|
from . import gir, language
|
||||||
from .ast_utils import AstNode
|
from .ast_utils import AstNode
|
||||||
from .lsp_utils import Completion, CompletionItemKind
|
from .lsp_utils import Completion, CompletionItemKind
|
||||||
from .tokenizer import Token, TokenType
|
from .tokenizer import Token, TokenType
|
||||||
|
@ -163,3 +163,18 @@ def get_property_completion(
|
||||||
snippet=snippet,
|
snippet=snippet,
|
||||||
docs=doc,
|
docs=doc,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_object_id_completions(
|
||||||
|
ctx: CompletionContext, value_type: T.Optional[gir.GirType] = None
|
||||||
|
):
|
||||||
|
for id, obj in ctx.ast_node.root.context[language.ScopeCtx].objects.items():
|
||||||
|
if value_type is None or (
|
||||||
|
obj.gir_class is not None and obj.gir_class.assignable_to(value_type)
|
||||||
|
):
|
||||||
|
yield Completion(
|
||||||
|
id,
|
||||||
|
CompletionItemKind.Variable,
|
||||||
|
signature=" " + obj.signature,
|
||||||
|
sort_text=get_sort_key(CompletionPriority.NAMED_OBJECT, id),
|
||||||
|
)
|
||||||
|
|
|
@ -247,3 +247,11 @@ def decompile_signal(
|
||||||
line += ";"
|
line += ";"
|
||||||
ctx.print(line)
|
ctx.print(line)
|
||||||
return gir
|
return gir
|
||||||
|
|
||||||
|
|
||||||
|
@completer(
|
||||||
|
[Signal],
|
||||||
|
[[(TokenType.PUNCTUATION, "(")]],
|
||||||
|
)
|
||||||
|
def signal_object_completer(ctx: CompletionContext):
|
||||||
|
yield from get_object_id_completions(ctx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue