fix(sql): keep SQL Server table hints out of soft statement starts

This commit is contained in:
dienaso authored and GitHub committed 2026-09-24 17:18:06 +08:00
1 parent d11d5acdfa
commit a593a2b200
2 files changed
+44

No files matched your search

@@ -1229,6 +1229,11 @@ function softStatementKeywordAt(sql: string, pos: number, databaseType?: Databas
// COMMENT is also a common column name. Only COMMENT ON starts a standalone
// SQL command; otherwise a line-start projection column must stay in SELECT.
if (keyword === "COMMENT" && nextSqlWord(sql, pos + match[0].length, databaseType, parameterOptions) !== "ON") return null;
// `WITH (` is a SQL Server table hint (`FROM t WITH (NOLOCK)`), not a CTE
// opener — CTEs are always `WITH name AS (` / `WITH RECURSIVE name AS (`.
// Formatters break table hints onto their own line; without this, the
// following statement loses its run target (#10098).
if (keyword === "WITH" && nextNonWhitespaceChar(sql, pos + match[0].length) === "(") return null;
return softStatementStartKeywords(databaseType).has(keyword) ? keyword : null;
}