Highlight error location
Some databases return the location of an error, when one occurs (PostgreSQL, for example). It would be really really useful to highlight the location of the error in the editor or query.
I use this pice of code in dat-atom/lib/managers/postgres-manager.js but it is not very clean and it does not work when you submit a selection (because it looks from cursor position 0,0. At the moment I have no time to refine it an submit a pull request but maybe some has the time to do so ... The changes are only the "errorfunc" and the assignment of errorfunc to the events below Also it will also pop up NOTICES which you would normally not see in data-atom (ans I like them for debugging)
execute(database, query, onQueryToken) {
return new Promise((resolve, reject) => {
var url = database !== '' ? this.dbConfig.getUrlWithDb(database) : this.dbConfig.getUrl();
var errorfunc = function (err, client) {
var notification = {
buttons: [
{
className: "btn-details",
onDidClick: function() {
var editor = atom.workspace.getActiveTextEditor();
editor.setCursorBufferPosition(0,0);
editor.moveRight(err.position);
},
text: "find error"
}
],
dismissable: true
};
if (err.severity == 'INFO' || err.severity == 'NOTICE') {
atom.notifications.addInfo(err.message, notification);
} else if (err.severity == 'WARNING') {
atom.notifications.addWarning(err.message, notification);
} else {
atom.notifications.addError(err.message, notification);
}
console.log(err.message, JSON.stringify(err))
};
pg.connect(url, (err, client, done) => {
if (err) {
// call `done()` to release the client back to the pool
done();
reject(this.buildErrorMessage(err));
}
else {
client.on('notice', errorfunc);
client.on('error', errorfunc);
var pgQuery = client.query({text: query, rowMode: 'array', multiResult: true}, (err, results) => {
if (err) {
errorfunc(err, client);
done();
reject(this.buildErrorMessage(err));
}
else {
done();
resolve(this.translateResults(results));
}
});
if (onQueryToken) {
// give back some data so they can tell us to cancel the query if needed
onQueryToken({ client: client, query: pgQuery });
}
}
});
});
}