fix(completion): add datepart args for sqlserver date functions

This commit is contained in:
zipg authored and GitHub committed 2026-08-27 08:40:12 +08:00
1 parent 2138f59da4
commit e7191b1c4b
2 files changed
+52 -1

No files matched your search

@@ -26,6 +26,40 @@ describe("sqlCompletion keyword snippets", () => {
});
});
describe("SQL Server datepart completion", () => {
it.each(["DATEADD", "DATEDIFF", "DATEPART", "DATENAME"])("suggests datepart values for the first %s argument", (functionName) => {
const sql = `SELECT ${functionName}(d`;
const items = buildSqlCompletionItems(sql, sql.length, {
tables: [],
columnsByTable: new Map(),
databaseType: "sqlserver",
dialect: "sqlserver",
keywordCase: "lower",
});
expect(items).toEqual(expect.arrayContaining([expect.objectContaining({ label: "day", type: "keyword" }), expect.objectContaining({ label: "dayofyear", type: "keyword" })]));
expect(items.some((item) => item.label === "deadlock_priority")).toBe(false);
});
it("auto-opens the datepart list immediately after the opening parenthesis", () => {
const sql = "SELECT DATEADD(";
expect(shouldAutoOpenSqlCompletion(sql, sql.length, { databaseType: "sqlserver", dialect: "sqlserver" })).toBe(true);
});
it("stops offering datepart values after the first argument", () => {
const sql = "SELECT DATEADD(day, d";
expect(getSqlCompletionContext(sql, sql.length, { databaseType: "sqlserver", dialect: "sqlserver" }).preferredValueKeywords).toBeUndefined();
});
it("does not apply SQL Server datepart values to other dialects", () => {
const sql = "SELECT DATEADD(d";
expect(getSqlCompletionContext(sql, sql.length, { databaseType: "mysql", dialect: "mysql" }).preferredValueKeywords).toBeUndefined();
});
});
describe("MySQL DESCRIBE table completion", () => {
it.each(["DESC", "DESCRIBE"])("treats %s as a table-name context", (keyword) => {
const sql = `${keyword} ord`;