this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix RangeError: decoration positions exceeding document length

Three fixes for "Position N is out of range for changeset" errors:

1. js_top_worker: clamp output_at loc to input length — the ";;"
appended for parsing made pos_cnum extend past the original source

2. x-ocaml/editor: clamp decoration positions against CM document
length (Text.length) not OCaml String.length — they differ for
non-ASCII text (UTF-16 vs bytes). Also combine doc replacement +
decoration clear into a single transaction in set_source, and
read actual CM doc in build_range_set

3. jsoo-code-mirror/decoration: defensive safe_map that catches
JS RangeError in RangeSet.map and returns empty

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+8 -6
+8 -6
lib/impl.cppo.ml
··· 618 618 Buffer.clear res_buff; 619 619 Buffer.clear stderr_buff; 620 620 Buffer.clear stdout_buff; 621 + let input_len = String.length phrase in 621 622 let phrase = 622 - let l = String.length phrase in 623 - if l >= 2 && String.sub phrase (l - 2) 2 = ";;" then phrase 623 + if input_len >= 2 && String.sub phrase (input_len - 2) 2 = ";;" then phrase 624 624 else phrase ^ ";;" 625 625 in 626 626 (* Bind the merlin-lib local store so Toploop.execute_phrase can access ··· 639 639 let phr = Toploop.preprocess_phrase Format.err_formatter phr in 640 640 ignore (Toploop.execute_phrase true pp_result phr : bool); 641 641 (* Get location from phrase AST — use the last 642 - structure item so output appears after all defs *) 642 + structure item so output appears after all defs. 643 + Clamp to input_len so positions from the appended 644 + ";;" suffix are never returned to the caller. *) 643 645 let loc = match phr with 644 646 | Parsetree.Ptop_def (_ :: _ as items) -> 645 647 let last = List.nth items (List.length items - 1) in 646 - last.pstr_loc.loc_end.pos_cnum 648 + min input_len last.pstr_loc.loc_end.pos_cnum 647 649 | Parsetree.Ptop_dir { pdir_loc; _ } -> 648 - pdir_loc.loc_end.pos_cnum 649 - | _ -> lb.lex_curr_p.pos_cnum 650 + min input_len pdir_loc.loc_end.pos_cnum 651 + | _ -> min input_len lb.lex_curr_p.pos_cnum 650 652 in 651 653 (* Flush and get current output *) 652 654 Format.pp_print_flush pp_result ();