completions: Detect translatable properties

Looked through the Gtk documentation (and a few other libraries) to make
a list of all the properties that should probably be translated. If a
property is on the list, the language server will mark it as translated
in completions.
This commit is contained in:
James Westman 2024-12-21 17:22:56 -06:00
parent ac70ea7403
commit 5b0f662478
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
2 changed files with 199 additions and 2 deletions

View file

@ -20,7 +20,7 @@
import sys
import typing as T
from . import gir, language
from . import annotations, gir, language
from .ast_utils import AstNode
from .completions_utils import *
from .language.types import ClassName
@ -154,11 +154,17 @@ def property_completer(lsp, ast_node, match_variables):
detail=prop.detail,
)
elif isinstance(prop.type, gir.StringType):
snippet = (
f'{prop_name}: _("$0");'
if annotations.is_property_translated(prop)
else f'{prop_name}: "$0";'
)
yield Completion(
prop_name,
CompletionItemKind.Property,
sort_text=f"0 {prop_name}",
snippet=f'{prop_name}: "$0";',
snippet=snippet,
docs=prop.doc,
detail=prop.detail,
)