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