fix(sql): add sql server completions

This commit is contained in:
t8y2
2026-05-13 17:11:33 +08:00
parent 02b257dd0f
commit 80f33b1460
2 changed files with 68 additions and 0 deletions
+32
View File
@@ -42,11 +42,14 @@ const SQL_KEYWORDS = [
"THEN",
"ELSE",
"END",
"IF",
"COUNT",
"SUM",
"AVG",
"MIN",
"MAX",
"IIF",
"CHOOSE",
"COALESCE",
"CAST",
"ALTER",
@@ -129,6 +132,35 @@ const SQL_KEYWORDS = [
"SHOW",
"SUMMARIZE",
"PRAGMA",
"BIGINT",
"BINARY",
"BIT",
"CHAR",
"DATE",
"DATETIME",
"DATETIME2",
"DATETIMEOFFSET",
"DECIMAL",
"FLOAT",
"IMAGE",
"INT",
"MONEY",
"NCHAR",
"NTEXT",
"NUMERIC",
"NVARCHAR",
"REAL",
"SMALLDATETIME",
"SMALLINT",
"SMALLMONEY",
"TEXT",
"TIME",
"TIMESTAMP",
"TINYINT",
"UNIQUEIDENTIFIER",
"VARBINARY",
"VARCHAR",
"XML",
];
const TABLE_TRIGGER_KEYWORDS = new Set(["from", "join", "update", "into", "table", "describe", "explain", "apply"]);
+36
View File
@@ -123,6 +123,42 @@ test("always includes keywords alongside table suggestions", () => {
assert.ok(items.some((item) => item.type === "keyword" && item.label === "USING"));
});
test("suggests SQL Server IF keyword for conditional DDL", () => {
const sql = "DROP TABLE I";
const items = buildSqlCompletionItems(sql, sql.length, {
tables,
columnsByTable,
});
assert.ok(items.some((item) => item.type === "keyword" && item.label === "IF"));
});
test("suggests SQL Server IIF and CHOOSE scalar functions", () => {
const iifItems = buildSqlCompletionItems("SELECT II", "SELECT II".length, {
tables,
columnsByTable,
});
const chooseItems = buildSqlCompletionItems("SELECT CHO", "SELECT CHO".length, {
tables,
columnsByTable,
});
assert.ok(iifItems.some((item) => item.type === "keyword" && item.label === "IIF"));
assert.ok(chooseItems.some((item) => item.type === "keyword" && item.label === "CHOOSE"));
});
test("suggests SQL Server data types in CREATE TABLE column definitions", () => {
const sql = "CREATE TABLE dbo.jobs (id ";
const items = buildSqlCompletionItems(sql, sql.length, {
tables,
columnsByTable,
});
assert.ok(items.some((item) => item.type === "keyword" && item.label === "INT"));
assert.ok(items.some((item) => item.type === "keyword" && item.label === "BIGINT"));
assert.ok(items.some((item) => item.type === "keyword" && item.label === "NVARCHAR"));
});
test("limits table suggestions for large schemas after filtering by prefix", () => {
const largeTables: SqlCompletionTable[] = Array.from({ length: 500 }, (_, index) => ({
name: `erp_invoice_${String(index).padStart(4, "0")}`,