diff --git a/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts b/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts index bac2a5779c..81e7561109 100644 --- a/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts +++ b/apps/desktop/src/lib/__tests__/editor/codemirrorSqlDialect.spec.ts @@ -68,6 +68,24 @@ describe("codemirrorSqlDialect", () => { expect(nodeNameAt(dialect, "SELECT GETDATE()", "GETDATE")).toBe("Builtin"); }); + it("tokenizes T-SQL temp table names instead of erroring on the hash (#8267)", () => { + const dialect = createDbxCodeMirrorSqlDialect(langSql, "sqlserver", "sqlserver"); + const statement = "select * into #GH_GHMXK from ##global_temp where b.jssjh = @sjh"; + + // `#`/`##` prefixes used to fall through to a parser error token, leaving + // temp table names unhighlighted; they share the SpecialVar channel with + // @@variables, whose scanner handles the doubled prefix natively. + expect(nodeNameAt(dialect, statement, "#GH_GHMXK")).toBe("SpecialVar"); + expect(nodeNameAt(dialect, statement, "##global_temp")).toBe("SpecialVar"); + expect(nodeNameAt(dialect, statement, "@sjh")).toBe("SpecialVar"); + expect(nodeNameAt(dialect, statement, "select")).toBe("Keyword"); + expect(nodeNameAt(dialect, statement, "into")).toBe("Keyword"); + + // MySQL keeps interpreting `#` as a line comment — its dialect is untouched. + const mysql = createDbxCodeMirrorSqlDialect(langSql, "mysql", "mysql"); + expect(nodeNameAt(mysql, "SELECT a FROM t -- x\nWHERE b = 1", "WHERE")).toBe("Keyword"); + }); + it("keeps double quotes as identifier delimiters for Oracle-family dialects", () => { const databaseTypes: DatabaseType[] = ["oracle", "dameng", "yashandb", "oscar", "oceanbase-oracle"]; diff --git a/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts b/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts index 161390abae..3d0d92d8d9 100644 --- a/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts +++ b/apps/desktop/src/lib/editor/codemirrorSqlDialect.ts @@ -247,6 +247,11 @@ export function createDbxCodeMirrorSqlDialect(langSql: CodeMirrorSqlLanguageModu keywords: [baseKeywords, commonKeywords, isClickHouse ? CLICKHOUSE_KEYWORDS : "", isPostgres ? POSTGRES_PLPGSQL_KEYWORDS : "", isSqlServer ? SQLSERVER_KEYWORDS : ""].filter(Boolean).join(" "), types: [baseTypes, isClickHouse ? CLICKHOUSE_TYPES : "", isPostgres ? POSTGRES_PLPGSQL_TYPES : ""].filter(Boolean).join(" ") || undefined, builtin: [baseBuiltin, isClickHouse ? CLICKHOUSE_BUILTINS : "", isPostgres ? `${POSTGRES_BUILTINS} ${POSTGRES_PLPGSQL_BUILTIN}` : "", isMysql ? MYSQL_BUILTINS : "", driverProfileSqlBuiltinTerms(driverProfile)].filter(Boolean).join(" ") || undefined, + // T-SQL temp tables (#local / ##global) otherwise tokenize the leading + // `#` as a parser error, breaking highlighting for the whole name. The + // specialVar scanner natively handles the doubled prefix and already + // covers @@variables, so # joins the same channel for SQL Server (#8267). + ...(isSqlServer ? { specialVar: `${baseDialect.spec.specialVar ?? ""}#` } : {}), ...(isClickHouse ? { identifierQuotes: '"`',