fix(sql-completion): improve MongoDB editor suggestions
This commit is contained in:
6 files changed
+234
-50
No files matched your search
@@ -3,6 +3,16 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { executableStatementRangeAtCursor, executableStatementRangeCacheForDoc, executableStatementRangeStartingAt, type ExecutableStatementRangeParser } from "@/lib/sql/executableStatementRangeCache";
|
||||
|
||||
describe("executableStatementRangeCacheForDoc", () => {
|
||||
it("tracks MongoDB commands for current-statement framing", () => {
|
||||
const sql = 'db.users.find({})\n\ndb.getCollection("audit.logs").countDocuments({})';
|
||||
const doc = Text.of(sql.split("\n"));
|
||||
const cache = executableStatementRangeCacheForDoc(null, doc, "mongodb");
|
||||
|
||||
expect(executableStatementRangeAtCursor(cache, sql.indexOf("users"))?.sql).toBe("db.users.find({})");
|
||||
expect(executableStatementRangeAtCursor(cache, sql.indexOf("audit.logs"))?.sql).toBe('db.getCollection("audit.logs").countDocuments({})');
|
||||
expect(executableStatementRangeAtCursor(cache, doc.line(2).from)).toBeNull();
|
||||
});
|
||||
|
||||
it("reuses parsed executable statement ranges for the same document and database type", () => {
|
||||
const doc = Text.of(["SELECT 1;", "SELECT 2;"]);
|
||||
const parse = vi.fn<ExecutableStatementRangeParser>(() => [
|
||||
|
||||
Reference in new issue
Block a user