mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 12:33:58 +00:00
split query rich result refactor
This commit is contained in:
@@ -30,14 +30,16 @@ export interface SplitLineContext extends SplitStreamContext {
|
|||||||
// semicolonKeyTokenRegex: RegExp;
|
// semicolonKeyTokenRegex: RegExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SplitPositionDefinition {
|
||||||
|
position: number;
|
||||||
|
line: number;
|
||||||
|
column: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SplitResultItemRich {
|
export interface SplitResultItemRich {
|
||||||
text: string;
|
text: string;
|
||||||
startPosition: number;
|
start: SplitPositionDefinition;
|
||||||
endPosition: number;
|
end: SplitPositionDefinition;
|
||||||
startLine: number;
|
|
||||||
startColumn: number;
|
|
||||||
endLine: number;
|
|
||||||
endColumn: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SplitResultItem = string | SplitResultItemRich;
|
export type SplitResultItem = string | SplitResultItemRich;
|
||||||
@@ -212,13 +214,17 @@ function pushQuery(context: SplitLineContext) {
|
|||||||
trimPositions(sql, {
|
trimPositions(sql, {
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
|
|
||||||
startPosition: context.commandStartPosition,
|
start: {
|
||||||
startLine: context.commandStartLine,
|
position: context.commandStartPosition,
|
||||||
startColumn: context.commandStartColumn,
|
line: context.commandStartLine,
|
||||||
|
column: context.commandStartColumn,
|
||||||
|
},
|
||||||
|
|
||||||
endPosition: context.streamPosition,
|
end: {
|
||||||
endLine: context.line,
|
position: context.streamPosition,
|
||||||
endColumn: context.column,
|
line: context.line,
|
||||||
|
column: context.column,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -229,15 +235,20 @@ function pushQuery(context: SplitLineContext) {
|
|||||||
|
|
||||||
function trimPositions(full: string, positions: SplitResultItemRich): SplitResultItemRich {
|
function trimPositions(full: string, positions: SplitResultItemRich): SplitResultItemRich {
|
||||||
const startIndex = full.indexOf(positions.text);
|
const startIndex = full.indexOf(positions.text);
|
||||||
const res = { ...positions };
|
const res = {
|
||||||
|
...positions,
|
||||||
|
start: {
|
||||||
|
...positions.start,
|
||||||
|
},
|
||||||
|
};
|
||||||
for (let i = 0; i < startIndex; i += 1) {
|
for (let i = 0; i < startIndex; i += 1) {
|
||||||
if (full[i] == '\n') {
|
if (full[i] == '\n') {
|
||||||
res.startPosition += 1;
|
res.start.position += 1;
|
||||||
res.startLine += 1;
|
res.start.line += 1;
|
||||||
res.startColumn = 0;
|
res.start.column = 0;
|
||||||
} else {
|
} else {
|
||||||
res.startPosition += 1;
|
res.start.position += 1;
|
||||||
res.startColumn += 1;
|
res.start.column += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,12 +332,18 @@ export function finishSplitStream(context: SplitStreamContext) {
|
|||||||
context.pushOutput(
|
context.pushOutput(
|
||||||
trimPositions(context.commandPart, {
|
trimPositions(context.commandPart, {
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
startPosition: context.commandStartPosition,
|
|
||||||
startLine: context.commandStartLine,
|
start: {
|
||||||
startColumn: context.commandStartColumn,
|
position: context.commandStartPosition,
|
||||||
endPosition: context.streamPosition,
|
line: context.commandStartLine,
|
||||||
endLine: context.line,
|
column: context.commandStartColumn,
|
||||||
endColumn: context.column,
|
},
|
||||||
|
|
||||||
|
end: {
|
||||||
|
position: context.streamPosition,
|
||||||
|
line: context.line,
|
||||||
|
column: context.column,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -100,24 +100,32 @@ test('count lines', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table1`',
|
text: 'SELECT * FROM `table1`',
|
||||||
|
|
||||||
startPosition: 0,
|
start: expect.objectContaining({
|
||||||
startLine: 0,
|
position: 0,
|
||||||
startColumn: 0,
|
line: 0,
|
||||||
|
column: 0,
|
||||||
|
}),
|
||||||
|
|
||||||
endPosition: 22,
|
end: expect.objectContaining({
|
||||||
endLine: 0,
|
position: 22,
|
||||||
endColumn: 22,
|
line: 0,
|
||||||
|
column: 22,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table2`',
|
text: 'SELECT * FROM `table2`',
|
||||||
|
|
||||||
startPosition: 24,
|
start: expect.objectContaining({
|
||||||
startLine: 1,
|
position: 24,
|
||||||
startColumn: 0,
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}),
|
||||||
|
|
||||||
endPosition: 46,
|
end: expect.objectContaining({
|
||||||
endLine: 1,
|
position: 46,
|
||||||
endColumn: 22,
|
line: 1,
|
||||||
|
column: 22,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@@ -133,24 +141,32 @@ test('count lines with flush', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table1`',
|
text: 'SELECT * FROM `table1`',
|
||||||
|
|
||||||
startPosition: 0,
|
start: expect.objectContaining({
|
||||||
startLine: 0,
|
position: 0,
|
||||||
startColumn: 0,
|
line: 0,
|
||||||
|
column: 0,
|
||||||
|
}),
|
||||||
|
|
||||||
endPosition: 22,
|
end: expect.objectContaining({
|
||||||
endLine: 0,
|
position: 22,
|
||||||
endColumn: 22,
|
line: 0,
|
||||||
|
column: 22,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
text: 'SELECT * FROM `table2`',
|
text: 'SELECT * FROM `table2`',
|
||||||
|
|
||||||
startPosition: 24,
|
start: expect.objectContaining({
|
||||||
startLine: 1,
|
position: 24,
|
||||||
startColumn: 0,
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}),
|
||||||
|
|
||||||
endPosition: 46,
|
end: expect.objectContaining({
|
||||||
endLine: 1,
|
position: 46,
|
||||||
endColumn: 22,
|
line: 1,
|
||||||
|
column: 22,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -181,8 +181,8 @@
|
|||||||
const cursor = selectionRange.start;
|
const cursor = selectionRange.start;
|
||||||
const part = queryParts.find(
|
const part = queryParts.find(
|
||||||
x =>
|
x =>
|
||||||
((cursor.row == x.startLine && cursor.column >= x.startColumn) || cursor.row > x.startLine) &&
|
((cursor.row == x.start.line && cursor.column >= x.start.column) || cursor.row > x.start.line) &&
|
||||||
((cursor.row == x.endLine && cursor.column <= x.endColumn) || cursor.row < x.endLine)
|
((cursor.row == x.end.line && cursor.column <= x.end.column) || cursor.row < x.end.line)
|
||||||
);
|
);
|
||||||
if (part?.text != currentPart?.text) {
|
if (part?.text != currentPart?.text) {
|
||||||
removeCurrentPartMarker();
|
removeCurrentPartMarker();
|
||||||
@@ -192,7 +192,7 @@
|
|||||||
currentPartMarker = editor
|
currentPartMarker = editor
|
||||||
.getSession()
|
.getSession()
|
||||||
.addMarker(
|
.addMarker(
|
||||||
new ace.Range(currentPart.startLine, currentPart.startColumn, currentPart.endLine, currentPart.endColumn),
|
new ace.Range(currentPart.start.line, currentPart.start.column, currentPart.end.line, currentPart.end.column),
|
||||||
'ace_active-line',
|
'ace_active-line',
|
||||||
'text'
|
'text'
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user