From ffe1e58fbbbadee43536059ba4c9078f4fd36c59 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Sat, 5 Sep 2026 09:09:01 +0800 Subject: [PATCH] fix(editor): restore keyword highlighting for standard-SQL dialects Closes #8123 --- .../editor/codemirrorSqlDialect.spec.ts | 19 +++++++++++++++++++ .../src/lib/editor/codemirrorSqlDialect.ts | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts b/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts index 2592095712..bac2a5779c 100644 --- a/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts +++ b/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts @@ -76,6 +76,25 @@ describe("codemirrorSqlDialect", () => { } }); + it("highlights core keywords for StandardSQL-based dialects (#8123)", () => { + // IRIS/Caché (and every other StandardSQL-based type) previously resolved + // with an empty keyword set, so SELECT/FROM/WHERE/AND rendered as plain + // identifiers — exactly the highlighting the #8123 report shows. + const reporterStatement = "select di.MR_ADM\nfrom SQLUser.DHCMRInfo di\nwhere di.MR_BAH = 1942487\n and di.MR_RYRQ >= '2023-01-01'"; + for (const databaseType of ["iris", "jdbc", "h2", "db2", "hive"] as DatabaseType[]) { + const dialect = createDbxCodeMirrorSqlDialect(langSql, "mysql", databaseType); + for (const keyword of ["select", "from", "where", "and"]) { + expect(nodeNameAt(dialect, reporterStatement, keyword), `${databaseType}:${keyword}`).toBe("Keyword"); + } + } + + // Standard-SQL types gain a vocabulary too, while ClickHouse keeps its + // pre-existing standard-vocabulary treatment unchanged. + expect(createDbxCodeMirrorSqlDialect(langSql, "mysql", "iris").spec.types).toBe("array binary bit boolean char character clob date decimal double float int integer interval large national nchar nclob numeric object precision real smallint time timestamp varchar varying"); + const clickhouseDialect = createDbxCodeMirrorSqlDialect(langSql, "mysql", "clickhouse"); + expect(nodeNameAt(clickhouseDialect, "SELECT x FROM t WHERE y > 1", "WHERE")).toBe("Keyword"); + }); + it("enables backslashEscapes for MySQL-family dialects and ClickHouse while keeping it disabled for standard dialects", () => { const backslashEscapesTypes: DatabaseType[] = ["mysql", "doris", "starrocks", "manticoresearch", "goldendb", "gbase", "clickhouse", "hive", "spark", "impala", "argo", "databend"]; for (const databaseType of backslashEscapesTypes) { diff --git a/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts b/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts index 798e15f888..161390abae 100644 --- a/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts +++ b/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts @@ -233,8 +233,12 @@ export function createDbxCodeMirrorSqlDialect(langSql: CodeMirrorSqlLanguageModu const isSqlServer = baseDialect === langSql.MSSQL; const isPlsql = baseDialect === langSql.PLSQL; const isClickHouse = databaseType === "clickhouse" || dialectName === "clickhouse"; - const baseKeywords = isClickHouse ? standardSqlKeywordSyntaxTerms(langSql) : isPostgres ? postgresKeywordSyntaxTerms(baseDialect.spec.keywords || "") : baseDialect.spec.keywords || ""; - const baseTypes = isClickHouse ? STANDARD_SQL_TYPES : baseDialect.spec.types || ""; + // StandardSQL.spec exposes no vocabulary, so every StandardSQL-based dialect + // (generic JDBC, IRIS/Caché, H2, DB2, …) needs the reconstructed standard + // keyword set — without it SELECT/WHERE/AND highlight as plain identifiers. + const isStandardSql = isClickHouse || baseDialect === langSql.StandardSQL; + const baseKeywords = isStandardSql ? standardSqlKeywordSyntaxTerms(langSql) : isPostgres ? postgresKeywordSyntaxTerms(baseDialect.spec.keywords || "") : baseDialect.spec.keywords || ""; + const baseTypes = isStandardSql ? STANDARD_SQL_TYPES : baseDialect.spec.types || ""; const commonKeywords = isClickHouse ? DBX_COMMON_SQL_KEYWORDS.toLowerCase() : DBX_COMMON_SQL_KEYWORDS; const baseBuiltin = isSqlServer ? sqlServerBuiltinSyntaxTerms(baseDialect.spec.builtin || "") : baseDialect.spec.builtin || "";