fix(database): colour quoted identifiers as names in DuckDB and Snowflake consoles (#7260)

The DuckDB and Snowflake console dialects are built from lang-sql directly, which tags QuotedIdentifier like a string, so "schema"."table" was still painted in the string colour there after #7255 fixed the plain SQL mode. Both dialects now restyle QuotedIdentifier as a name.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-01 23:08:39 +08:00
1 джерело 63c2ced086
коміт b85027dc47
4 files changed
+61 -23

No files matched your search

+25 -22
Переглянути файл
@@ -1,31 +1,34 @@
import { SQLDialect } from "@codemirror/lang-sql";
import type { LRLanguage } from "@codemirror/language";
import { quotedIdentifiersAsNames } from "./quotedIdentifiers";
import { CLAUSE_WORDS, DATA_TYPES, functions, predicateKeywords, statementStarters } from "./dialect";
let language: LRLanguage | undefined;
/** Token colouring for DuckDB; scope and completion come from the SQL editor. */
export function duckdbLanguage(): LRLanguage {
return (language ??= SQLDialect.define({
keywords: [
...CLAUSE_WORDS,
...statementStarters("duckdb"),
...predicateKeywords("duckdb"),
"ASOF ANTI SEMI EXCLUDE REPLACE RENAME COLUMNS QUALIFY OVER PARTITION FILTER NULLS FIRST LAST",
"IF RECURSIVE DESCRIBE SUMMARIZE COMMENT INSTALL LOAD EXPORT IMPORT PRAGMA RESET VACUUM",
"SAMPLE REPEATABLE PERCENT ROWS MATERIALIZED TEMPORARY LAMBDA TRY_CAST AT TIME ZONE",
]
.join(" ")
.toLowerCase(),
types: DATA_TYPES.duckdb
.filter((type) => type !== "UNION")
.join(" ")
.toLowerCase(),
builtin: functions("duckdb")
.map((f) => f.name)
.join(" "),
caseInsensitiveIdentifiers: true,
doubleDollarQuotedStrings: true,
specialVar: "?$",
}).language);
return (language ??= quotedIdentifiersAsNames(
SQLDialect.define({
keywords: [
...CLAUSE_WORDS,
...statementStarters("duckdb"),
...predicateKeywords("duckdb"),
"ASOF ANTI SEMI EXCLUDE REPLACE RENAME COLUMNS QUALIFY OVER PARTITION FILTER NULLS FIRST LAST",
"IF RECURSIVE DESCRIBE SUMMARIZE COMMENT INSTALL LOAD EXPORT IMPORT PRAGMA RESET VACUUM",
"SAMPLE REPEATABLE PERCENT ROWS MATERIALIZED TEMPORARY LAMBDA TRY_CAST AT TIME ZONE",
]
.join(" ")
.toLowerCase(),
types: DATA_TYPES.duckdb
.filter((type) => type !== "UNION")
.join(" ")
.toLowerCase(),
builtin: functions("duckdb")
.map((f) => f.name)
.join(" "),
caseInsensitiveIdentifiers: true,
doubleDollarQuotedStrings: true,
specialVar: "?$",
}).language,
));
}
+27
Переглянути файл
@@ -0,0 +1,27 @@
import { highlightTree, tagHighlighter, tags as t } from "@lezer/highlight";
import { describe, expect, it } from "vitest";
import { duckdbLanguage } from "./duckdbHighlight";
import { snowflakeLanguage } from "./snowflakeHighlight";
function coloured(language: ReturnType<typeof duckdbLanguage>, doc: string): string[] {
const found: string[] = [];
highlightTree(
language.parser.parse(doc),
tagHighlighter([
{ tag: t.name, class: "name" },
{ tag: t.string, class: "string" },
]),
(from, to, cls) => found.push(`${cls}:${doc.slice(from, to)}`),
);
return found;
}
describe("quoted identifiers in dialect consoles", () => {
const doc = `SELECT "id" FROM "public"."t" WHERE 1 = 'a'`;
it.each([
["DuckDB", duckdbLanguage],
["Snowflake", snowflakeLanguage],
])("%s colours them as names and literals as strings", (_name, language) => {
expect(coloured(language(), doc)).toEqual(['name:"id"', 'name:"public"', 'name:"t"', "string:'a'"]);
});
});
+7
Переглянути файл
@@ -0,0 +1,7 @@
import { styleTags, tags as t } from "@lezer/highlight";
import type { LRLanguage } from "@codemirror/language";
/** lang-sql tags `"schema"."table"` like a string; in SQL it names a schema, table or column. */
export function quotedIdentifiersAsNames(language: LRLanguage): LRLanguage {
return language.configure({ props: [styleTags({ QuotedIdentifier: t.name })] });
}
+2 -1
Переглянути файл
@@ -7,6 +7,7 @@ import { SQLDialect } from "@codemirror/lang-sql";
import type { LRLanguage } from "@codemirror/language";
import { ExternalTokenizer, type InputStream, type LRParser, type Stack } from "@lezer/lr";
import { DATA_TYPES, functions } from "./dialect";
import { quotedIdentifiersAsNames } from "./quotedIdentifiers";
import { SNOWFLAKE_KEYWORDS } from "./snowflakeKeywords";
/** A grammar tokenizer as the parser calls it. */
@@ -69,5 +70,5 @@ let built: LRLanguage | undefined;
/** The Snowflake SQL language (built on first use). */
export function snowflakeLanguage(): LRLanguage {
return (built ??= build());
return (built ??= quotedIdentifiersAsNames(build()));
}