diff --git a/src/lib/sqlCompletion.ts b/src/lib/sqlCompletion.ts index a017248201..89f487a7fd 100644 --- a/src/lib/sqlCompletion.ts +++ b/src/lib/sqlCompletion.ts @@ -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"]); diff --git a/tests/sqlCompletion.test.ts b/tests/sqlCompletion.test.ts index 41e187dd61..a3e84ff474 100644 --- a/tests/sqlCompletion.test.ts +++ b/tests/sqlCompletion.test.ts @@ -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")}`,