@@ -118,6 +118,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
118118 let Command :: Format {
119119 do_print_to_stdout,
120120 use_verbose_output,
121+ use_debug_output,
121122 do_check_formatted_only,
122123 use_spaces,
123124 indent_size,
@@ -157,17 +158,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
157158 . read_to_string ( & mut input_content)
158159 . map_err ( |error| format ! ( "Failed to read from stdin: {}" , error) ) ?;
159160
160- let mut stdin_config = config. clone ( ) ;
161161 let current_directory = env:: current_dir ( ) . expect ( "Failed to get current directory" ) ;
162162 // When running from stdin users would still like to apply editorconfig
163163 // settings. For the most part, you'd use a section like `[*.gd]`
164164 // matching GDScript files. we fake running the formatter on a `.gd`
165165 // file in the current directory to get user settings to apply.
166- config_apply_editorconfig_then_cli_overrides (
167- & mut stdin_config,
168- & current_directory. join ( "stdin.gd" ) ,
169- config_overrides,
170- ) ;
166+ let stdin_path = current_directory. join ( "stdin.gd" ) ;
167+ let stdin_config =
168+ get_final_config_applied_to_script ( & config, & stdin_path, config_overrides) ;
169+ if use_debug_output {
170+ eprintln ! (
171+ "{}" ,
172+ get_formatted_configuration_as_string( & stdin_path, & stdin_config)
173+ ) ;
174+ }
171175 let formatted_content = match format_gdscript ( & input_content, & stdin_config) {
172176 Ok ( formatted_content) => formatted_content,
173177 Err ( FormatErrors :: ParseErrors ) => {
@@ -214,6 +218,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
214218 let _ = io:: stdout ( ) . flush ( ) ;
215219 }
216220
221+ if use_debug_output {
222+ for file_path in & input_gdscript_files {
223+ let file_config =
224+ get_final_config_applied_to_script ( & config, file_path, config_overrides) ;
225+ eprintln ! (
226+ "{}" ,
227+ get_formatted_configuration_as_string( file_path, & file_config)
228+ ) ;
229+ }
230+ }
231+
217232 let mut sorted_outputs: Vec < Result < FormatterFileProcessingResult , String > > =
218233 format_files_parallel ( & input_gdscript_files, & config, config_overrides) ;
219234
@@ -393,8 +408,7 @@ fn format_one_file(
393408
394409 // We need to clone that config because files in nested directories can
395410 // match different EditorConfig files and rules.
396- let mut file_config = config. clone ( ) ;
397- config_apply_editorconfig_then_cli_overrides ( & mut file_config, file_path, config_overrides) ;
411+ let file_config = get_final_config_applied_to_script ( config, file_path, config_overrides) ;
398412 match format_gdscript_with_buffers ( & input_content, & file_config, render_elements, output) {
399413 Ok ( ( ) ) => { }
400414 Err ( FormatErrors :: ParseErrors ) => {
@@ -422,36 +436,73 @@ fn format_one_file(
422436 } ) )
423437}
424438
425- /// Applies project editorconfig settings first and CLI settings second.
439+ /// Builds the final configuration applied to one file by applying the
440+ /// editorconfig settings first and CLI settings second.
426441///
427442/// The override fields are `Option`s because `None` means that the user did
428443/// not pass that flag. Without this distinction, a CLI default such as an
429444/// indentation size of four would look like an explicit request and would
430445/// incorrectly override `.editorconfig`.
431- fn config_apply_editorconfig_then_cli_overrides (
432- config : & mut FormatterConfiguration ,
433- config_path : & Path ,
446+ fn get_final_config_applied_to_script (
447+ config : & FormatterConfiguration ,
448+ file_path : & Path ,
434449 config_overrides : FormatterConfigOverrides ,
435- ) {
436- gdscript_formatter:: editorconfig:: apply_editorconfig_to_formatter_config ( config, config_path) ;
450+ ) -> FormatterConfiguration {
451+ let mut file_config = config. clone ( ) ;
452+ gdscript_formatter:: editorconfig:: apply_editorconfig_to_formatter_config (
453+ & mut file_config,
454+ file_path,
455+ ) ;
437456 if let Some ( use_spaces) = config_overrides. use_spaces {
438- config . printer . use_spaces = use_spaces;
457+ file_config . printer . use_spaces = use_spaces;
439458 }
440459 if let Some ( indent_size) = config_overrides. indent_size {
441- config . printer . indent_size = indent_size;
460+ file_config . printer . indent_size = indent_size;
442461 }
443462 if let Some ( max_line_length) = config_overrides. max_line_length {
444- config . printer . max_line_length = max_line_length;
463+ file_config . printer . max_line_length = max_line_length;
445464 }
446465 if let Some ( blank_lines_around_definitions) = config_overrides. blank_lines_around_definitions {
447- config . blank_lines_around_definitions = blank_lines_around_definitions;
466+ file_config . blank_lines_around_definitions = blank_lines_around_definitions;
448467 }
449468 if let Some ( continuation_indent_level) = config_overrides. continuation_indent_level {
450- config . printer . continuation_indent_level = continuation_indent_level;
469+ file_config . printer . continuation_indent_level = continuation_indent_level;
451470 }
452471 if let Some ( quote_style) = config_overrides. quote_style {
453- config . quote_style = quote_style;
472+ file_config . quote_style = quote_style;
454473 }
474+ file_config
475+ }
476+
477+ fn get_formatted_configuration_as_string (
478+ file_path : & Path ,
479+ config : & FormatterConfiguration ,
480+ ) -> String {
481+ let indentation_style = if config. printer . use_spaces {
482+ format ! ( "spaces (size {})" , config. printer. indent_size)
483+ } else {
484+ "tabs" . to_string ( )
485+ } ;
486+ let quote_style = match config. quote_style {
487+ QuoteStyle :: Preserve => "preserve" ,
488+ QuoteStyle :: Single => "single" ,
489+ QuoteStyle :: Double => "double" ,
490+ } ;
491+
492+ format ! (
493+ "Debug: {}\n max_line_length: {}\n indentation: {}\n blank_lines_around_definitions: {}\n continuation_indent_level: {}\n quote_style: {}\n insert_final_newline: {}\n trim_trailing_whitespace: {}\n indent_blank_lines: {}\n reorder_code: {}\n verify_structure: {}" ,
494+ file_path. display( ) ,
495+ config. printer. max_line_length,
496+ indentation_style,
497+ config. blank_lines_around_definitions,
498+ config. printer. continuation_indent_level,
499+ quote_style,
500+ config. printer. insert_final_newline,
501+ config. printer. trim_trailing_whitespace,
502+ config. printer. indent_blank_lines,
503+ config. reorder_code,
504+ config. safe,
505+ )
455506}
456507
457508/// Formats files concurrently but preserves their original order when
0 commit comments