mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
Add a diagnostics getter to ComponentCompiler
This commit is contained in:
parent
5b726cacbe
commit
e1f9347aaa
4 changed files with 71 additions and 0 deletions
|
@ -473,6 +473,9 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
using Diagnostic = sixtyfps::cbindgen_private::CDiagnostic;
|
||||
using DiagnosticLevel = sixtyfps::cbindgen_private::CDiagnosticLevel;
|
||||
|
||||
class ComponentCompiler
|
||||
{
|
||||
cbindgen_private::ComponentCompilerOpaque inner;
|
||||
|
@ -513,6 +516,13 @@ public:
|
|||
return paths;
|
||||
}
|
||||
|
||||
sixtyfps::SharedVector<Diagnostic> diagnostics() const
|
||||
{
|
||||
sixtyfps::SharedVector<Diagnostic> result;
|
||||
cbindgen_private::sixtyfps_interpreter_component_compiler_get_diagnostics(&inner, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::optional<ComponentDefinition> build_from_source(std::string_view source_code,
|
||||
std::string_view path)
|
||||
{
|
||||
|
|
|
@ -88,6 +88,22 @@ struct SharedString
|
|||
/// \return true if the string contains no characters; false otherwise.
|
||||
bool empty() const { return std::string_view(*this).empty(); }
|
||||
|
||||
/// \return true if the string starts with the specified prefix string; false otherwise
|
||||
bool starts_with(std::string_view prefix) const
|
||||
{
|
||||
return std::string_view(*this).substr(0, prefix.size()) == prefix;
|
||||
}
|
||||
|
||||
/// \return true if the string ends with the specified prefix string; false otherwise
|
||||
bool ends_with(std::string_view prefix) const
|
||||
{
|
||||
std::string_view self_view(*this);
|
||||
return self_view.size() >= prefix.size()
|
||||
&& self_view.compare(self_view.size() - prefix.size(), std::string_view::npos,
|
||||
prefix)
|
||||
== 0;
|
||||
}
|
||||
|
||||
/// Creates a new SharedString from the given number \a n. The string representation of the
|
||||
/// number uses a minimal formatting scheme: If \a n has no fractional part, the number will be
|
||||
/// formatted as an integer.
|
||||
|
|
|
@ -282,6 +282,10 @@ SCENARIO("Component Compiler")
|
|||
{
|
||||
auto result = compiler.build_from_path(SOURCE_DIR "/file-not-there.60");
|
||||
REQUIRE_FALSE(result.has_value());
|
||||
auto diags = compiler.diagnostics();
|
||||
|
||||
REQUIRE(diags.size() == 1);
|
||||
REQUIRE(diags[0].message.starts_with("Could not load"));
|
||||
}
|
||||
|
||||
SECTION("Compile from path")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue