@@ -5,6 +5,7 @@ use ra_syntax::{
5
5
6
6
use crate :: { Assist , AssistCtx , AssistId } ;
7
7
use ast:: { CallExpr , Expr } ;
8
+ use hir:: ModuleDef ;
8
9
use ra_fmt:: leading_indent;
9
10
10
11
// Assist: add_function
@@ -72,7 +73,7 @@ fn generate_fn(ctx: &AssistCtx, call: &CallExpr) -> Option<(String, TextUnit, Te
72
73
let fn_generics = fn_generics ( & call) ?;
73
74
fn_buf. push_str ( & fn_generics) ;
74
75
75
- let fn_args = fn_args ( ) ?;
76
+ let fn_args = fn_args ( ctx , & call ) ?;
76
77
fn_buf. push_str ( & fn_args) ;
77
78
78
79
fn_buf. push_str ( " {\n " ) ;
@@ -99,10 +100,34 @@ fn fn_generics(_call: &CallExpr) -> Option<String> {
99
100
Some ( "" . into ( ) )
100
101
}
101
102
102
- fn fn_args ( ) -> Option < String > {
103
+ fn fn_args ( ctx : & AssistCtx , _call : & CallExpr ) -> Option < String > {
104
+ let arg_list = _call. syntax ( ) . descendants ( ) . find_map ( ast:: ArgList :: cast) ?;
105
+ for arg in arg_list. args ( ) {
106
+ match & arg {
107
+ Expr :: CallExpr ( call_expr) => {
108
+ arg_for_call ( ctx, call_expr) ;
109
+ }
110
+ _ => { }
111
+ }
112
+ dbg ! ( & arg) ;
113
+ }
103
114
Some ( "()" . into ( ) )
104
115
}
105
116
117
+ fn arg_for_call ( ctx : & AssistCtx , call_expr : & CallExpr ) -> Option < String > {
118
+ let path = call_expr. syntax ( ) . descendants ( ) . find_map ( ast:: Path :: cast) ?;
119
+ let type_string = match ctx. sema . resolve_path ( & path) ? {
120
+ hir:: PathResolution :: Def ( ModuleDef :: Function ( f) ) => {
121
+ let _ret_type = dbg ! ( f. ret_type( ctx. sema. db) ) ;
122
+ // TODO: find out how to print this
123
+ String :: new ( )
124
+ }
125
+ _ => return None ,
126
+ } ;
127
+
128
+ Some ( format ! ( "arg: {}" , type_string) )
129
+ }
130
+
106
131
/// Returns the position inside the current mod or file
107
132
/// directly after the current block
108
133
/// We want to write the generated function directly after
0 commit comments