Skip to content

Commit 42e371d

Browse files
committed
AST object is always an array
1 parent a2fbdee commit 42e371d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/language/provider.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { Parser } = require(`node-sql-parser`);
55
const Store = require(`./store`);
66
const Configuration = require(`../configuration`);
77

8-
/** @type {{[path: string]: object}} */
8+
/** @type {{[path: string]: object[]}} */
99
const workingAst = {}
1010

1111
/**
@@ -36,12 +36,26 @@ exports.initialise = async (context) => {
3636
});
3737

3838
if (sqlAst) {
39-
workingAst[document.uri.path] = sqlAst;
39+
const astArray = Array.isArray(sqlAst) ? sqlAst : [sqlAst];
40+
workingAst[document.uri.path] = astArray;
4041
}
4142

4243
linterDiagnostics.set(document.uri, []);
4344
} catch (e) {
44-
const location = e.location;
45+
let location = e.location;
46+
47+
if (!location) {
48+
location = {
49+
start: {
50+
line: 1,
51+
column: 1,
52+
},
53+
end: {
54+
line: 1,
55+
column: 1,
56+
},
57+
};
58+
}
4559

4660
if (Configuration.get(`validator`)) {
4761
editTimeout = setTimeout(async () => {
@@ -61,16 +75,16 @@ exports.initialise = async (context) => {
6175
///** @type vscode.CompletionItem[] */
6276
const items = [];
6377

64-
const ast = workingAst[document.uri.path];
65-
if (ast) {
78+
const astList = workingAst[document.uri.path];
79+
astList.forEach((ast) => {
6680
if (ast.from && ast.from.length > 0) {
6781
ast.from.forEach(definedAs => {
6882
const item = new vscode.CompletionItem(definedAs.as || definedAs.table, vscode.CompletionItemKind.Struct);
6983
item.detail = `${definedAs.db}.${definedAs.table}`;
7084
items.push(item);
7185
});
7286
}
73-
};
87+
});
7488

7589
return items;
7690
}
@@ -91,11 +105,7 @@ exports.initialise = async (context) => {
91105

92106
let fallbackLookup = false;
93107

94-
const baseAst = workingAst[document.uri.path];
95-
96-
let astList = [];
97-
if (Array.isArray(baseAst)) astList = baseAst;
98-
else if (baseAst) astList = [baseAst];
108+
const astList = workingAst[document.uri.path];
99109

100110
if (prefix) {
101111
for (const ast of astList) {

0 commit comments

Comments
 (0)