|
|
@ -3,15 +3,22 @@
|
|
|
|
// Import the module and reference it with the alias vscode in your code below
|
|
|
|
// Import the module and reference it with the alias vscode in your code below
|
|
|
|
import * as vscode from 'vscode';
|
|
|
|
import * as vscode from 'vscode';
|
|
|
|
import { ConnectionProvider, ConnectionNode } from './connections'
|
|
|
|
import { ConnectionProvider, ConnectionNode } from './connections'
|
|
|
|
|
|
|
|
|
|
|
|
const { spawn } = require('child_process');
|
|
|
|
const { spawn } = require('child_process');
|
|
|
|
|
|
|
|
const extensionName = "frog";
|
|
|
|
|
|
|
|
|
|
|
|
var dbSession = null;
|
|
|
|
var dbSession = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this method is called when your extension is activated
|
|
|
|
// this method is called when your extension is activated
|
|
|
|
// your extension is activated the very first time the command is executed
|
|
|
|
// your extension is activated the very first time the command is executed
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
|
|
const connectionProvider = new ConnectionProvider();
|
|
|
|
const connectionProvider = new ConnectionProvider();
|
|
|
|
let myOutputChannel = vscode.window.createOutputChannel('SQL Query Results');
|
|
|
|
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);
|
|
|
|
vscode.window.registerTreeDataProvider('connections', connectionProvider);
|
|
|
|
|
|
|
|
|
|
|
@ -25,6 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
|
let disposable = vscode.commands.registerCommand('extension.executeSnippet', () => {
|
|
|
|
let disposable = vscode.commands.registerCommand('extension.executeSnippet', () => {
|
|
|
|
// The code you place here will be executed every time your command is executed
|
|
|
|
// The code you place here will be executed every time your command is executed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let editor = vscode.window.activeTextEditor;
|
|
|
|
let editor = vscode.window.activeTextEditor;
|
|
|
|
|
|
|
|
|
|
|
|
if (!editor) return;
|
|
|
|
if (!editor) return;
|
|
|
@ -47,13 +55,27 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
let json = JSON.parse(outputBuffer);
|
|
|
|
let json = JSON.parse(outputBuffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const diagnostics = [];
|
|
|
|
let cd = json['columnDefinitions']
|
|
|
|
let cd = json['columnDefinitions']
|
|
|
|
|
|
|
|
|
|
|
|
if (!json['rows']) {
|
|
|
|
if (!json['rows']) {
|
|
|
|
if (!json['userErrors']) {
|
|
|
|
if (!json['userErrors']) {
|
|
|
|
myOutputChannel.append("SQL executed successfully.\n");
|
|
|
|
myOutputChannel.append("SQL executed successfully.\n");
|
|
|
|
} else {
|
|
|
|
} 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 {
|
|
|
|
} else {
|
|
|
|
for (let row of json["rows"]) {
|
|
|
|
for (let row of json["rows"]) {
|
|
|
@ -84,6 +106,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|
|
|
vscode.window.showInformationMessage('No text selected');
|
|
|
|
vscode.window.showInformationMessage('No text selected');
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myOutputChannel.append("-- " + new Date() + " -------------------------------\n"); //Executing: '" + text + "'\n");
|
|
|
|
myOutputChannel.append("-- " + new Date() + " -------------------------------\n"); //Executing: '" + text + "'\n");
|
|
|
|
dbSession.stdin.write(text + "\n--- END ---\n");
|
|
|
|
dbSession.stdin.write(text + "\n--- END ---\n");
|
|
|
|