Block detection

sql-parser
Thorsten Muerell 7 years ago
parent 096159ce1a
commit 501987f199

@ -2,7 +2,7 @@
"name": "frog", "name": "frog",
"displayName": "frog", "displayName": "frog",
"description": "The Oracle SQL workbench for VSCode", "description": "The Oracle SQL workbench for VSCode",
"version": "0.0.9", "version": "0.0.11",
"publisher": "todie", "publisher": "todie",
"engines": { "engines": {
"vscode": "^1.17.0" "vscode": "^1.17.0"
@ -11,7 +11,7 @@
"Other" "Other"
], ],
"activationEvents": [ "activationEvents": [
"onCommand:extension.executeSnippet", "onCommand:frog.executeSnippet",
"onLanguage:plsql", "onLanguage:plsql",
"onView:connections" "onView:connections"
], ],
@ -19,7 +19,7 @@
"contributes": { "contributes": {
"commands": [ "commands": [
{ {
"command": "extension.executeSnippet", "command": "frog.executeSnippet",
"title": "Execute SQL Snippet" "title": "Execute SQL Snippet"
}, },
{ {
@ -28,10 +28,9 @@
} }
], ],
"keybindings": [{ "keybindings": [{
"command": "extension.executeSnippet", "command": "frog.executeSnippet",
"key": "ctrl+enter", "key": "ctrl+enter",
"mac": "ctrl+enter", "mac": "ctrl+enter"
"when": "editorHasSelection"
}], }],
"views": { "views": {
"explorer": [ "explorer": [
@ -56,7 +55,7 @@
{ {
"language": "frog-runner", "language": "frog-runner",
"scopeName": "code.log", "scopeName": "code.log",
"path": "./src/frog-runner.tmLanguage" "path": "./syntaxes/frog-runner.tmLanguage"
} }
] ]
}, },

@ -0,0 +1,34 @@
import * as vscode from 'vscode';
export class BlockDetector {
constructor(private editor : vscode.TextEditor) {
}
public detect() {
const position = this.editor.selection.active;
const doc = this.editor.document;
let startLine = doc.lineAt(position.line-1);
let endLine = doc.lineAt(position.line);
while (!startLine.isEmptyOrWhitespace && startLine.lineNumber > 0) {
startLine = doc.lineAt(startLine.lineNumber-1)
}
if (startLine.isEmptyOrWhitespace) {
startLine = doc.lineAt(startLine.lineNumber+1)
}
let createMatch = startLine.text.match(/create\s+(or\s+replace\s+)?(\w+)\s+(\S+)/)
if (createMatch) {
while (!endLine.text.match("end " + createMatch[3] + ";") && endLine.lineNumber < doc.lineCount-1) {
endLine = this.editor.document.lineAt(endLine.lineNumber+1)
}
} else {
while (!endLine.text.match(/;/) && endLine.lineNumber < doc.lineCount-1) {
endLine = this.editor.document.lineAt(startLine.lineNumber+1)
}
}
this.editor.selection = new vscode.Selection(new vscode.Position(startLine.lineNumber, 0), new vscode.Position(endLine.lineNumber, endLine.text.length))
}
}

@ -4,6 +4,7 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { ConnectionProvider, ConnectionNode } from './connections' import { ConnectionProvider, ConnectionNode } from './connections'
import { TextDocumentContentProvider } from './resultsetview' import { TextDocumentContentProvider } from './resultsetview'
import { BlockDetector } from './editorsupport'
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const extensionName = "frog"; const extensionName = "frog";
@ -38,9 +39,8 @@ export function activate(context: vscode.ExtensionContext) {
// This line of code will only be executed once when your extension is activated // This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "frog" is now active!'); console.log('Congratulations, your extension "frog" is now active!');
let disposable = vscode.commands.registerCommand('extension.executeSnippet', () => { let disposable = vscode.commands.registerCommand('frog.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;
@ -48,9 +48,11 @@ export function activate(context: vscode.ExtensionContext) {
let selection = editor.selection; let selection = editor.selection;
if (selection.isEmpty) return; if (selection.isEmpty) {
new BlockDetector(editor).detect();
}
let text = editor.document.getText(selection); let text = editor.document.getText(editor.selection);
if (!dbSession) { if (!dbSession) {
if (!currentConnection) { if (!currentConnection) {

Loading…
Cancel
Save