show location of error in gutter and as selection

Close #3
This commit is contained in:
eelke 2018-04-09 21:44:00 +02:00
parent 47ee1857cd
commit 45b7d4fcbc
4 changed files with 105 additions and 14 deletions

View file

@ -512,7 +512,9 @@ void QueryTab::query_ready(Expected<std::shared_ptr<Pgsql::Result>> exp_res, qin
// statusBar()->showMessage(tr("No tuples returned, possibly an error..."));
// }
ui->tabWidget->setCurrentWidget(ui->messageTab);
receiveNotice(dbres->diagDetails());
auto details = dbres->diagDetails();
markError(details);
receiveNotice(details);
}
}
}
@ -526,6 +528,37 @@ void QueryTab::query_ready(Expected<std::shared_ptr<Pgsql::Result>> exp_res, qin
}
}
void QueryTab::markError(const Pgsql::ErrorDetails &details)
{
if (details.statementPosition > 0) {
QTextCursor cursor = ui->queryEdit->textCursor();
cursor.setPosition(details.statementPosition-1);
ui->queryEdit->setTextCursor(cursor);
int length = 0;
if (details.state == "42703") {
int pos = details.messagePrimary.find('"');
if (pos != std::string::npos) {
int pos2 = details.messagePrimary.find('"', pos+1);
if (pos2 != std::string::npos) {
length = pos2 - pos;
}
}
}
else if (details.state == "42P01") {
int pos = details.messagePrimary.find('"');
if (pos != std::string::npos) {
int pos2 = details.messagePrimary.find('"', pos+1);
if (pos2 != std::string::npos) {
length = pos2 - pos;
}
}
}
ui->queryEdit->addErrorMarker(details.statementPosition-1, length);
}
}
void QueryTab::clearResult()
{
for (auto e : resultList)