@@ -5,7 +5,7 @@ const { Parser } = require(`node-sql-parser`);
5
5
const Store = require ( `./store` ) ;
6
6
const Configuration = require ( `../configuration` ) ;
7
7
8
- /** @type {{[path: string]: object} } */
8
+ /** @type {{[path: string]: object[] } } */
9
9
const workingAst = { }
10
10
11
11
/**
@@ -36,12 +36,26 @@ exports.initialise = async (context) => {
36
36
} ) ;
37
37
38
38
if ( sqlAst ) {
39
- workingAst [ document . uri . path ] = sqlAst ;
39
+ const astArray = Array . isArray ( sqlAst ) ? sqlAst : [ sqlAst ] ;
40
+ workingAst [ document . uri . path ] = astArray ;
40
41
}
41
42
42
43
linterDiagnostics . set ( document . uri , [ ] ) ;
43
44
} 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
+ }
45
59
46
60
if ( Configuration . get ( `validator` ) ) {
47
61
editTimeout = setTimeout ( async ( ) => {
@@ -61,16 +75,16 @@ exports.initialise = async (context) => {
61
75
///** @type vscode.CompletionItem[] */
62
76
const items = [ ] ;
63
77
64
- const ast = workingAst [ document . uri . path ] ;
65
- if ( ast ) {
78
+ const astList = workingAst [ document . uri . path ] ;
79
+ astList . forEach ( ( ast ) => {
66
80
if ( ast . from && ast . from . length > 0 ) {
67
81
ast . from . forEach ( definedAs => {
68
82
const item = new vscode . CompletionItem ( definedAs . as || definedAs . table , vscode . CompletionItemKind . Struct ) ;
69
83
item . detail = `${ definedAs . db } .${ definedAs . table } ` ;
70
84
items . push ( item ) ;
71
85
} ) ;
72
86
}
73
- } ;
87
+ } ) ;
74
88
75
89
return items ;
76
90
}
@@ -91,11 +105,7 @@ exports.initialise = async (context) => {
91
105
92
106
let fallbackLookup = false ;
93
107
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 ] ;
99
109
100
110
if ( prefix ) {
101
111
for ( const ast of astList ) {
0 commit comments