fix(sql): keep Ctrl+Enter on current statement at trailing whitespace

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-08-07 02:56:26 +08:00
1 parent c32f92a902
commit b437c470e1
4 files changed
+177 -4

No files matched your search

@@ -103,6 +103,40 @@ describe("executableStatementRangeCacheForDoc", () => {
expect(executableStatementRangeAtCursor(cache, delimiterCursor + 1)?.sql).toBe("SELECT *\nFROM users");
});
it("resolves a trailing-whitespace cursor on a multi-line statement tail to that statement", () => {
const sql = "WITH x AS (SELECT 1)\nSELECT 2 \nSELECT 3;";
const doc = Text.of(sql.split("\n"));
const cache = executableStatementRangeCacheForDoc(null, doc, "mysql");
const contentEnd = sql.indexOf("SELECT 2") + "SELECT 2".length;
expect(executableStatementRangeAtCursor(cache, contentEnd)?.sql).toBe("WITH x AS (SELECT 1)\nSELECT 2");
expect(executableStatementRangeAtCursor(cache, contentEnd + 1)?.sql).toBe("WITH x AS (SELECT 1)\nSELECT 2");
expect(executableStatementRangeAtCursor(cache, contentEnd + 2)?.sql).toBe("WITH x AS (SELECT 1)\nSELECT 2");
});
it("keeps the simple single-line trailing-whitespace case on the current statement", () => {
const sql = "SELECT 1;\nSELECT 2 \nSELECT 3;";
const doc = Text.of(sql.split("\n"));
const cache = executableStatementRangeCacheForDoc(null, doc, "mysql");
const contentEnd = sql.indexOf("SELECT 2") + "SELECT 2".length;
expect(executableStatementRangeAtCursor(cache, contentEnd)?.sql).toBe("SELECT 2");
expect(executableStatementRangeAtCursor(cache, contentEnd + 1)?.sql).toBe("SELECT 2");
});
it("keeps a trailing-whitespace cursor on a non-final line of a multi-line statement in the frame cache", () => {
const sql = "SELECT * FROM `profiles`;\nSELECT * FROM `users` AS uu \nWHERE id = 2\nSELECT * FROM `orders`;";
const doc = Text.of(sql.split("\n"));
const cache = executableStatementRangeCacheForDoc(null, doc, "mysql");
const markerEnd = sql.indexOf("uu") + 2;
const lineEnd = sql.indexOf("\n", markerEnd);
const expected = "SELECT * FROM `users` AS uu \nWHERE id = 2";
for (let pos = markerEnd; pos < lineEnd; pos += 1) {
expect(executableStatementRangeAtCursor(cache, pos)?.sql).toBe(expected);
}
});
it("does not attach a semicolon after a blank line to the previous statement", () => {
const sql = "SELECT 1\n\n;";
const doc = Text.of(sql.split("\n"));