@@ -7,7 +7,9 @@ def suggest_type(full_text, text_before_cursor):
77 """Takes the full_text that is typed so far and also the text before the
88 cursor to suggest completion type and scope.
99
10- Returns a tuple with a type of entity ('table', 'column' etc) and a scope.
10+ Returns a tuple with a type of entity ('table', 'column' etc), a scope
11+ and a flag to tell the caller to ignore the word at cursor and return all
12+ matches in current scope.
1113 A scope for a column category will be a list of tables.
1214 """
1315
@@ -31,19 +33,25 @@ def suggest_type(full_text, text_before_cursor):
3133 last_token = last_token .value if last_token else ''
3234
3335 def is_function_word (word ):
36+ """
37+ Checks iw we are at function call, such as MAX(, MIN(, AVG(, etc.
38+ In this case, we want to return all columns.
39+ :param word: word at cursor, for example MAX(
40+ :return: true or false
41+ """
3442 return word and len (word ) > 1 and word [- 1 ] == '('
3543
3644 if is_function_word (word_before_cursor ):
37- return ('columns' , extract_tables (full_text ))
45+ return ('columns' , extract_tables (full_text ), True )
3846 elif last_token .lower () in ('set' , 'by' , 'distinct' ):
39- return ('columns' , extract_tables (full_text ))
47+ return ('columns' , extract_tables (full_text ), False )
4048 elif last_token .lower () in ('select' , 'where' , 'having' ):
41- return ('columns-and-functions' , extract_tables (full_text ))
49+ return ('columns-and-functions' , extract_tables (full_text ), False )
4250 elif last_token .lower () in ('from' , 'update' , 'into' , 'describe' ):
43- return ('tables' , [])
51+ return ('tables' , [], False )
4452 elif last_token in ('d' ,): # \d
45- return ('tables' , [])
53+ return ('tables' , [], False )
4654 elif last_token .lower () in ('c' , 'use' ): # \c
47- return ('databases' , [])
55+ return ('databases' , [], False )
4856 else :
49- return ('keywords' , [])
57+ return ('keywords' , [], False )
0 commit comments