1+ use pgt_schema_cache:: Function ;
2+
13use crate :: {
2- CompletionItemKind ,
4+ CompletionItemKind , CompletionText ,
35 builder:: { CompletionBuilder , PossibleCompletionItem } ,
46 context:: CompletionContext ,
7+ providers:: helper:: get_range_to_replace,
58 relevance:: { CompletionRelevanceData , filtering:: CompletionFilter , scoring:: CompletionScore } ,
69} ;
710
@@ -19,17 +22,46 @@ pub fn complete_functions<'a>(ctx: &'a CompletionContext, builder: &mut Completi
1922 filter : CompletionFilter :: from ( relevance) ,
2023 description : format ! ( "Schema: {}" , func. schema) ,
2124 kind : CompletionItemKind :: Function ,
22- completion_text : get_completion_text_with_schema_or_alias (
23- ctx,
24- & func. name ,
25- & func. schema ,
26- ) ,
25+ completion_text : Some ( get_completion_text ( ctx, func) ) ,
2726 } ;
2827
2928 builder. add_item ( item) ;
3029 }
3130}
3231
32+ fn get_completion_text ( ctx : & CompletionContext , func : & Function ) -> CompletionText {
33+ let range = get_range_to_replace ( ctx) ;
34+ let mut text = get_completion_text_with_schema_or_alias ( ctx, & func. name , & func. schema )
35+ . map ( |ct| ct. text )
36+ . unwrap_or ( func. name . to_string ( ) ) ;
37+
38+ if ctx. is_invocation {
39+ CompletionText {
40+ text,
41+ range,
42+ is_snippet : false ,
43+ }
44+ } else {
45+ text. push ( '(' ) ;
46+
47+ let num_args = func. args . args . len ( ) ;
48+ for ( idx, arg) in func. args . args . iter ( ) . enumerate ( ) {
49+ text. push_str ( format ! ( r#"${{{}:{}}}"# , idx + 1 , arg. name) . as_str ( ) ) ;
50+ if idx < num_args - 1 {
51+ text. push_str ( ", " ) ;
52+ }
53+ }
54+
55+ text. push ( ')' ) ;
56+
57+ CompletionText {
58+ text,
59+ range,
60+ is_snippet : num_args > 0 ,
61+ }
62+ }
63+ }
64+
3365#[ cfg( test) ]
3466mod tests {
3567 use crate :: {
0 commit comments