fix(editor): restore quoted table keyword completion

This commit is contained in:
ekesaiting authored and GitHub committed 2026-08-01 02:19:10 +08:00
1 parent 61e149bb9f
commit 7cf5795666
3 files changed
+44 -5

No files matched your search

+22 -5
View File
@@ -600,13 +600,13 @@ function trailingIdentifier(tokens: readonly SqlSemanticToken[], cursor: number,
}
function previousWord(tokens: readonly SqlSemanticToken[], cursor: number): string {
const before = tokens.filter((item) => item.span.end <= cursor && item.kind === "word");
return before[before.length - 1]?.normalized ?? "";
const before = tokens.filter((item) => item.span.end <= cursor && item.kind !== "comment");
return nearestPreviousSyntaxWord(before);
}
function wordBeforePosition(tokens: readonly SqlSemanticToken[], position: number): string {
const before = tokens.filter((item) => item.span.end <= position && item.kind === "word");
return before[before.length - 1]?.normalized ?? "";
const before = tokens.filter((item) => item.span.end <= position && item.kind !== "comment");
return nearestPreviousSyntaxWord(before);
}
function wordBeforeTrailingIdentifier(tokens: readonly SqlSemanticToken[], cursor: number, trailing: TrailingIdentifier): string {
@@ -622,7 +622,24 @@ function wordBeforeTrailingIdentifier(tokens: readonly SqlSemanticToken[], curso
identifiersToSkip -= 1;
index -= 1;
}
return before[index]?.kind === "word" ? before[index].normalized : "";
return nearestPreviousSyntaxWord(before.slice(0, index + 1));
}
/**
* Scans backward from the end of `before` for the nearest unquoted syntax word.
* A quoted identifier is a barrier: its object name must not participate in
* keyword comparisons even when it is named `from`, `join`, or `update`.
*/
function nearestPreviousSyntaxWord(tokens: readonly SqlSemanticToken[]): string {
for (let index = tokens.length - 1; index >= 0; index -= 1) {
const item = tokens[index];
if (!item) continue;
if (item.kind === "word") return item.normalized;
if (item.kind === "quoted_identifier") return "";
if (item.text === "." || item.kind === "comment") continue;
break;
}
return "";
}
function isTableListContinuation(tokens: readonly SqlSemanticToken[], position: number): boolean {