fix(editor): keep comment columns in query ranges
This commit is contained in:
1 parent
e2f53a786f
commit
dabbb58b0e
2 files changed
+16
No files matched your search
@@ -718,6 +718,9 @@ function softStatementKeywordAt(sql: string, pos: number, databaseType?: Databas
|
||||
if (!match) return null;
|
||||
const keyword = match[0].toUpperCase();
|
||||
if (keyword === "REPLACE" && nextNonWhitespaceChar(sql, pos + match[0].length) === "(") return null;
|
||||
// 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) !== "ON") return null;
|
||||
return softStatementStartKeywords(databaseType).has(keyword) ? keyword : null;
|
||||
}
|
||||
|
||||
@@ -913,6 +916,12 @@ function nextNonWhitespaceChar(sql: string, pos: number): string | null {
|
||||
return i < sql.length ? sql[i] : null;
|
||||
}
|
||||
|
||||
function nextSqlWord(sql: string, pos: number): string | null {
|
||||
let i = pos;
|
||||
while (i < sql.length && isSqlWhitespace(sql[i])) i += 1;
|
||||
return /^[A-Za-z_][\w$]*/.exec(sql.slice(i))?.[0]?.toUpperCase() ?? null;
|
||||
}
|
||||
|
||||
function isExplainLikeKeyword(keyword: string | null): boolean {
|
||||
return keyword === "EXPLAIN" || keyword === "DESCRIBE" || keyword === "DESC";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user