Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

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

t8y227369a40dd3e
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: '"`',