1
1
use crate :: {
2
2
CompletionItemKind ,
3
3
builder:: { CompletionBuilder , PossibleCompletionItem } ,
4
- context:: CompletionContext ,
4
+ context:: { CompletionContext , WrappingClause } ,
5
5
relevance:: { CompletionRelevanceData , filtering:: CompletionFilter , scoring:: CompletionScore } ,
6
6
} ;
7
7
8
+ use super :: helper:: { find_matching_alias_for_table, get_completion_text_with_schema} ;
9
+
8
10
pub fn complete_columns < ' a > ( ctx : & CompletionContext < ' a > , builder : & mut CompletionBuilder < ' a > ) {
9
11
let available_columns = & ctx. schema_cache . columns ;
10
12
11
13
for col in available_columns {
12
14
let relevance = CompletionRelevanceData :: Column ( col) ;
13
15
14
- let item = PossibleCompletionItem {
16
+ let mut item = PossibleCompletionItem {
15
17
label : col. name . clone ( ) ,
16
18
score : CompletionScore :: from ( relevance. clone ( ) ) ,
17
19
filter : CompletionFilter :: from ( relevance) ,
@@ -20,6 +22,14 @@ pub fn complete_columns<'a>(ctx: &CompletionContext<'a>, builder: &mut Completio
20
22
completion_text : None ,
21
23
} ;
22
24
25
+ // autocomplete with the alias in a join clause if we find one
26
+ if matches ! ( ctx. wrapping_clause_type, Some ( WrappingClause :: Join { .. } ) ) {
27
+ item. completion_text = find_matching_alias_for_table ( ctx, col. table_name . as_str ( ) )
28
+ . and_then ( |alias| {
29
+ get_completion_text_with_schema ( ctx, col. name . as_str ( ) , alias. as_str ( ) )
30
+ } ) ;
31
+ }
32
+
23
33
builder. add_item ( item) ;
24
34
}
25
35
}
0 commit comments