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
@@ -20,17 +23,46 @@ pub fn complete_functions<'a>(ctx: &'a CompletionContext, builder: &mut Completi
2023 description : format ! ( "Schema: {}" , func. schema) ,
2124 kind : CompletionItemKind :: Function ,
2225 detail : None ,
23- completion_text : get_completion_text_with_schema_or_alias (
24- ctx,
25- & func. name ,
26- & func. schema ,
27- ) ,
26+ completion_text : Some ( get_completion_text ( ctx, func) ) ,
2827 } ;
2928
3029 builder. add_item ( item) ;
3130 }
3231}
3332
33+ fn get_completion_text ( ctx : & CompletionContext , func : & Function ) -> CompletionText {
34+ let range = get_range_to_replace ( ctx) ;
35+ let mut text = get_completion_text_with_schema_or_alias ( ctx, & func. name , & func. schema )
36+ . map ( |ct| ct. text )
37+ . unwrap_or ( func. name . to_string ( ) ) ;
38+
39+ if ctx. is_invocation {
40+ CompletionText {
41+ text,
42+ range,
43+ is_snippet : false ,
44+ }
45+ } else {
46+ text. push ( '(' ) ;
47+
48+ let num_args = func. args . args . len ( ) ;
49+ for ( idx, arg) in func. args . args . iter ( ) . enumerate ( ) {
50+ text. push_str ( format ! ( r#"${{{}:{}}}"# , idx + 1 , arg. name) . as_str ( ) ) ;
51+ if idx < num_args - 1 {
52+ text. push_str ( ", " ) ;
53+ }
54+ }
55+
56+ text. push ( ')' ) ;
57+
58+ CompletionText {
59+ text,
60+ range,
61+ is_snippet : num_args > 0 ,
62+ }
63+ }
64+ }
65+
3466#[ cfg( test) ]
3567mod tests {
3668 use crate :: {
0 commit comments