File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -169,8 +169,19 @@ impl LanguageServer for Backend {
169169 }
170170 }
171171
172- let mut completions =
173- CompletionProvider :: get_function_completions ( document. functions . as_slice ( ) ) ;
172+ let mut completions = CompletionProvider :: get_function_completions (
173+ & document
174+ . functions
175+ . iter ( )
176+ . map ( |func| {
177+ let function_doc = document
178+ . functions_docs
179+ . get ( & func. name ( ) . to_string ( ) )
180+ . map_or ( String :: new ( ) , |s| s. clone ( ) ) ;
181+ ( func. to_owned ( ) , function_doc)
182+ } )
183+ . collect :: < Vec < _ > > ( ) ,
184+ ) ;
174185 completions. extend_from_slice ( self . completion_provider . builtins ( ) ) ;
175186
176187 Ok ( Some ( CompletionResponse :: Array ( completions) ) )
@@ -307,13 +318,13 @@ impl Backend {
307318 let function = document. functions . iter ( ) . find ( |f| f. name ( ) == func) ?;
308319 let function_doc = document. functions_docs . get ( & func. to_string ( ) ) ?;
309320
310- let template = completion:: function_to_template ( function) ;
321+ let template = completion:: function_to_template ( function, & function_doc ) ;
311322 let description = format ! (
312323 "```simplicityhl\n fn {}({}) -> {}\n ```\n {}" ,
313324 template. display_name,
314325 template. args. join( ", " ) ,
315326 template. return_type,
316- * function_doc
327+ template . description
317328 ) ;
318329 Some ( Hover {
319330 contents : tower_lsp_server:: lsp_types:: HoverContents :: Markup ( MarkupContent {
Original file line number Diff line number Diff line change @@ -47,27 +47,27 @@ impl CompletionProvider {
4747 }
4848
4949 /// Get generic functions completions.
50- pub fn get_function_completions ( functions : & [ Function ] ) -> Vec < CompletionItem > {
50+ pub fn get_function_completions ( functions : & [ ( Function , String ) ] ) -> Vec < CompletionItem > {
5151 functions
5252 . iter ( )
53- . map ( |func| {
54- let template = function_to_template ( func) ;
53+ . map ( |( func, doc ) | {
54+ let template = function_to_template ( func, doc ) ;
5555 template_to_completion ( & template)
5656 } )
5757 . collect ( )
5858 }
5959}
6060
6161/// Convert `simplicityhl::parse::Function` to `FunctionTemplate`.
62- pub fn function_to_template ( func : & Function ) -> types:: FunctionTemplate {
62+ pub fn function_to_template ( func : & Function , doc : & String ) -> types:: FunctionTemplate {
6363 types:: FunctionTemplate :: simple (
6464 func. name ( ) . to_string ( ) ,
6565 func. params ( ) . iter ( ) . map ( |item| format ! ( "{item}" ) ) . collect ( ) ,
6666 match func. ret ( ) {
6767 Some ( ret) => format ! ( "{ret}" ) ,
6868 None => "()" . to_string ( ) ,
6969 } ,
70- "User defined function" ,
70+ doc ,
7171 )
7272}
7373
You can’t perform that action at this time.
0 commit comments