Snippets: Split error messages out of the parsed snippet

Change-Id: Ic5d6664c86405c558e8bb133b854521e4eaef58a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-04-20 14:25:18 +02:00
parent d9862a767b
commit c8f8513c8d
3 changed files with 68 additions and 40 deletions

View File

@@ -2700,15 +2700,14 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
void TextEditorWidget::insertCodeSnippet(const QTextCursor &cursor_arg, const QString &snippet)
{
ParsedSnippet data = Snippet::parse(snippet);
if (!data.success) {
QString message = QString::fromLatin1("Cannot parse snippet \"%1\".").arg(snippet);
if (!data.errorMessage.isEmpty())
message += QLatin1String("\nParse error: ") + data.errorMessage;
QMessageBox::warning(this, QLatin1String("Snippet Parse Error"), message);
SnippetParseResult result = Snippet::parse(snippet);
if (Utils::holds_alternative<SnippetParseError>(result)) {
const auto &error = Utils::get<SnippetParseError>(result);
QMessageBox::warning(this, QLatin1String("Snippet Parse Error"), error.htmlMessage());
return;
}
QTC_ASSERT(Utils::holds_alternative<ParsedSnippet>(result), return);
ParsedSnippet data = Utils::get<ParsedSnippet>(result);
QTextCursor cursor = cursor_arg;
cursor.beginEditBlock();