Skip to content

Commit

Permalink
[macro] Expose PositionTools.toZeroRange()
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Dec 17, 2024
1 parent e93d7ca commit 2b2bc2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/macro/macroApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,10 @@ let macro_api ccom get_api =
] in
location
);
"position_to_zero_range", vfun1 (fun p ->
let p = decode_pos p in
encode_pos (mk_zero_range_pos p)
);
"on_null_safety_report", vfun1 (fun f ->
let f = prepare_callback f 1 in
(ccom()).callbacks#add_null_safety_report (fun (errors:(string*pos) list) ->
Expand Down
10 changes: 10 additions & 0 deletions std/haxe/macro/PositionTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,15 @@ class PositionTools {
public static function toLocation(p:Position):Location {
return Context.load("position_to_range", 1)(p);
}

/**
Returns a copy of a `haxe.macro.Position`, with `pmax` set to `pmin`.
This ensures that the resulting position will not enclose other positions that might be
looked at for display requests, which could lead to unexpected results.
**/
public static function toZeroRange(p:Position):Position {
return Context.load("position_to_zero_range", 1)(p);
}
#end
}

0 comments on commit 2b2bc2c

Please sign in to comment.