lsp: Fix crash when import version missing

The issue is specific to the language server, since it's trying to use
an AST that contains errors. The test would not fail but was added
anyway.
This commit is contained in:
Sonny Piers 2022-07-09 21:04:28 +02:00 committed by James Westman
parent b9fdc5a5f1
commit 2da6be7618
5 changed files with 16 additions and 3 deletions

9
CONTRIBUTING.md Normal file
View file

@ -0,0 +1,9 @@
First of all, thank you for contributing to Blueprint.
If you learn something useful, please add it to this file.
# Run the test suite
```
python -m unittest
```

View file

@ -31,16 +31,17 @@ class GtkDirective(AstNode):
@validate("version")
def gtk_version(self):
if self.tokens["version"] not in ["4.0"]:
version = self.tokens["version"]
if version not in ["4.0"]:
err = CompileError("Only GTK 4 is supported")
if self.tokens["version"].startswith("4"):
if version and version.startswith("4"):
err.hint("Expected the GIR version, not an exact version number. Use 'using Gtk 4.0;'.")
else:
err.hint("Expected 'using Gtk 4.0;'")
raise err
try:
gir.get_namespace("Gtk", self.tokens["version"])
gir.get_namespace("Gtk", version)
except CompileError as e:
raise CompileError(
"Could not find GTK 4 introspection files. Is gobject-introspection installed?",

View file

@ -0,0 +1 @@
using Gtk

View file

@ -0,0 +1 @@
1,10,0,Expected a version number for GTK

View file

@ -188,6 +188,7 @@ class TestSamples(unittest.TestCase):
self.assert_sample_error("gtk_exact_version")
self.assert_sample_error("invalid_bool")
self.assert_sample_error("layout_in_non_widget")
self.assert_sample_error("no_import_version")
self.assert_sample_error("ns_not_imported")
self.assert_sample_error("not_a_class")
self.assert_sample_error("object_dne")