fix(editor): refresh SQL signatures on dialect change
This commit is contained in:
4 files changed
+51
-6
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const queryEditorSource = readFileSync(new URL("../../../components/editor/QueryEditor.vue", import.meta.url), "utf8");
|
||||
|
||||
describe("QueryEditor SQL signature refresh wiring", () => {
|
||||
it("reconfigures signature help when the database dialect changes", () => {
|
||||
expect(queryEditorSource).toContain('let sqlSignatureComp: import("@codemirror/state").Compartment | null = null;');
|
||||
expect(queryEditorSource).toContain("sqlSignatureComp.of(buildSqlSignatureExtension())");
|
||||
|
||||
const watcherStart = queryEditorSource.indexOf("watch([() => props.databaseType, () => props.dialect, () => props.syntaxDialect]");
|
||||
const watcherEnd = queryEditorSource.indexOf("\n});", watcherStart);
|
||||
const dialectWatcher = queryEditorSource.slice(watcherStart, watcherEnd);
|
||||
|
||||
expect(watcherStart).toBeGreaterThanOrEqual(0);
|
||||
expect(watcherEnd).toBeGreaterThan(watcherStart);
|
||||
expect(dialectWatcher).toContain("sqlSignatureComp.reconfigure(buildSqlSignatureExtension())");
|
||||
});
|
||||
});
|
||||
@@ -954,6 +954,7 @@ const POSTGRES_FUNCTION_SIGNATURES = new Map<string, string[]>([
|
||||
]);
|
||||
|
||||
const MYSQL_FUNCTION_SIGNATURES = new Map<string, string[]>([
|
||||
["CONVERT", ["expression", "type"]],
|
||||
["DATE_FORMAT", ["date", "format"]],
|
||||
["FROM_UNIXTIME", ["unix_timestamp"]],
|
||||
["UNIX_TIMESTAMP", []],
|
||||
@@ -975,6 +976,7 @@ const SQLITE_FUNCTION_SIGNATURES = new Map<string, string[]>([
|
||||
const CLOUDFLARE_D1_FUNCTION_SIGNATURES = new Map(Array.from(SQLITE_FUNCTION_SIGNATURES.entries()).filter(([name]) => name !== "NOW"));
|
||||
|
||||
const SQLSERVER_FUNCTION_SIGNATURES = new Map<string, string[]>([
|
||||
["CONVERT", ["type", "expression"]],
|
||||
["TRY_CAST", ["expression AS type"]],
|
||||
["TRY_CONVERT", ["type", "expression"]],
|
||||
["JSON_VALUE", ["expression", "path"]],
|
||||
@@ -1619,7 +1621,7 @@ export function getSqlCompletionResultValidFor(sql: string, cursor: number): Reg
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getSqlFunctionSignatureHelp(sql: string, cursor: number): SqlFunctionSignatureHelp | null {
|
||||
export function getSqlFunctionSignatureHelp(sql: string, cursor: number, databaseType?: DatabaseType): SqlFunctionSignatureHelp | null {
|
||||
const beforeCursor = sql.slice(0, cursor);
|
||||
const openParenIndex = findActiveFunctionOpenParen(beforeCursor);
|
||||
if (openParenIndex == null) return null;
|
||||
@@ -1628,7 +1630,7 @@ export function getSqlFunctionSignatureHelp(sql: string, cursor: number): SqlFun
|
||||
const name = /([A-Za-z_][\w$]*)$/.exec(beforeParen)?.[1]?.toUpperCase();
|
||||
if (!name) return null;
|
||||
|
||||
const parameters = SQL_FUNCTION_SIGNATURES.get(name);
|
||||
const parameters = (databaseType ? DATABASE_FUNCTION_SIGNATURES[databaseType]?.get(name) : undefined) ?? SQL_FUNCTION_SIGNATURES.get(name);
|
||||
if (!parameters) return null;
|
||||
|
||||
const activeParameter = countTopLevelCommas(beforeCursor.slice(openParenIndex + 1));
|
||||
|
||||
Reference in new issue
Block a user