fix(editor): tokenize t-sql temp table names for highlighting

Closes #8267
This commit is contained in:
t8y2 committed 2026-09-06 10:18:37 +08:00
1 parent c0390bff16
commit 27369a40dd
2 files changed
+23

No files matched your search

@@ -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"];
@@ -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: '"`',