fix(completion): keep FROM tables across blank lines in one statement

This commit is contained in:
dienaso authored and GitHub committed 2026-09-26 06:23:21 +08:00
1 parent 1364293202
commit ec9935d3ea
3 files changed
+75 -3

No files matched your search

+25 -1
View File
@@ -2308,9 +2308,20 @@ function currentLineBlockEnd(sql: string, cursor: number, start: number): number
const boundedLineEnd = lineEnd >= 0 ? lineEnd : sql.length;
const originalTrimmed = sql.slice(lineStart, boundedLineEnd).trimStart();
const trimmed = masked.slice(lineStart, boundedLineEnd).trimStart();
if (lineStart > start && (!originalTrimmed || /^(get|post|put|delete|patch|head)\s+\//i.test(originalTrimmed))) {
if (lineStart > start && /^(get|post|put|delete|patch|head)\s+\//i.test(originalTrimmed)) {
return lineStart;
}
// A blank line only ends the block when the next non-empty line opens a new
// top-level statement. Blank lines *inside* one statement (`SELECT list`
// then a blank line then `FROM t`) must keep the later FROM in scope so
// column hints still resolve (#10196); #9370's next-statement exclusion is
// already handled by the statement-start rule below.
if (lineStart > start && !originalTrimmed && depth === 0) {
const nextContent = nextNonEmptyLineTrimmed(sql, boundedLineEnd);
if (nextContent === null || STATEMENT_START_LINE_PATTERN.test(nextContent) || /^(get|post|put|delete|patch|head)\s+\//i.test(nextContent)) {
return lineStart;
}
}
// The cursor's own line always belongs to the block; only a following
// top-level statement line ends it.
if (!atCursorLine && lineStart > start && depth === 0 && STATEMENT_START_LINE_PATTERN.test(trimmed)) {
@@ -2328,6 +2339,19 @@ function currentLineBlockEnd(sql: string, cursor: number, start: number): number
return null;
}
function nextNonEmptyLineTrimmed(sql: string, from: number): string | null {
let offset = from;
while (offset < sql.length) {
const lineEnd = sql.indexOf("\n", offset);
const boundedEnd = lineEnd >= 0 ? lineEnd : sql.length;
const trimmed = sql.slice(offset, boundedEnd).trim();
if (trimmed) return trimmed;
if (lineEnd < 0) return null;
offset = lineEnd + 1;
}
return null;
}
export function getSqlCompletionResultValidFor(sql: string, cursor: number): RegExp | undefined {
void sql;
void cursor;