@@ -107,17 +107,12 @@ export default class IntellisensePlugin<T extends ILanguageServer> implements IL
107
107
return [ ] ;
108
108
}
109
109
110
- private getCompletionsFromHueAst = async ( { currentWord, conn, text, currentOffset } : { currentWord : string ; conn : Connection | null ; text : string ; currentOffset : number } ) : Promise < CompletionItem [ ] > => {
111
- let completionsMap = {
112
- query : [ ] ,
113
- tables : [ ] ,
114
- columns : [ ] ,
115
- dbs : [ ]
116
- } ;
117
-
118
- const hueAst = sqlAutocompleteParser . parseSql ( text . substring ( 0 , currentOffset ) , text . substring ( currentOffset ) ) ;
110
+ private getHueAst ( text : string , currentOffset :number ) {
111
+ return sqlAutocompleteParser . parseSql ( text . substring ( 0 , currentOffset ) , text . substring ( currentOffset ) ) ;
112
+ }
119
113
120
- completionsMap . query = ( hueAst . suggestKeywords || [ ] ) . filter ( kw => kw . value . startsWith ( currentWord ) ) . map ( kw => < CompletionItem > {
114
+ private getKeywordsCompletion ( hueAst : any , currentWord : string ) : CompletionItem [ ] {
115
+ return ( hueAst . suggestKeywords || [ ] ) . filter ( kw => kw . value . startsWith ( currentWord ) ) . map ( kw => < CompletionItem > {
121
116
label : kw . value ,
122
117
detail : kw . value ,
123
118
filterText : kw . value ,
@@ -129,11 +124,21 @@ export default class IntellisensePlugin<T extends ILanguageServer> implements IL
129
124
kind : 'markdown'
130
125
}
131
126
} )
132
- const visitedKeywords : [ string ] = ( hueAst . suggestKeywords || [ ] ) . map ( kw => kw . value )
133
- if ( ! conn ) {
134
- log . info ( 'no active connection completions count: %d' , completionsMap . query . length ) ;
135
- return completionsMap . query ;
127
+ }
128
+
129
+ private getCompletionsFromHueAst = async ( { currentWord, conn, text, currentOffset } : { currentWord : string ; conn : Connection | null ; text : string ; currentOffset : number } ) : Promise < CompletionItem [ ] > => {
130
+ let completionsMap = {
131
+ query : [ ] ,
132
+ tables : [ ] ,
133
+ columns : [ ] ,
134
+ dbs : [ ]
136
135
} ;
136
+
137
+ const hueAst = this . getHueAst ( text , currentOffset ) ;
138
+
139
+ completionsMap . query = this . getKeywordsCompletion ( hueAst , currentWord ) ;
140
+ const visitedKeywords : [ string ] = ( hueAst . suggestKeywords || [ ] ) . map ( kw => kw . value )
141
+
137
142
// Can't distinguish functions types, so put all other keywords
138
143
if ( hueAst . suggestFunctions || hueAst . suggestAggregateFunctions || hueAst . suggestAnalyticFunctions ) {
139
144
const staticCompletions = await conn . getStaticCompletions ( ) ;
@@ -179,17 +184,26 @@ export default class IntellisensePlugin<T extends ILanguageServer> implements IL
179
184
currentOffset
180
185
} = await this . getQueryData ( params ) ;
181
186
182
- // First try to get completions from connection's getCompletionsForRawQuery method
187
+ // When no active connection attatched to the file - return only SQL keywords
188
+ if ( ! conn ) {
189
+ const hueAst = this . getHueAst ( text , currentOffset ) ;
190
+ const keywordCompletions = this . getKeywordsCompletion ( hueAst , currentWord ) ;
191
+
192
+ log . info ( 'no active connection, keyword completions:: %d' , keywordCompletions . length ) ;
193
+ return keywordCompletions ;
194
+ } ;
195
+
196
+ // First try connection's getCompletionsForRawQuery method if the connection supports it
183
197
const connectionCompletions = await conn . getCompletionsForRawQuery ( text , currentOffset ) ;
184
198
if ( connectionCompletions !== null ) {
185
- log . debug ( 'Got completions from raw the query, count: %d' , connectionCompletions . length ) ;
199
+ log . info ( 'Got completions from raw the query, count: %d' , connectionCompletions . length ) ;
186
200
return connectionCompletions ;
187
201
}
188
202
189
203
// Fallback to hue AST-based completions
190
- log . debug ( 'Using completions based on hue SQL parser' ) ;
204
+ log . info ( 'Using completions based on hue SQL parser' ) ;
191
205
const completions = await this . getCompletionsFromHueAst ( { currentWord, conn, text, currentOffset } ) ;
192
- log . debug ( 'total completions %d' , completions . length ) ;
206
+ log . info ( 'total completions %d' , completions . length ) ;
193
207
return completions ;
194
208
} catch ( error ) {
195
209
log . error ( 'got an error:\n %O' , error ) ;
0 commit comments