Block detection
This commit is contained in:
13
package.json
13
package.json
@@ -2,7 +2,7 @@
|
||||
"name": "frog",
|
||||
"displayName": "frog",
|
||||
"description": "The Oracle SQL workbench for VSCode",
|
||||
"version": "0.0.9",
|
||||
"version": "0.0.11",
|
||||
"publisher": "todie",
|
||||
"engines": {
|
||||
"vscode": "^1.17.0"
|
||||
@@ -11,7 +11,7 @@
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:extension.executeSnippet",
|
||||
"onCommand:frog.executeSnippet",
|
||||
"onLanguage:plsql",
|
||||
"onView:connections"
|
||||
],
|
||||
@@ -19,7 +19,7 @@
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.executeSnippet",
|
||||
"command": "frog.executeSnippet",
|
||||
"title": "Execute SQL Snippet"
|
||||
},
|
||||
{
|
||||
@@ -28,10 +28,9 @@
|
||||
}
|
||||
],
|
||||
"keybindings": [{
|
||||
"command": "extension.executeSnippet",
|
||||
"command": "frog.executeSnippet",
|
||||
"key": "ctrl+enter",
|
||||
"mac": "ctrl+enter",
|
||||
"when": "editorHasSelection"
|
||||
"mac": "ctrl+enter"
|
||||
}],
|
||||
"views": {
|
||||
"explorer": [
|
||||
@@ -56,7 +55,7 @@
|
||||
{
|
||||
"language": "frog-runner",
|
||||
"scopeName": "code.log",
|
||||
"path": "./src/frog-runner.tmLanguage"
|
||||
"path": "./syntaxes/frog-runner.tmLanguage"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
34
src/editorsupport.ts
Normal file
34
src/editorsupport.ts
Normal file
@@ -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 { ConnectionProvider, ConnectionNode } from './connections'
|
||||
import { TextDocumentContentProvider } from './resultsetview'
|
||||
import { BlockDetector } from './editorsupport'
|
||||
|
||||
const { spawn } = require('child_process');
|
||||
const extensionName = "frog";
|
||||
@@ -38,19 +39,20 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// This line of code will only be executed once when your extension is activated
|
||||
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
|
||||
|
||||
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (!editor) return;
|
||||
|
||||
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 (!currentConnection) {
|
||||
|
Reference in New Issue
Block a user