@@ -10,7 +10,10 @@ use full_moon::tokenizer::{Token, TokenKind, TokenReference, TokenType};
1010#[ cfg( feature = "luau" ) ]
1111use crate :: formatters:: luau:: { format_generic_declaration, format_type_specifier} ;
1212use crate :: {
13- context:: { create_indent_trivia, create_newline_trivia, Context } ,
13+ context:: {
14+ create_function_call_trivia, create_function_definition_trivia, create_indent_trivia,
15+ create_newline_trivia, Context ,
16+ } ,
1417 fmt_symbol,
1518 formatters:: {
1619 block:: { format_block, format_last_stmt_no_trivia} ,
@@ -31,7 +34,6 @@ use crate::{
3134 } ,
3235 shape:: Shape ,
3336 CallParenType ,
34- SpaceAfterFunctions ,
3537} ;
3638
3739/// Formats an Anonymous Function
@@ -43,7 +45,9 @@ pub fn format_anonymous_function(
4345 shape : Shape ,
4446) -> ( TokenReference , FunctionBody ) {
4547 const FUNCTION_LEN : usize = "function" . len ( ) ;
46- let function_token = fmt_symbol ! ( ctx, function_token, "function" , shape) ;
48+ let function_definition_trivia = vec ! [ create_function_definition_trivia( ctx) ] ;
49+ let function_token = fmt_symbol ! ( ctx, function_token, "function" , shape)
50+ . update_trailing_trivia ( FormatTriviaType :: Append ( function_definition_trivia) ) ;
4751 let function_body = format_function_body ( ctx, function_body, shape. add_width ( FUNCTION_LEN ) ) ;
4852
4953 ( function_token, function_body)
@@ -74,13 +78,14 @@ pub fn format_call(
7478 shape : Shape ,
7579 call_next_node : FunctionCallNextNode ,
7680) -> Call {
81+ let function_call_trivia = vec ! [ create_function_call_trivia( ctx) ] ;
7782 match call {
78- Call :: AnonymousCall ( function_args) => Call :: AnonymousCall ( format_function_args (
79- ctx ,
80- function_args,
81- shape ,
82- call_next_node ,
83- ) ) ,
83+ Call :: AnonymousCall ( function_args) => {
84+ let formatted_function_args =
85+ format_function_args ( ctx , function_args, shape , call_next_node )
86+ . update_leading_trivia ( FormatTriviaType :: Append ( function_call_trivia ) ) ;
87+ Call :: AnonymousCall ( formatted_function_args )
88+ }
8489 Call :: MethodCall ( method_call) => {
8590 Call :: MethodCall ( format_method_call ( ctx, method_call, shape, call_next_node) )
8691 }
@@ -1151,6 +1156,7 @@ pub fn format_function_declaration(
11511156 // Calculate trivia
11521157 let leading_trivia = vec ! [ create_indent_trivia( ctx, shape) ] ;
11531158 let trailing_trivia = vec ! [ create_newline_trivia( ctx) ] ;
1159+ let function_definition_trivia = vec ! [ create_function_definition_trivia( ctx) ] ;
11541160
11551161 let function_token = fmt_symbol ! (
11561162 ctx,
@@ -1159,7 +1165,8 @@ pub fn format_function_declaration(
11591165 shape
11601166 )
11611167 . update_leading_trivia ( FormatTriviaType :: Append ( leading_trivia) ) ;
1162- let formatted_function_name = format_function_name ( ctx, function_declaration. name ( ) , shape) ;
1168+ let formatted_function_name = format_function_name ( ctx, function_declaration. name ( ) , shape)
1169+ . update_trailing_trivia ( FormatTriviaType :: Append ( function_definition_trivia) ) ;
11631170
11641171 let shape = shape + ( 9 + strip_trivia ( & formatted_function_name) . to_string ( ) . len ( ) ) ; // 9 = "function "
11651172 let function_body = format_function_body ( ctx, function_declaration. body ( ) , shape)
@@ -1179,11 +1186,13 @@ pub fn format_local_function(
11791186 // Calculate trivia
11801187 let leading_trivia = vec ! [ create_indent_trivia( ctx, shape) ] ;
11811188 let trailing_trivia = vec ! [ create_newline_trivia( ctx) ] ;
1189+ let function_definition_trivia = vec ! [ create_function_definition_trivia( ctx) ] ;
11821190
11831191 let local_token = fmt_symbol ! ( ctx, local_function. local_token( ) , "local " , shape)
11841192 . update_leading_trivia ( FormatTriviaType :: Append ( leading_trivia) ) ;
11851193 let function_token = fmt_symbol ! ( ctx, local_function. function_token( ) , "function " , shape) ;
1186- let formatted_name = format_token_reference ( ctx, local_function. name ( ) , shape) ;
1194+ let formatted_name = format_token_reference ( ctx, local_function. name ( ) , shape)
1195+ . update_trailing_trivia ( FormatTriviaType :: Append ( function_definition_trivia) ) ;
11871196
11881197 let shape = shape + ( 6 + 9 + strip_trivia ( & formatted_name) . to_string ( ) . len ( ) ) ; // 6 = "local ", 9 = "function "
11891198 let function_body = format_function_body ( ctx, local_function. body ( ) , shape)
@@ -1202,12 +1211,14 @@ pub fn format_method_call(
12021211 shape : Shape ,
12031212 call_next_node : FunctionCallNextNode ,
12041213) -> MethodCall {
1214+ let function_call_trivia = vec ! [ create_function_call_trivia( ctx) ] ;
12051215 let formatted_colon_token = format_token_reference ( ctx, method_call. colon_token ( ) , shape) ;
12061216 let formatted_name = format_token_reference ( ctx, method_call. name ( ) , shape) ;
12071217 let shape =
12081218 shape + ( formatted_colon_token. to_string ( ) . len ( ) + formatted_name. to_string ( ) . len ( ) ) ;
12091219 let formatted_function_args =
1210- format_function_args ( ctx, method_call. args ( ) , shape, call_next_node) ;
1220+ format_function_args ( ctx, method_call. args ( ) , shape, call_next_node)
1221+ . update_leading_trivia ( FormatTriviaType :: Append ( function_call_trivia) ) ;
12111222
12121223 MethodCall :: new ( formatted_name, formatted_function_args) . with_colon_token ( formatted_colon_token)
12131224}
0 commit comments