From d92f08b8ebe1d98d67f031f48b774bd4e0fa5c3f Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 21 Feb 2024 07:13:04 +0100 Subject: [PATCH] Unify help messages handling (#11584) * Don't go through message reporting for help messages * [tests] Avoid (ab)using --version --- src/compiler/args.ml | 15 +++++---------- src/compiler/compiler.ml | 2 +- tests/misc/projects/Issue8471/Macro.hx | 1 + tests/misc/projects/Issue8471/Macro2.hx | 1 + tests/misc/projects/Issue8471/compile.hxml | 1 - .../Issue8471/compile2-pretty.hxml.stderr | 4 ++-- tests/misc/projects/Issue8471/compile2.hxml | 1 - .../misc/projects/Issue8471/compile2.hxml.stderr | 2 +- 8 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/compiler/args.ml b/src/compiler/args.ml index 127d84f9e6c..c3de78ce41e 100644 --- a/src/compiler/args.ml +++ b/src/compiler/args.ml @@ -154,8 +154,7 @@ let parse_args com = com.debug <- true; ),"","add debug information to the compiled code"); ("Miscellaneous",["--version"],["-version"],Arg.Unit (fun() -> - com.info s_version_full null_pos; - actx.did_something <- true; + raise (Helper.HelpMessage s_version_full); ),"","print version and exit"); ("Miscellaneous", ["-h";"--help"], ["-help"], Arg.Unit (fun () -> raise (Arg.Help "") @@ -163,31 +162,27 @@ let parse_args com = ("Miscellaneous",["--help-defines"],[], Arg.Unit (fun() -> let all,max_length = Define.get_documentation_list com.user_defines in let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in - List.iter (fun msg -> com.print (msg ^ "\n")) all; - actx.did_something <- true + raise (Helper.HelpMessage (ExtLib.String.join "\n" all)); ),"","print help for all compiler specific defines"); ("Miscellaneous",["--help-user-defines"],[], Arg.Unit (fun() -> actx.did_something <- true; com.callbacks#add_after_init_macros (fun() -> let all,max_length = Define.get_user_documentation_list com.user_defines in let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in - List.iter (fun msg -> com.print (msg ^ "\n")) all; - raise Abort + raise (Helper.HelpMessage (ExtLib.String.join "\n" all)); ) ),"","print help for all user defines"); ("Miscellaneous",["--help-metas"],[], Arg.Unit (fun() -> let all,max_length = Meta.get_documentation_list com.user_metas in let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in - List.iter (fun msg -> com.print (msg ^ "\n")) all; - actx.did_something <- true + raise (Helper.HelpMessage (ExtLib.String.join "\n" all)); ),"","print help for all compiler metadatas"); ("Miscellaneous",["--help-user-metas"],[], Arg.Unit (fun() -> actx.did_something <- true; com.callbacks#add_after_init_macros (fun() -> let all,max_length = Meta.get_user_documentation_list com.user_metas in let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in - List.iter (fun msg -> com.print (msg ^ "\n")) all; - raise Abort + raise (Helper.HelpMessage (ExtLib.String.join "\n" all)); ) ),"","print help for all user metadatas"); ] in diff --git a/src/compiler/compiler.ml b/src/compiler/compiler.ml index 52fef29aed9..cd7d63d2c14 100644 --- a/src/compiler/compiler.ml +++ b/src/compiler/compiler.ml @@ -440,7 +440,7 @@ with | Failure msg when not Helper.is_debug_run -> error ctx ("Error: " ^ msg) null_pos | Helper.HelpMessage msg -> - com.info msg null_pos + print_endline msg | Parser.TypePath (p,c,is_import,pos) -> DisplayOutput.handle_type_path_exception ctx p c is_import pos | Parser.SyntaxCompletion(kind,subj) -> diff --git a/tests/misc/projects/Issue8471/Macro.hx b/tests/misc/projects/Issue8471/Macro.hx index 0253ca3c155..2aadcbc88bf 100644 --- a/tests/misc/projects/Issue8471/Macro.hx +++ b/tests/misc/projects/Issue8471/Macro.hx @@ -2,6 +2,7 @@ import haxe.macro.Context; class Macro { public static function init() { + Context.info("Info", Context.currentPos()); Context.warning("This warning will disappear", Context.currentPos()); Context.onAfterTyping(afterTyping); diff --git a/tests/misc/projects/Issue8471/Macro2.hx b/tests/misc/projects/Issue8471/Macro2.hx index 437fd064f0f..3d85b5b70fa 100644 --- a/tests/misc/projects/Issue8471/Macro2.hx +++ b/tests/misc/projects/Issue8471/Macro2.hx @@ -9,6 +9,7 @@ class Macro2 { } static function afterTyping(_) { + Context.info("Info", Context.currentPos()); Context.warning(("1" :DeprecatedType), Context.currentPos()); Context.warning("2", Context.currentPos()); Context.warning("3", Context.currentPos()); diff --git a/tests/misc/projects/Issue8471/compile.hxml b/tests/misc/projects/Issue8471/compile.hxml index d294417d47b..a838b3a019d 100644 --- a/tests/misc/projects/Issue8471/compile.hxml +++ b/tests/misc/projects/Issue8471/compile.hxml @@ -1,2 +1 @@ ---version --macro Macro.init() diff --git a/tests/misc/projects/Issue8471/compile2-pretty.hxml.stderr b/tests/misc/projects/Issue8471/compile2-pretty.hxml.stderr index 75fed4d477c..77e260c8072 100644 --- a/tests/misc/projects/Issue8471/compile2-pretty.hxml.stderr +++ b/tests/misc/projects/Issue8471/compile2-pretty.hxml.stderr @@ -1,6 +1,6 @@ -[WARNING] (macro) Macro2.hx:12: characters 25-39 +[WARNING] (macro) Macro2.hx:13: characters 25-39 - 12 | Context.warning(("1" :DeprecatedType), Context.currentPos()); + 13 | Context.warning(("1" :DeprecatedType), Context.currentPos()); | ^^^^^^^^^^^^^^ | (WDeprecated) This typedef is deprecated in favor of String diff --git a/tests/misc/projects/Issue8471/compile2.hxml b/tests/misc/projects/Issue8471/compile2.hxml index 840524bc392..e4f8de4771c 100644 --- a/tests/misc/projects/Issue8471/compile2.hxml +++ b/tests/misc/projects/Issue8471/compile2.hxml @@ -1,2 +1 @@ ---version --macro Macro2.init() diff --git a/tests/misc/projects/Issue8471/compile2.hxml.stderr b/tests/misc/projects/Issue8471/compile2.hxml.stderr index c3b0af5feb7..8c78458c934 100644 --- a/tests/misc/projects/Issue8471/compile2.hxml.stderr +++ b/tests/misc/projects/Issue8471/compile2.hxml.stderr @@ -1,4 +1,4 @@ -Macro2.hx:12: characters 25-39 : Warning : (WDeprecated) This typedef is deprecated in favor of String +Macro2.hx:13: characters 25-39 : Warning : (WDeprecated) This typedef is deprecated in favor of String Warning : 1 Warning : 2 Warning : 3