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
@@ -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