Block detection
This commit is contained in:
		
							
								
								
									
										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,9 +39,8 @@ 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;
 | 
			
		||||
 | 
			
		||||
@@ -48,9 +48,11 @@ export function activate(context: vscode.ExtensionContext) {
 | 
			
		||||
 | 
			
		||||
        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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,50 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 | 
			
		||||
<plist version="1.0">
 | 
			
		||||
    <dict>
 | 
			
		||||
        <key>scopeName</key>
 | 
			
		||||
        <string>code.log</string>
 | 
			
		||||
        <key>fileTypes</key>
 | 
			
		||||
        <array>
 | 
			
		||||
            <string>log</string>
 | 
			
		||||
        </array>
 | 
			
		||||
        <key>name</key>
 | 
			
		||||
        <string>frog-runner</string>
 | 
			
		||||
        <key>patterns</key>
 | 
			
		||||
        <array>
 | 
			
		||||
            <dict>
 | 
			
		||||
                <!-- Date lines -->
 | 
			
		||||
                <key>match</key>
 | 
			
		||||
                <string>--.*</string>
 | 
			
		||||
                <key>name</key>
 | 
			
		||||
                <string>string.quoted</string>
 | 
			
		||||
            </dict>
 | 
			
		||||
            <dict>
 | 
			
		||||
                <key>match</key>
 | 
			
		||||
                <string>Query successful.</string>
 | 
			
		||||
                <key>name</key>
 | 
			
		||||
                <string>keyword</string>
 | 
			
		||||
            </dict>
 | 
			
		||||
            <dict>
 | 
			
		||||
                <key>match</key>
 | 
			
		||||
                <string>Exception.*</string>
 | 
			
		||||
                <key>name</key>
 | 
			
		||||
                <string>invalid.illegal</string>
 | 
			
		||||
            </dict>
 | 
			
		||||
            <dict>
 | 
			
		||||
                <key>match</key>
 | 
			
		||||
                <string>Errors found:.*</string>
 | 
			
		||||
                <key>name</key>
 | 
			
		||||
                <string>invalid.illegal</string>
 | 
			
		||||
            </dict>
 | 
			
		||||
            <dict>
 | 
			
		||||
                <key>match</key>
 | 
			
		||||
                <string>^\d+:.*</string>
 | 
			
		||||
                <key>name</key>
 | 
			
		||||
                <string>invalid.illegal</string>
 | 
			
		||||
            </dict>
 | 
			
		||||
        </array>
 | 
			
		||||
        <key>uuid</key>
 | 
			
		||||
        <string>648a6fba-bf11-11e7-abc4-cec278b6b50a</string>
 | 
			
		||||
    </dict>
 | 
			
		||||
</plist>
 | 
			
		||||
		Reference in New Issue
	
	Block a user