11use crate :: {
22 CompletionItemKind ,
33 builder:: { CompletionBuilder , PossibleCompletionItem } ,
4- context:: CompletionContext ,
4+ context:: { CompletionContext , WrappingClause } ,
55 relevance:: { CompletionRelevanceData , filtering:: CompletionFilter , scoring:: CompletionScore } ,
66} ;
77
8+ use super :: helper:: { find_matching_alias_for_table, get_completion_text_with_schema} ;
9+
810pub fn complete_columns < ' a > ( ctx : & CompletionContext < ' a > , builder : & mut CompletionBuilder < ' a > ) {
911 let available_columns = & ctx. schema_cache . columns ;
1012
1113 for col in available_columns {
1214 let relevance = CompletionRelevanceData :: Column ( col) ;
1315
14- let item = PossibleCompletionItem {
16+ let mut item = PossibleCompletionItem {
1517 label : col. name . clone ( ) ,
1618 score : CompletionScore :: from ( relevance. clone ( ) ) ,
1719 filter : CompletionFilter :: from ( relevance) ,
@@ -20,6 +22,14 @@ pub fn complete_columns<'a>(ctx: &CompletionContext<'a>, builder: &mut Completio
2022 completion_text : None ,
2123 } ;
2224
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+
2333 builder. add_item ( item) ;
2434 }
2535}
0 commit comments