mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-06 16:19:07 -04:00
Compare commits
5 commits
02344139c2
...
8c6f8760f7
Author | SHA1 | Date | |
---|---|---|---|
|
8c6f8760f7 | ||
|
b9f58aeab5 | ||
|
55e5095fba | ||
|
f3faf4b993 | ||
|
d6f4b88d35 |
14 changed files with 94 additions and 6 deletions
|
@ -146,8 +146,10 @@ def format(data, tab_size=2, insert_space=True):
|
||||||
is_child_type = False
|
is_child_type = False
|
||||||
|
|
||||||
elif str_item in CLOSING_TOKENS:
|
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]
|
current_line = current_line[:-1]
|
||||||
|
if str(last_not_whitespace) != ",":
|
||||||
|
current_line += ","
|
||||||
commit_current_line()
|
commit_current_line()
|
||||||
current_line = "]"
|
current_line = "]"
|
||||||
elif str(last_not_whitespace) in OPENING_TOKENS:
|
elif str(last_not_whitespace) in OPENING_TOKENS:
|
||||||
|
|
|
@ -143,12 +143,13 @@ class Signal(AstNode):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def document_symbol(self) -> DocumentSymbol:
|
def document_symbol(self) -> DocumentSymbol:
|
||||||
|
detail = self.ranges["detail_start", "detail_end"]
|
||||||
return DocumentSymbol(
|
return DocumentSymbol(
|
||||||
self.full_name,
|
self.full_name,
|
||||||
SymbolKind.Event,
|
SymbolKind.Event,
|
||||||
self.range,
|
self.range,
|
||||||
self.group.tokens["name"].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]:
|
def get_reference(self, idx: int) -> T.Optional[LocationLink]:
|
||||||
|
|
|
@ -487,6 +487,14 @@ class ArrayValue(AstNode):
|
||||||
range=quoted_literal.range,
|
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:
|
if len(errors) > 0:
|
||||||
raise MultipleErrors(errors)
|
raise MultipleErrors(errors)
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ class LanguageServer:
|
||||||
self.client_capabilities = {}
|
self.client_capabilities = {}
|
||||||
self.client_supports_completion_choice = False
|
self.client_supports_completion_choice = False
|
||||||
self._open_files: T.Dict[str, OpenFile] = {}
|
self._open_files: T.Dict[str, OpenFile] = {}
|
||||||
|
self._exited = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Read <doc> tags from gir files. During normal compilation these are
|
# Read <doc> tags from gir files. During normal compilation these are
|
||||||
|
@ -125,7 +126,7 @@ class LanguageServer:
|
||||||
xml_reader.PARSE_GIR.add("doc")
|
xml_reader.PARSE_GIR.add("doc")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while not self._exited:
|
||||||
line = ""
|
line = ""
|
||||||
content_len = -1
|
content_len = -1
|
||||||
while content_len == -1 or (line != "\n" and line != "\r\n"):
|
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")
|
@command("textDocument/didOpen")
|
||||||
def didOpen(self, id, params):
|
def didOpen(self, id, params):
|
||||||
doc = params.get("textDocument")
|
doc = params.get("textDocument")
|
||||||
|
|
21
tests/formatting/lists_in.blp
Normal file
21
tests/formatting/lists_in.blp
Normal 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",]
|
||||||
|
}
|
31
tests/formatting/lists_out.blp
Normal file
31
tests/formatting/lists_out.blp
Normal 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",
|
||||||
|
]
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ Overlay {
|
||||||
notify::icon-name => $on_icon_name_changed(label) swapped;
|
notify::icon-name => $on_icon_name_changed(label) swapped;
|
||||||
|
|
||||||
styles [
|
styles [
|
||||||
"destructive"
|
"destructive",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
tests/sample_errors/incomplete_signal.blp
Normal file
5
tests/sample_errors/incomplete_signal.blp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
Label {
|
||||||
|
notify::
|
||||||
|
}
|
2
tests/sample_errors/incomplete_signal.err
Normal file
2
tests/sample_errors/incomplete_signal.err
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
5,1,0,Expected a signal detail name
|
||||||
|
4,9,3,Unexpected tokens
|
7
tests/sample_errors/translated_string_array.blp
Normal file
7
tests/sample_errors/translated_string_array.blp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
StringList {
|
||||||
|
strings: [
|
||||||
|
_("Test")
|
||||||
|
];
|
||||||
|
}
|
1
tests/sample_errors/translated_string_array.err
Normal file
1
tests/sample_errors/translated_string_array.err
Normal file
|
@ -0,0 +1 @@
|
||||||
|
5,5,9,Arrays can't contain translated strings
|
|
@ -5,6 +5,6 @@ AboutDialog about {
|
||||||
|
|
||||||
authors: [
|
authors: [
|
||||||
"Jane doe <jane-doe@email.com>",
|
"Jane doe <jane-doe@email.com>",
|
||||||
"Jhonny D <jd@email.com>"
|
"Jhonny D <jd@email.com>",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@ using Gtk 4.0;
|
||||||
Label {
|
Label {
|
||||||
styles [
|
styles [
|
||||||
"class-1",
|
"class-1",
|
||||||
"class-2"
|
"class-2",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,3 +47,4 @@ class TestFormatter(unittest.TestCase):
|
||||||
self.assert_format_test("correct1.blp", "correct1.blp")
|
self.assert_format_test("correct1.blp", "correct1.blp")
|
||||||
self.assert_format_test("string_in.blp", "string_out.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("comment_in.blp", "comment_out.blp")
|
||||||
|
self.assert_format_test("lists_in.blp", "lists_out.blp")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue