Added error markers.

sql-parser
Thorsten Muerell 7 years ago
parent 2d1d6d491e
commit 3a9674e80b

Binary file not shown.

@ -3,15 +3,22 @@
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { ConnectionProvider, ConnectionNode } from './connections'
const { spawn } = require('child_process');
const extensionName = "frog";
var dbSession = null;
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
const connectionProvider = new ConnectionProvider();
let myOutputChannel = vscode.window.createOutputChannel('SQL Query Results');
context.subscriptions.push(myOutputChannel);
let diagnosticCollection = vscode.languages.createDiagnosticCollection(extensionName);
context.subscriptions.push(diagnosticCollection);
vscode.window.registerTreeDataProvider('connections', connectionProvider);
@ -25,6 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('extension.executeSnippet', () => {
// The code you place here will be executed every time your command is executed
let editor = vscode.window.activeTextEditor;
if (!editor) return;
@ -47,13 +55,27 @@ export function activate(context: vscode.ExtensionContext) {
try {
let json = JSON.parse(outputBuffer);
const diagnostics = [];
let cd = json['columnDefinitions']
if (!json['rows']) {
if (!json['userErrors']) {
myOutputChannel.append("SQL executed successfully.\n");
} else {
myOutputChannel.append(JSON.stringify(json, null ,2));
myOutputChannel.append("Errors found:\n");
const document = vscode.window.activeTextEditor.document;
for (let error of json['userErrors'][0]['lines']) {
let range = document.lineAt(selection.start.line + error['line'] - 1).range;
let diagnostic = new vscode.Diagnostic(range, error['text'], vscode.DiagnosticSeverity.Error);
diagnostic.source = extensionName;
diagnostic.code = "code";
diagnostics.push(diagnostic);
myOutputChannel.append(error['line'] + ": " + error['text'] + "\n");
}
diagnosticCollection.set(document.uri, diagnostics);
}
} else {
for (let row of json["rows"]) {
@ -85,6 +107,7 @@ export function activate(context: vscode.ExtensionContext) {
return;
}
myOutputChannel.append("-- " + new Date() + " -------------------------------\n"); //Executing: '" + text + "'\n");
dbSession.stdin.write(text + "\n--- END ---\n");
});

Loading…
Cancel
Save