fix(editor): resolve JOIN tables for navigation
This commit is contained in:
1 parent
e1d6d1224e
commit
024a4aedd6
3 files changed
+91
-4
No files matched your search
@@ -16,10 +16,10 @@ import type {
|
||||
SqlSemanticToken,
|
||||
} from "@/lib/sql/semantic/types";
|
||||
|
||||
const TABLE_INTRODUCERS = new Set(["from", "join", "update", "into", "using", "apply"]);
|
||||
const TABLE_INTRODUCERS = new Set(["from", "join", "straight_join", "update", "into", "using", "apply"]);
|
||||
const JOIN_MODIFIERS = new Set(["left", "right", "inner", "outer", "cross", "full", "natural"]);
|
||||
const CLAUSE_BOUNDARIES = new Set(["where", "group", "having", "order", "limit", "offset", "union", "intersect", "except", "on", "set", "values", "returning"]);
|
||||
const ALIAS_BLACKLIST = new Set([...CLAUSE_BOUNDARIES, "join", "left", "right", "inner", "outer", "cross", "full", "natural", "as", "select", "from"]);
|
||||
const ALIAS_BLACKLIST = new Set([...CLAUSE_BOUNDARIES, "join", "straight_join", "left", "right", "inner", "outer", "cross", "full", "natural", "as", "select", "from"]);
|
||||
|
||||
interface ParseState {
|
||||
dialect: SqlSemanticDialectAdapter;
|
||||
|
||||
@@ -2205,6 +2205,7 @@ function extractReferencedTables(sql: string): SqlCompletionReferencedTable[] {
|
||||
"select",
|
||||
"from",
|
||||
"join",
|
||||
"straight_join",
|
||||
"left",
|
||||
"right",
|
||||
"inner",
|
||||
@@ -2287,11 +2288,16 @@ function extractReferencedTables(sql: string): SqlCompletionReferencedTable[] {
|
||||
"respect",
|
||||
]);
|
||||
|
||||
const pattern = /\b(?:from|join|update|apply)\s+((?:"[^"]+"|`[^`]+`|[^\s,;()]+)(?:\.(?:"[^"]+"|`[^`]+`|[^\s,;()]+))?)(?:\s+(?:as\s+)?([A-Za-z_][\w$]*))?/gi;
|
||||
// STRAIGHT_JOIN is a standalone MySQL table introducer, not a modifier followed by JOIN.
|
||||
const pattern = /\b(?:from|join|straight_join|update|apply)\s+((?:"[^"]+"|`[^`]+`|[^\s,;()]+)(?:\.(?:"[^"]+"|`[^`]+`|[^\s,;()]+))?)(?:\s+(?:as\s+)?([A-Za-z_][\w$]*))?/gi;
|
||||
const referenced: SqlCompletionReferencedTable[] = [];
|
||||
for (const match of sql.matchAll(pattern)) {
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = pattern.exec(sql)) !== null) {
|
||||
const rawName = match[1];
|
||||
const alias = match[2];
|
||||
if (alias && ALIAS_BLACKLIST.has(alias.toLowerCase())) {
|
||||
pattern.lastIndex = match.index + match[0].length - alias.length;
|
||||
}
|
||||
const quotedName = !!rawName && (rawName.startsWith('"') || rawName.startsWith("`"));
|
||||
if (!quotedName && rawName && ALIAS_BLACKLIST.has(rawName.toLowerCase())) continue;
|
||||
// Filter out SQL keywords that accidentally matched as aliases
|
||||
|
||||
Reference in new issue
Block a user