@@ -107,17 +107,12 @@ export default class IntellisensePlugin<T extends ILanguageServer> implements IL
107107 return [ ] ;
108108 }
109109
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+ }
119113
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 > {
121116 label : kw . value ,
122117 detail : kw . value ,
123118 filterText : kw . value ,
@@ -129,11 +124,21 @@ export default class IntellisensePlugin<T extends ILanguageServer> implements IL
129124 kind : 'markdown'
130125 }
131126 } )
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 : [ ]
136135 } ;
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+
137142 // Can't distinguish functions types, so put all other keywords
138143 if ( hueAst . suggestFunctions || hueAst . suggestAggregateFunctions || hueAst . suggestAnalyticFunctions ) {
139144 const staticCompletions = await conn . getStaticCompletions ( ) ;
@@ -179,17 +184,26 @@ export default class IntellisensePlugin<T extends ILanguageServer> implements IL
179184 currentOffset
180185 } = await this . getQueryData ( params ) ;
181186
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
183197 const connectionCompletions = await conn . getCompletionsForRawQuery ( text , currentOffset ) ;
184198 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 ) ;
186200 return connectionCompletions ;
187201 }
188202
189203 // 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' ) ;
191205 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 ) ;
193207 return completions ;
194208 } catch ( error ) {
195209 log . error ( 'got an error:\n %O' , error ) ;
0 commit comments