fix(sql): preserve same-line TDSQL directives

This commit is contained in:
李子凡 authored and GitHub committed 2026-08-14 22:46:32 +08:00
1 parent a574459f8b
commit 5695ef6e77
6 files changed
+145 -39

No files matched your search

@@ -118,12 +118,12 @@ describe("executableStatementRangeCacheForDoc", () => {
expect(executableStatementRangeStartingAt(cache, doc.line(3).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;"]);
it("resolves a same-line leading TDSQL directive for gutter execution", () => {
const sql = "/*sets:allsets */ SELECT 1;";
const doc = Text.of([sql]);
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");
expect(executableStatementRangeStartingAt(cache, doc.line(1).from)?.sql).toBe(sql.slice(0, -1));
});
it("resolves the current statement from a cursor inside a continuation line", () => {
@@ -205,12 +205,13 @@ describe("executableStatementRangeCacheForDoc", () => {
expect(executableStatementRangeAtCursor(cache, doc.line(4).from)).toBeNull();
});
it("resolves SQL after a leading block comment on the same line", () => {
const doc = Text.of(["/* comment */ SELECT 1;"]);
it("preserves a same-line TDSQL directive while ignoring a cursor inside its comment", () => {
const sql = "/*sets:allsets */ SELECT 1;";
const doc = Text.of([sql]);
const cache = executableStatementRangeCacheForDoc(null, doc, "mysql");
expect(executableStatementRangeAtCursor(cache, doc.toString().indexOf("SELECT"))?.sql).toBe("SELECT 1");
expect(executableStatementRangeAtCursor(cache, doc.toString().indexOf("comment"))).toBeNull();
expect(executableStatementRangeAtCursor(cache, sql.indexOf("SELECT"))?.sql).toBe(sql.slice(0, -1));
expect(executableStatementRangeAtCursor(cache, sql.indexOf("sets"))).toBeNull();
});
it("rebuilds the cache when the document instance changes", () => {