Skip to content

Commit bb87194

Browse files
committed
Fix potential errors
1 parent 23f2121 commit bb87194

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/language/provider.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,40 @@ exports.initialise = async (context) => {
7777
const items = [];
7878

7979
const instance = getInstance();
80-
const config = instance ? instance.getConfig() : null;
80+
const config = instance && instance.getConnection() ? instance.getConfig() : null;
8181
const currentLibrary = config ? config.currentLibrary : null;
8282

8383
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+
});
9394

94-
if (currentLibrary) {
95-
const objects = await Store.getObjects(currentLibrary);
95+
if (currentLibrary) {
96+
const objects = await Store.getObjects(currentLibrary);
9697

97-
objects.forEach(object => {
98-
let type;
98+
objects.forEach(object => {
99+
let type;
99100

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+
}
105106

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+
}
112114
}
113115

114116
return items;
@@ -132,7 +134,7 @@ exports.initialise = async (context) => {
132134

133135
const astList = workingAst[document.uri.path];
134136

135-
if (prefix) {
137+
if (prefix && astList) {
136138
for (const ast of astList) {
137139
fallbackLookup = false;
138140

0 commit comments

Comments
 (0)