mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 10:16:03 +00:00
trim positions in current query detection
This commit is contained in:
@@ -30,9 +30,7 @@ export interface SplitLineContext extends SplitStreamContext {
|
|||||||
// semicolonKeyTokenRegex: RegExp;
|
// semicolonKeyTokenRegex: RegExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SplitResultItem =
|
export interface SplitResultItemRich {
|
||||||
| string
|
|
||||||
| {
|
|
||||||
text: string;
|
text: string;
|
||||||
startPosition: number;
|
startPosition: number;
|
||||||
endPosition: number;
|
endPosition: number;
|
||||||
@@ -40,7 +38,9 @@ export type SplitResultItem =
|
|||||||
startColumn: number;
|
startColumn: number;
|
||||||
endLine: number;
|
endLine: number;
|
||||||
endColumn: number;
|
endColumn: number;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export type SplitResultItem = string | SplitResultItemRich;
|
||||||
|
|
||||||
function movePosition(context: SplitLineContext, count: number) {
|
function movePosition(context: SplitLineContext, count: number) {
|
||||||
if (context.options.returnRichInfo) {
|
if (context.options.returnRichInfo) {
|
||||||
@@ -208,7 +208,8 @@ function pushQuery(context: SplitLineContext) {
|
|||||||
const trimmed = sql.trim();
|
const trimmed = sql.trim();
|
||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
if (context.options.returnRichInfo) {
|
if (context.options.returnRichInfo) {
|
||||||
context.pushOutput({
|
context.pushOutput(
|
||||||
|
trimPositions(sql, {
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
|
|
||||||
startPosition: context.commandStartPosition,
|
startPosition: context.commandStartPosition,
|
||||||
@@ -218,13 +219,31 @@ function pushQuery(context: SplitLineContext) {
|
|||||||
endPosition: context.streamPosition,
|
endPosition: context.streamPosition,
|
||||||
endLine: context.line,
|
endLine: context.line,
|
||||||
endColumn: context.column,
|
endColumn: context.column,
|
||||||
});
|
})
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
context.pushOutput(trimmed);
|
context.pushOutput(trimmed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trimPositions(full: string, positions: SplitResultItemRich): SplitResultItemRich {
|
||||||
|
const startIndex = full.indexOf(positions.text);
|
||||||
|
const res = { ...positions };
|
||||||
|
for (let i = 0; i < startIndex; i += 1) {
|
||||||
|
if (full[i] == '\n') {
|
||||||
|
res.startPosition += 1;
|
||||||
|
res.startLine += 1;
|
||||||
|
res.startColumn = 0;
|
||||||
|
} else {
|
||||||
|
res.startPosition += 1;
|
||||||
|
res.startColumn += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
function markStartCommand(context: SplitLineContext) {
|
function markStartCommand(context: SplitLineContext) {
|
||||||
if (context.options.returnRichInfo) {
|
if (context.options.returnRichInfo) {
|
||||||
context.commandStartPosition = context.streamPosition;
|
context.commandStartPosition = context.streamPosition;
|
||||||
@@ -299,7 +318,8 @@ export function finishSplitStream(context: SplitStreamContext) {
|
|||||||
const trimmed = context.commandPart.trim();
|
const trimmed = context.commandPart.trim();
|
||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
if (context.options.returnRichInfo) {
|
if (context.options.returnRichInfo) {
|
||||||
context.pushOutput({
|
context.pushOutput(
|
||||||
|
trimPositions(context.commandPart, {
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
startPosition: context.commandStartPosition,
|
startPosition: context.commandStartPosition,
|
||||||
startLine: context.commandStartLine,
|
startLine: context.commandStartLine,
|
||||||
@@ -307,7 +327,8 @@ export function finishSplitStream(context: SplitStreamContext) {
|
|||||||
endPosition: context.streamPosition,
|
endPosition: context.streamPosition,
|
||||||
endLine: context.line,
|
endLine: context.line,
|
||||||
endColumn: context.column,
|
endColumn: context.column,
|
||||||
});
|
})
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
context.pushOutput(trimmed);
|
context.pushOutput(trimmed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,9 +111,9 @@ test('count lines', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table2`',
|
text: 'SELECT * FROM `table2`',
|
||||||
|
|
||||||
startPosition: 23,
|
startPosition: 24,
|
||||||
startLine: 0,
|
startLine: 1,
|
||||||
startColumn: 23,
|
startColumn: 0,
|
||||||
|
|
||||||
endPosition: 46,
|
endPosition: 46,
|
||||||
endLine: 1,
|
endLine: 1,
|
||||||
@@ -144,9 +144,9 @@ test('count lines with flush', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table2`',
|
text: 'SELECT * FROM `table2`',
|
||||||
|
|
||||||
startPosition: 23,
|
startPosition: 24,
|
||||||
startLine: 0,
|
startLine: 1,
|
||||||
startColumn: 23,
|
startColumn: 0,
|
||||||
|
|
||||||
endPosition: 46,
|
endPosition: 46,
|
||||||
endLine: 1,
|
endLine: 1,
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
import { findEngineDriver } from 'dbgate-tools';
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
import AceEditor from '../query/AceEditor.svelte';
|
import AceEditor from '../query/AceEditor.svelte';
|
||||||
import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte';
|
import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte';
|
||||||
|
import { showSnackbarError } from '../utility/snackbar';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
export let conid;
|
export let conid;
|
||||||
@@ -139,6 +140,11 @@
|
|||||||
|
|
||||||
async function executeCore(sql) {
|
async function executeCore(sql) {
|
||||||
if (busy) return;
|
if (busy) return;
|
||||||
|
if (!sql || !sql.trim()) {
|
||||||
|
showSnackbarError('Skipped executing empty query');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
executeNumber++;
|
executeNumber++;
|
||||||
visibleResultTabs = true;
|
visibleResultTabs = true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user