Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.08 KB

README.md

File metadata and controls

43 lines (31 loc) · 1.08 KB

@tidbcloud/codemirror-extension-cur-sql

A codemirror extension listens the editor selection change, returns the complete SQL statements around the cursor position.

This extension is installed internally inside the SQLEditorInstance.

Installation

npm install @tidbcloud/codemirror-extension-cur-sql

You need to install its dependencies as well:

npm install @codemirror/view @codemirror/state @codemirror/language @codemirror/lang-sql @tidbcloud/codemirror-extension-sql-parser

Usage

import { EditorView } from '@codemirror/view'
import { EditorState } from '@codemirror/state'
import { sql, MySQL } from '@codemirror/lang-sql'
import { sqlParser } from '@tidbcloud/codemirror-extension-sql-parser'
import { curSql } from '@tidbcloud/codemirror-extension-cur-sql'

const editorView = new EditorView({
  state: EditorState.create({
    doc,
    extensions: [sql({ dialect: MySQL }), sqlParser(), curSql()]
  })
})

API

/* get selected statements */
function getCurStatements(state: EditorState): SqlStatement[]

function curSql(): Extension