From 599c0a8ad7f1ab8122f37c9ba257ded3b9a02c29 Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Fri, 19 Mar 2021 03:47:02 -0700 Subject: [PATCH] [Super errors] Add the missing gutter when a line overflows to the next Fixes part of https://github.com/rescript-lang/rescript-vscode/issues/86 Previous to #5013 we couldn't fix this issue because we used Format to break lines for us. Now that we're controlling this manually, we can draw the gutter for those lines. --- .../expected/highlighting5.re.expected | 2 +- jscomp/super_errors/super_code_frame.ml | 23 ++++++++----------- lib/4.06.1/unstable/js_compiler.ml | 23 ++++++++----------- lib/4.06.1/whole_compiler.ml | 23 ++++++++----------- 4 files changed, 28 insertions(+), 43 deletions(-) diff --git a/jscomp/build_tests/super_errors/expected/highlighting5.re.expected b/jscomp/build_tests/super_errors/expected/highlighting5.re.expected index 7a0eb66385..3ecbffcd27 100644 --- a/jscomp/build_tests/super_errors/expected/highlighting5.re.expected +++ b/jscomp/build_tests/super_errors/expected/highlighting5.re.expected @@ -4,7 +4,7 @@ 1 │ /* overflows in the terminal */ 2 │ let a: int = "hellllllllllllllllllllllllllllllllllllllllllllllllllllllll - lllllllllllllllllllllllllll"; + │ lllllllllllllllllllllllllll"; 3 │ This has type: string diff --git a/jscomp/super_errors/super_code_frame.ml b/jscomp/super_errors/super_code_frame.ml index 4c41a7adb4..b6fbba43ff 100644 --- a/jscomp/super_errors/super_code_frame.ml +++ b/jscomp/super_errors/super_code_frame.ml @@ -238,20 +238,15 @@ let print ~is_warning ~src ~startPos ~endPos = Buffer.add_string buf (col NoColor "\n"); | Number line_number -> begin content |> List.iteri (fun i line -> - if i = 0 then begin - let gutter_color = - if i = 0 - && line_number >= highlight_line_start_line - && line_number <= highlight_line_end_line then - if is_warning then Warn else Err - else NoColor - in - draw_gutter gutter_color (string_of_int line_number); - end else begin - (* TODO: remove this branch after the next PR *) - let pad = String.make (max_line_digits_count + indent + 3) ' ' in - Buffer.add_string buf (col NoColor pad); - end; + let gutter_content = if i = 0 then string_of_int line_number else "" in + let gutter_color = + if i = 0 + && line_number >= highlight_line_start_line + && line_number <= highlight_line_end_line then + if is_warning then Warn else Err + else NoColor + in + draw_gutter gutter_color gutter_content; line.s |> String.iteri (fun ii ch -> let c = diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 1917370acf..45c2d03788 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -407653,20 +407653,15 @@ let print ~is_warning ~src ~startPos ~endPos = Buffer.add_string buf (col NoColor "\n"); | Number line_number -> begin content |> List.iteri (fun i line -> - if i = 0 then begin - let gutter_color = - if i = 0 - && line_number >= highlight_line_start_line - && line_number <= highlight_line_end_line then - if is_warning then Warn else Err - else NoColor - in - draw_gutter gutter_color (string_of_int line_number); - end else begin - (* TODO: remove this branch after the next PR *) - let pad = String.make (max_line_digits_count + indent + 3) ' ' in - Buffer.add_string buf (col NoColor pad); - end; + let gutter_content = if i = 0 then string_of_int line_number else "" in + let gutter_color = + if i = 0 + && line_number >= highlight_line_start_line + && line_number <= highlight_line_end_line then + if is_warning then Warn else Err + else NoColor + in + draw_gutter gutter_color gutter_content; line.s |> String.iteri (fun ii ch -> let c = diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 6aaedc785d..e85db4fc0a 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -433704,20 +433704,15 @@ let print ~is_warning ~src ~startPos ~endPos = Buffer.add_string buf (col NoColor "\n"); | Number line_number -> begin content |> List.iteri (fun i line -> - if i = 0 then begin - let gutter_color = - if i = 0 - && line_number >= highlight_line_start_line - && line_number <= highlight_line_end_line then - if is_warning then Warn else Err - else NoColor - in - draw_gutter gutter_color (string_of_int line_number); - end else begin - (* TODO: remove this branch after the next PR *) - let pad = String.make (max_line_digits_count + indent + 3) ' ' in - Buffer.add_string buf (col NoColor pad); - end; + let gutter_content = if i = 0 then string_of_int line_number else "" in + let gutter_color = + if i = 0 + && line_number >= highlight_line_start_line + && line_number <= highlight_line_end_line then + if is_warning then Warn else Err + else NoColor + in + draw_gutter gutter_color gutter_content; line.s |> String.iteri (fun ii ch -> let c =