Compare commits

..

5 commits

Author SHA1 Message Date
James Westman
8c6f8760f7 language: Add expression literals
Add expression literals, so you can set properties of type
Gtk.Expression.
2025-01-04 17:09:57 +00:00
Alexey Yerin
b9f58aeab5 Formatter: Add trailing commas in lists 2025-01-04 16:29:15 +00:00
James Westman
55e5095fba
values: Don't allow translated strings in arrays
Gtk.Builder has no way to translate individual strings in a string
array, so don't allow it in the syntax.
2025-01-03 18:56:24 -06:00
Alexey Yerin
f3faf4b993 LSP: Handle shutdown commands
This fixes the issue with terminal-based editor Helix which asks
language servers to shut down when trying to close the editor. Since
blueprint-compiler's server implementation didn't handle this request,
Helix ended up waiting for a response until timing out after a few
seconds and forcefully terminating the language server process.

Besides fixing Helix, this patch should also make user-initiated server
restarts more robust.
2025-01-03 22:49:36 +03:00
James Westman
d6f4b88d35
lsp: Fix crash on incomplete detailed signal 2024-12-25 10:31:35 -06:00
14 changed files with 94 additions and 6 deletions

View file

@ -146,8 +146,10 @@ def format(data, tab_size=2, insert_space=True):
is_child_type = False
elif str_item in CLOSING_TOKENS:
if str_item == "]" and last_not_whitespace != ",":
if str_item == "]" and str(last_not_whitespace) != "[":
current_line = current_line[:-1]
if str(last_not_whitespace) != ",":
current_line += ","
commit_current_line()
current_line = "]"
elif str(last_not_whitespace) in OPENING_TOKENS:

View file

@ -143,12 +143,13 @@ class Signal(AstNode):
@property
def document_symbol(self) -> DocumentSymbol:
detail = self.ranges["detail_start", "detail_end"]
return DocumentSymbol(
self.full_name,
SymbolKind.Event,
self.range,
self.group.tokens["name"].range,
self.ranges["detail_start", "detail_end"].text,
detail.text if detail is not None else None,
)
def get_reference(self, idx: int) -> T.Optional[LocationLink]:

View file

@ -487,6 +487,14 @@ class ArrayValue(AstNode):
range=quoted_literal.range,
)
)
elif isinstance(value.child, Translated):
errors.append(
CompileError(
"Arrays can't contain translated strings",
range=value.child.range,
)
)
if len(errors) > 0:
raise MultipleErrors(errors)

View file

@ -118,6 +118,7 @@ class LanguageServer:
self.client_capabilities = {}
self.client_supports_completion_choice = False
self._open_files: T.Dict[str, OpenFile] = {}
self._exited = False
def run(self):
# Read <doc> tags from gir files. During normal compilation these are
@ -125,7 +126,7 @@ class LanguageServer:
xml_reader.PARSE_GIR.add("doc")
try:
while True:
while not self._exited:
line = ""
content_len = -1
while content_len == -1 or (line != "\n" and line != "\r\n"):
@ -221,6 +222,14 @@ class LanguageServer:
},
)
@command("shutdown")
def shutdown(self, id, params):
self._send_response(id, None)
@command("exit")
def exit(self, id, params):
self._exited = True
@command("textDocument/didOpen")
def didOpen(self, id, params):
doc = params.get("textDocument")

View file

@ -0,0 +1,21 @@
using Gtk 4.0;
Box {
styles []
}
Box {
styles ["a"]
}
Box {
styles ["a",]
}
Box {
styles ["a", "b"]
}
Box {
styles ["a", "b",]
}

View file

@ -0,0 +1,31 @@
using Gtk 4.0;
Box {
styles []
}
Box {
styles [
"a",
]
}
Box {
styles [
"a",
]
}
Box {
styles [
"a",
"b",
]
}
Box {
styles [
"a",
"b",
]
}

View file

@ -11,7 +11,7 @@ Overlay {
notify::icon-name => $on_icon_name_changed(label) swapped;
styles [
"destructive"
"destructive",
]
}

View file

@ -0,0 +1,5 @@
using Gtk 4.0;
Label {
notify::
}

View file

@ -0,0 +1,2 @@
5,1,0,Expected a signal detail name
4,9,3,Unexpected tokens

View file

@ -0,0 +1,7 @@
using Gtk 4.0;
StringList {
strings: [
_("Test")
];
}

View file

@ -0,0 +1 @@
5,5,9,Arrays can't contain translated strings

View file

@ -5,6 +5,6 @@ AboutDialog about {
authors: [
"Jane doe <jane-doe@email.com>",
"Jhonny D <jd@email.com>"
"Jhonny D <jd@email.com>",
];
}

View file

@ -3,6 +3,6 @@ using Gtk 4.0;
Label {
styles [
"class-1",
"class-2"
"class-2",
]
}

View file

@ -47,3 +47,4 @@ class TestFormatter(unittest.TestCase):
self.assert_format_test("correct1.blp", "correct1.blp")
self.assert_format_test("string_in.blp", "string_out.blp")
self.assert_format_test("comment_in.blp", "comment_out.blp")
self.assert_format_test("lists_in.blp", "lists_out.blp")