@@ -11,10 +11,11 @@ use lsp_types::{
1111
1212use gleam_core:: {
1313 ast:: { CallArg , ImplicitCallArgOrigin , TypedExpr } ,
14- type_:: { FieldMap , ModuleValueConstructor , Type , pretty:: Printer } ,
14+ build:: Module ,
15+ type_:: { FieldMap , ModuleValueConstructor , Type , printer:: Printer } ,
1516} ;
1617
17- pub fn for_expression ( expr : & TypedExpr ) -> Option < SignatureHelp > {
18+ pub fn for_expression ( expr : & TypedExpr , module : & Module ) -> Option < SignatureHelp > {
1819 // If we're inside a function call we can provide signature help,
1920 // otherwise we don't want anything to pop up.
2021 let TypedExpr :: Call { fun, arguments, .. } = expr else {
@@ -27,7 +28,13 @@ pub fn for_expression(expr: &TypedExpr) -> Option<SignatureHelp> {
2728 // help.
2829 TypedExpr :: Var {
2930 constructor, name, ..
30- } => signature_help ( name. clone ( ) , fun, arguments, constructor. field_map ( ) ) ,
31+ } => signature_help (
32+ name. clone ( ) ,
33+ fun,
34+ arguments,
35+ constructor. field_map ( ) ,
36+ module,
37+ ) ,
3138
3239 // If we're making a qualified call to another module's function
3340 // then we want to show its type, documentation and the exact name
@@ -50,7 +57,7 @@ pub fn for_expression(expr: &TypedExpr) -> Option<SignatureHelp> {
5057 | ModuleValueConstructor :: Fn { field_map, .. } => field_map. into ( ) ,
5158 } ;
5259 let name = format ! ( "{module_alias}.{label}" ) . into ( ) ;
53- signature_help ( name, fun, arguments, field_map)
60+ signature_help ( name, fun, arguments, field_map, module )
5461 }
5562
5663 // If the function being called is an invalid node we don't want to
@@ -87,7 +94,7 @@ pub fn for_expression(expr: &TypedExpr) -> Option<SignatureHelp> {
8794 | TypedExpr :: BitArray { .. }
8895 | TypedExpr :: RecordUpdate { .. }
8996 | TypedExpr :: NegateBool { .. }
90- | TypedExpr :: NegateInt { .. } => signature_help ( "fn" . into ( ) , fun, arguments, None ) ,
97+ | TypedExpr :: NegateInt { .. } => signature_help ( "fn" . into ( ) , fun, arguments, None , module ) ,
9198 }
9299}
93100
@@ -109,6 +116,7 @@ fn signature_help(
109116 fun : & TypedExpr ,
110117 supplied_arguments : & [ CallArg < TypedExpr > ] ,
111118 field_map : Option < & FieldMap > ,
119+ module : & Module ,
112120) -> Option < SignatureHelp > {
113121 let ( arguments, return_) = fun. type_ ( ) . fn_types ( ) ?;
114122
@@ -127,7 +135,7 @@ fn signature_help(
127135 None => HashMap :: new ( ) ,
128136 } ;
129137
130- let printer = Printer :: new ( ) ;
138+ let printer = Printer :: new ( & module . ast . names ) ;
131139 let ( label, parameters) =
132140 print_signature_help ( printer, fun_name, arguments, return_, & index_to_label) ;
133141
@@ -240,7 +248,7 @@ fn active_parameter_index(
240248/// `ParameterInformation` for all its arguments.
241249///
242250fn print_signature_help (
243- mut printer : Printer ,
251+ mut printer : Printer < ' _ > ,
244252 function_name : EcoString ,
245253 arguments : Vec < Arc < Type > > ,
246254 return_ : Arc < Type > ,
@@ -256,7 +264,7 @@ fn print_signature_help(
256264 signature. push_str ( label) ;
257265 signature. push_str ( ": " ) ;
258266 }
259- signature. push_str ( & printer. pretty_print ( argument, 0 ) ) ;
267+ signature. push_str ( & printer. print_type ( argument) ) ;
260268 let arg_end = signature. len ( ) ;
261269 let label = ParameterLabel :: LabelOffsets ( [ arg_start as u32 , arg_end as u32 ] ) ;
262270
@@ -272,6 +280,6 @@ fn print_signature_help(
272280 }
273281
274282 signature. push_str ( ") -> " ) ;
275- signature. push_str ( & printer. pretty_print ( & return_, 0 ) ) ;
283+ signature. push_str ( & printer. print_type ( & return_) ) ;
276284 ( signature, parameter_informations)
277285}
0 commit comments