lsp: Fix completions when editing existing item

Many completion snippets insert more than just the name. For example,
the object completer inserts the braces and places your cursor inside
them automatically, to save some typing. However, if you're changing the
class of an existing object, this isn't what you want. Changed so that
if the next token is '{', only the name is inserted.

Made similar changes to the property and signal completers.
This commit is contained in:
James Westman 2025-01-04 13:45:47 -06:00
parent 2e42dc6848
commit bf4d8579b6
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
13 changed files with 122 additions and 97 deletions

View file

@ -232,7 +232,7 @@ class ExtAccessibility(AstNode):
applies_in=[ObjectContent],
matches=new_statement_patterns,
)
def a11y_completer(lsp, ast_node, match_variables):
def a11y_completer(_ctx: CompletionContext):
yield Completion(
"accessibility", CompletionItemKind.Snippet, snippet="accessibility {\n $0\n}"
)
@ -242,12 +242,12 @@ def a11y_completer(lsp, ast_node, match_variables):
applies_in=[ExtAccessibility],
matches=new_statement_patterns,
)
def a11y_name_completer(lsp, ast_node, match_variables):
for name, type in get_types(ast_node.root.gir).items():
def a11y_name_completer(ctx: CompletionContext):
for name, type in get_types(ctx.ast_node.root.gir).items():
yield Completion(
name,
CompletionItemKind.Property,
docs=_get_docs(ast_node.root.gir, type.name),
docs=_get_docs(ctx.ast_node.root.gir, type.name),
)