fix(editor): show gutter run button for statements with leading whitespace (#2729)

Co-authored-by: zipg <4047349+zipg@users.noreply.github.com>
This commit is contained in:
zipgandzipg authored and GitHub committed 2026-07-07 10:53:27 +08:00
1 parent df1f53acb8
commit 6efe1797a3
2 files changed
+27 -2

No files matched your search

@@ -27,6 +27,25 @@ describe("executableStatementRangeCacheForDoc", () => {
expect(executableStatementRangeStartingAt(cache, secondStatementLine.from)?.sql).toBe("SELECT *\nFROM menus AS mn\nLIMIT 100");
});
it("resolves statements with leading whitespace for gutter run buttons", () => {
const doc = Text.of([" SELECT 1;", " SELECT 2;", "\t SELECT 3;", "", " "]);
const cache = executableStatementRangeCacheForDoc(null, doc, "mysql");
expect(executableStatementRangeStartingAt(cache, doc.line(1).from)?.sql).toBe("SELECT 1");
expect(executableStatementRangeStartingAt(cache, doc.line(2).from)?.sql).toBe("SELECT 2");
expect(executableStatementRangeStartingAt(cache, doc.line(3).from)?.sql).toBe("SELECT 3");
expect(executableStatementRangeStartingAt(cache, doc.line(4).from)).toBeNull();
expect(executableStatementRangeStartingAt(cache, doc.line(5).from)).toBeNull();
});
it("does not resolve gutter run buttons when non-whitespace precedes the statement on the same line", () => {
const doc = Text.of(["/* comment */ SELECT 1;"]);
const cache = executableStatementRangeCacheForDoc(null, doc, "mysql");
expect(executableStatementRangeStartingAt(cache, doc.line(1).from)).toBeNull();
expect(executableStatementRangeStartingAt(cache, doc.toString().indexOf("SELECT"))?.sql).toBe("SELECT 1");
});
it("resolves the current statement from a cursor inside a continuation line", () => {
const doc = Text.of(["SELECT *", "FROM apis AS ap", "LIMIT 100;", "", "SELECT *", "FROM menus AS mn", "LIMIT 100;"]);
const cache = executableStatementRangeCacheForDoc(null, doc, "mysql");