@@ -77,38 +77,40 @@ exports.initialise = async (context) => {
77
77
const items = [ ] ;
78
78
79
79
const instance = getInstance ( ) ;
80
- const config = instance ? instance . getConfig ( ) : null ;
80
+ const config = instance && instance . getConnection ( ) ? instance . getConfig ( ) : null ;
81
81
const currentLibrary = config ? config . currentLibrary : null ;
82
82
83
83
const astList = workingAst [ document . uri . path ] ;
84
- astList . forEach ( ( ast ) => {
85
- if ( ast . from && ast . from . length > 0 ) {
86
- ast . from . forEach ( definedAs => {
87
- const item = new vscode . CompletionItem ( definedAs . as || definedAs . table , vscode . CompletionItemKind . Struct ) ;
88
- item . detail = `${ definedAs . db } .${ definedAs . table } ` ;
89
- items . push ( item ) ;
90
- } ) ;
91
- }
92
- } ) ;
84
+ if ( astList ) {
85
+ astList . forEach ( ( ast ) => {
86
+ if ( ast . from && ast . from . length > 0 ) {
87
+ ast . from . forEach ( definedAs => {
88
+ const item = new vscode . CompletionItem ( definedAs . as || definedAs . table , vscode . CompletionItemKind . Struct ) ;
89
+ item . detail = `${ definedAs . db } .${ definedAs . table } ` ;
90
+ items . push ( item ) ;
91
+ } ) ;
92
+ }
93
+ } ) ;
93
94
94
- if ( currentLibrary ) {
95
- const objects = await Store . getObjects ( currentLibrary ) ;
95
+ if ( currentLibrary ) {
96
+ const objects = await Store . getObjects ( currentLibrary ) ;
96
97
97
- objects . forEach ( object => {
98
- let type ;
98
+ objects . forEach ( object => {
99
+ let type ;
99
100
100
- switch ( object . TABLE_TYPE ) {
101
- case `T` : type = `Table` ; break ;
102
- case `V` : type = `View` ; break ;
103
- case `P` : type = `Table` ; break ;
104
- }
101
+ switch ( object . TABLE_TYPE ) {
102
+ case `T` : type = `Table` ; break ;
103
+ case `V` : type = `View` ; break ;
104
+ case `P` : type = `Table` ; break ;
105
+ }
105
106
106
- const item = new vscode . CompletionItem ( object . TABLE_NAME . toLowerCase ( ) , vscode . CompletionItemKind . Struct ) ;
107
- item . insertText = new vscode . SnippetString ( object . TABLE_NAME . toLowerCase ( ) ) ;
108
- item . detail = type ;
109
- item . documentation = object . TABLE_TEXT ;
110
- items . push ( item ) ;
111
- } ) ;
107
+ const item = new vscode . CompletionItem ( object . TABLE_NAME . toLowerCase ( ) , vscode . CompletionItemKind . Struct ) ;
108
+ item . insertText = new vscode . SnippetString ( object . TABLE_NAME . toLowerCase ( ) ) ;
109
+ item . detail = type ;
110
+ item . documentation = object . TABLE_TEXT ;
111
+ items . push ( item ) ;
112
+ } ) ;
113
+ }
112
114
}
113
115
114
116
return items ;
@@ -132,7 +134,7 @@ exports.initialise = async (context) => {
132
134
133
135
const astList = workingAst [ document . uri . path ] ;
134
136
135
- if ( prefix ) {
137
+ if ( prefix && astList ) {
136
138
for ( const ast of astList ) {
137
139
fallbackLookup = false ;
138
140
0 commit comments