Skip to content

Commit

Permalink
Unify help messages handling (#11584)
Browse files Browse the repository at this point in the history
* Don't go through message reporting for help messages

* [tests] Avoid (ab)using --version
  • Loading branch information
kLabz authored Feb 21, 2024
1 parent 539601b commit d92f08b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 16 deletions.
15 changes: 5 additions & 10 deletions src/compiler/args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,40 +154,35 @@ 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 "")
),"","show extended help information");
("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
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
1 change: 1 addition & 0 deletions tests/misc/projects/Issue8471/Macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/misc/projects/Issue8471/Macro2.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 0 additions & 1 deletion tests/misc/projects/Issue8471/compile.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--version
--macro Macro.init()
4 changes: 2 additions & 2 deletions tests/misc/projects/Issue8471/compile2-pretty.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion tests/misc/projects/Issue8471/compile2.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--version
--macro Macro2.init()
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue8471/compile2.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d92f08b

Please sign in to comment.