дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
Query consoles stay in <dataDir>/consoles/db; the database feature registers that folder as a Database Consoles root in the Project view's Scratches and Consoles scope, re-registered when a remote session starts or ends. Console folders show the data source's name and icon ("Orders", "Orders: sales") through new display-only label/icon file decorations, which also order siblings when sorting by name. Consoles announce their creation so the tree refreshes, deleted console files close their editors, and a console's data source is recovered from its path when the binding is missing.
Co-authored-by: wangyuewen-china <[email protected]>
60 рядки
2.7 KiB
TypeScript
60 рядки
2.7 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { useProject } from "@/platform/project";
|
|
import { resolutionScopeOf, validateResolutionScopes } from "./resolutionScopes";
|
|
import { bindConsole, consoleSchema, consoleSource, useDatabase } from "./store";
|
|
|
|
const scopes = validateResolutionScopes([
|
|
{ path: "", dataSource: "main", schema: "" },
|
|
{ path: "./src/main/resources/mapper/", dataSource: "orders", schema: "sales" },
|
|
{ path: "src/main/resources/mapper/legacy/Old.xml", dataSource: "legacy", schema: "" },
|
|
{ path: "src/gone", dataSource: "removed", schema: "" },
|
|
]);
|
|
|
|
describe("SQL resolution scopes", () => {
|
|
it("normalises paths and picks the deepest folder or file covering a file, else the project row", () => {
|
|
expect(scopes[1]!.path).toBe("src/main/resources/mapper");
|
|
const at = (rel: string) => resolutionScopeOf(`/p/${rel}`, "/p", scopes)?.dataSource;
|
|
expect(at("src/main/resources/mapper/UserMapper.xml")).toBe("orders");
|
|
expect(at("src/main/resources/mapper/legacy/Old.xml")).toBe("legacy");
|
|
expect(at("src/main/resources/mapper/legacy/New.xml")).toBe("orders");
|
|
// A sibling folder whose name starts the same is not inside.
|
|
expect(at("src/main/resources/mapperx/A.xml")).toBe("main");
|
|
expect(resolutionScopeOf("/elsewhere/a.sql", "/p", scopes)).toBeNull();
|
|
});
|
|
|
|
it("skips rows whose data source no longer exists", () => {
|
|
const known = (id: string) => id !== "removed";
|
|
expect(resolutionScopeOf("/p/src/gone/a.sql", "/p", scopes, known)?.dataSource).toBe("main");
|
|
});
|
|
});
|
|
|
|
describe("the data source a SQL file resolves against", () => {
|
|
beforeEach(() => {
|
|
useProject.setState({
|
|
project: { name: "p", root: "/p", trusted: true } as never,
|
|
settings: { database: { resolutionScopes: scopes } } as never,
|
|
});
|
|
useDatabase.setState({
|
|
sources: ["main", "orders", "legacy"].map((id) => ({ id, name: id, driver: "postgres" as const })),
|
|
consoles: {},
|
|
consoleSchemas: {},
|
|
completion: { orders: { defaultSchema: "public", tables: [], foreignKeys: [] } },
|
|
});
|
|
});
|
|
|
|
it("is the one picked in its toolbar, else its scope's (with the scope's schema)", () => {
|
|
const file = "/p/src/main/resources/mapper/UserMapper.xml";
|
|
expect(consoleSource(file)).toBe("orders");
|
|
expect(consoleSchema(file)).toBe("sales");
|
|
bindConsole(file, "legacy");
|
|
expect(consoleSource(file)).toBe("legacy");
|
|
bindConsole(file, null);
|
|
expect(consoleSource("/p/scratch.sql")).toBe("main");
|
|
});
|
|
|
|
it("recovers a query console's data source from its path", () => {
|
|
expect(consoleSource("/data/consoles/db/orders/console.sql")).toBe("orders");
|
|
expect(consoleSource("/data/consoles/db/orders.sales/console_1.sql")).toBe("orders:sales");
|
|
});
|
|
});
|