diff --git a/src/macro/macroApi.ml b/src/macro/macroApi.ml index fcb07729356..312a0379fd0 100644 --- a/src/macro/macroApi.ml +++ b/src/macro/macroApi.ml @@ -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) -> diff --git a/std/haxe/macro/PositionTools.hx b/std/haxe/macro/PositionTools.hx index f29300f6367..46dbdf02a0f 100644 --- a/std/haxe/macro/PositionTools.hx +++ b/std/haxe/macro/PositionTools.hx @@ -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 }