Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public tokenizeModel = (
model: monacoEditor.editor.ITextModel,
cursorPos?: Position | undefined,
selection?: Selection | undefined
): Array => {
//
/**
*
* Получаем ВЕСЬ текст (editor),
* 1) Токинизируем, с разбивкой на ключевые составляющие которые нужны: KeyWords[SELECT,DELETE], TabixCommands
* 2) Определяем выделенную область после токинизации
* 3) Определяем какой текст выполнять
*/
const cursorPosition = cursorPos || new Position(0, 0);
const splitterQueryToken = 'warn-token.sql'; // Токен разбития на запросы
const splitterTabixToken = 'tabix.sql'; // Токен разбития на запросы
let countTabixCommandsInQuery: number = 0; // Кол-во tabix комманд запросе
let tokensList: any[] = [];
const tokens = globalMonaco.editor.tokenize(model.getValue(), 'clickhouse'); // ВЕСЬ текст редактора
let countQuery: number = 0; // Кол-во запросов в тексте
const splits: any[] = [];
let splitToken = {
line: 1,
offset: 1,
type: '',
language: '',
};
let previousToken = {
function getPositionAt(text: string, offset: number): monaco.IPosition {
const lines = text.split('\n')
let pos = 0
for (const [i, line] of lines.entries()) {
if (offset < pos + line.length + 1) {
return new monaco.Position(i + 1, offset - pos + 1)
}
pos += line.length + 1
}
throw new Error(`offset ${offset} out of bounds in text of length ${text.length}`)
}
function getPositionAt(text: string, offset: number): monaco.IPosition {
const lines = text.split('\n')
let pos = 0
for (const [i, line] of lines.entries()) {
if (offset < pos + line.length + 1) {
return new monaco.Position(i + 1, offset - pos + 1)
}
pos += line.length + 1
}
throw new Error(`offset ${offset} out of bounds in text of length ${text.length}`)
}
function getPositionAt(text: string, offset: number): _monaco.IPosition {
const lines = text.split('\n')
let pos = 0
let i = 0
for (const line of lines) {
if (offset < pos + line.length + 1) {
return new _monaco.Position(i + 1, offset - pos + 1)
}
pos += line.length + 1
i++
}
throw new Error(`offset ${offset} out of bounds in text of length ${text.length}`)
}
const setPosition = endCol => {
const currentPos = new Position(2, endCol);
instance.setPosition(currentPos);
};
function shiftBackOneCharacter (model, start, end) {
const range = new monaco.Range(start.lineNumber, start.column, start.lineNumber, start.column)
const unlessEqual = new monaco.Range(end.lineNumber, end.column, end.lineNumber, end.column)
if (range.equalsRange(unlessEqual)) {
return range
}
let line = range.startLineNumber
let character = range.startColumn - 1
if (character < 0) {
line -= 1
character = lineAt(model, line).range.endColumn
}
const { lineNumber, column } = new monaco.Position(line, character)
return [lineNumber, column]
}
function toMonacoPos(pos) {
return new Position(pos.line + 1, pos.ch + 1);
}