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 .completions_utils import (
|
||||
CompletionContext,
|
||||
completers,
|
||||
completer,
|
||||
get_sort_key,
|
||||
new_statement_patterns,
|
||||
get_property_completion,
|
||||
CompletionItemKind,
|
||||
CompletionPriority,
|
||||
completer,
|
||||
completers,
|
||||
get_object_id_completions,
|
||||
get_property_completion,
|
||||
get_sort_key,
|
||||
new_statement_patterns,
|
||||
)
|
||||
from .language.types import ClassName
|
||||
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"),
|
||||
)
|
||||
|
||||
for id, obj in ctx.ast_node.root.context[language.ScopeCtx].objects.items():
|
||||
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),
|
||||
)
|
||||
yield from get_object_id_completions(ctx, vt.value_type)
|
||||
|
||||
if isinstance(ctx.ast_node, language.Property):
|
||||
yield from _available_namespace_completions(ctx)
|
||||
|
|
|
@ -22,7 +22,7 @@ import typing as T
|
|||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
from . import gir
|
||||
from . import gir, language
|
||||
from .ast_utils import AstNode
|
||||
from .lsp_utils import Completion, CompletionItemKind
|
||||
from .tokenizer import Token, TokenType
|
||||
|
@ -163,3 +163,18 @@ def get_property_completion(
|
|||
snippet=snippet,
|
||||
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 += ";"
|
||||
ctx.print(line)
|
||||
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