Truncated view for blocks longer than 10 lines
Signed-off-by: Anurag Soni <anuragsoni.13@gmail.com>
This commit is contained in:
parent
6657247897
commit
81797f86cc
|
@ -2,6 +2,10 @@ open! Stdune
|
|||
|
||||
exception Already_reported
|
||||
|
||||
let max_lines_to_print_in_full = 10
|
||||
|
||||
let context_lines = 2
|
||||
|
||||
let err_buf = Buffer.create 128
|
||||
let err_ppf = Format.formatter_of_buffer err_buf
|
||||
let kerrf fmt ~f =
|
||||
|
@ -75,14 +79,37 @@ let print ppf loc =
|
|||
Format.fprintf pp "%s\n%*s\n" line
|
||||
stop_c
|
||||
(String.make len '^')
|
||||
else if num_lines <= 10 then
|
||||
let lines = file_lines path ~start:start.pos_lnum ~stop:stop.pos_lnum in
|
||||
let last_lnum = Option.map ~f:fst (List.last lines) in
|
||||
let padding_width = Option.value_exn
|
||||
(Option.map ~f:String.length last_lnum) in
|
||||
else
|
||||
let get_padding lines =
|
||||
let (lnum, _) = Option.value_exn (List.last lines) in
|
||||
String.length lnum
|
||||
in
|
||||
let print_ellipsis padding_width =
|
||||
(* We add 2 to the width of max line to account for
|
||||
the extra space and the `|` character at the end
|
||||
of a line number *)
|
||||
let line = String.make (padding_width + 2) '.' in
|
||||
Format.fprintf pp "%s\n" line
|
||||
in
|
||||
let print_lines lines padding_width =
|
||||
List.iter ~f:(fun (lnum, l) ->
|
||||
Format.fprintf pp "%*s: %s\n" padding_width lnum l)
|
||||
lines
|
||||
Format.fprintf pp "%*s | %s\n" padding_width lnum l) lines;
|
||||
in
|
||||
if num_lines <= max_lines_to_print_in_full then
|
||||
let lines = file_lines path ~start:start.pos_lnum ~stop:stop.pos_lnum in
|
||||
print_lines lines (get_padding lines)
|
||||
else
|
||||
(* We need to send the padding width from the last four lines
|
||||
so the two blocks of lines align if they have different number
|
||||
of digits in their line numbers *)
|
||||
let first_shown_lines = file_lines path ~start:(start.pos_lnum)
|
||||
~stop:(start.pos_lnum + context_lines) in
|
||||
let last_shown_lines = file_lines path ~start:(stop.pos_lnum - context_lines)
|
||||
~stop:(stop.pos_lnum) in
|
||||
let padding_width = get_padding last_shown_lines in
|
||||
(print_lines first_shown_lines padding_width;
|
||||
print_ellipsis padding_width;
|
||||
print_lines last_shown_lines padding_width)
|
||||
in
|
||||
Format.fprintf ppf
|
||||
"@{<loc>File \"%s\", line %d, characters %d-%d:@}@\n%a"
|
||||
|
|
|
@ -24,8 +24,8 @@ Errors:
|
|||
$ dune build --display short --root a foo.cma
|
||||
Entering directory 'a'
|
||||
File "dune", line 1, characters 0-21:
|
||||
1: (library
|
||||
2: (name foo))
|
||||
1 | (library
|
||||
2 | (name foo))
|
||||
Warning: Some modules don't have an implementation.
|
||||
You need to add the following field to this stanza:
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ Exact path provided by the user:
|
|||
$ dune runtest --root precise-path
|
||||
Entering directory 'precise-path'
|
||||
File "dune", line 1, characters 0-49:
|
||||
1: (alias
|
||||
2: (name runtest)
|
||||
3: (action (run ./foo.exe)))
|
||||
1 | (alias
|
||||
2 | (name runtest)
|
||||
3 | (action (run ./foo.exe)))
|
||||
Error: No rule found for foo.exe
|
||||
[1]
|
||||
|
||||
|
@ -24,8 +24,8 @@ Path in deps field of alias stanza
|
|||
$ dune runtest --root alias-deps-field
|
||||
Entering directory 'alias-deps-field'
|
||||
File "dune", line 1, characters 0-38:
|
||||
1: (alias
|
||||
2: (name runtest)
|
||||
3: (deps foobar))
|
||||
1 | (alias
|
||||
2 | (name runtest)
|
||||
3 | (deps foobar))
|
||||
Error: No rule found for foobar
|
||||
[1]
|
||||
|
|
|
@ -3,11 +3,11 @@ message is displayed:
|
|||
|
||||
$ dune build --root=public --display=short
|
||||
File "jbuild", line 4, characters 2-74:
|
||||
4: (
|
||||
5: (name mylib)
|
||||
6: (public_name mylib)
|
||||
7: (modes (shared_object))
|
||||
8: )
|
||||
4 | (
|
||||
5 | (name mylib)
|
||||
6 | (public_name mylib)
|
||||
7 | (modes (shared_object))
|
||||
8 | )
|
||||
Error: No installable mode found for this executable.
|
||||
One of the following modes is required:
|
||||
- exe
|
||||
|
|
|
@ -5,9 +5,9 @@ displayed. This can happen for:
|
|||
|
||||
$ dune build --root executable
|
||||
File "dune", line 1, characters 0-43:
|
||||
1: (executable
|
||||
2: (public_name an_executable)
|
||||
3: )
|
||||
1 | (executable
|
||||
2 | (public_name an_executable)
|
||||
3 | )
|
||||
Error: I can't determine automatically which package this stanza is for.
|
||||
I have the choice between these ones:
|
||||
- pkg1 (because of pkg1.opam)
|
||||
|
@ -32,10 +32,10 @@ displayed. This can happen for:
|
|||
|
||||
$ dune build --root install
|
||||
File "dune", line 1, characters 0-44:
|
||||
1: (install
|
||||
2: (section etc)
|
||||
3: (files file.conf)
|
||||
4: )
|
||||
1 | (install
|
||||
2 | (section etc)
|
||||
3 | (files file.conf)
|
||||
4 | )
|
||||
Error: I can't determine automatically which package this stanza is for.
|
||||
I have the choice between these ones:
|
||||
- pkg1 (because of pkg1.opam)
|
||||
|
|
|
@ -3,11 +3,11 @@ are readable.
|
|||
|
||||
$ dune build --root a
|
||||
File "dune", line 1, characters 12-72:
|
||||
1: (executable (
|
||||
2: (name hello)
|
||||
3: (public_name hello)
|
||||
4: (libraries (lib))
|
||||
5: ))
|
||||
1 | (executable (
|
||||
2 | (name hello)
|
||||
3 | (public_name hello)
|
||||
4 | (libraries (lib))
|
||||
5 | ))
|
||||
Error: Atom expected
|
||||
Hint: dune files require less parentheses than jbuild files.
|
||||
If you just converted this file from a jbuild file, try removing these parentheses.
|
||||
|
@ -31,9 +31,16 @@ are readable.
|
|||
If you just converted this file from a jbuild file, try removing these parentheses.
|
||||
[1]
|
||||
|
||||
Checking that extra long stanzas (over 10 lines) are not printed
|
||||
Checking that extra long stanzas (over 10 lines) are truncated in the middle, and the two blocks are aligned.
|
||||
$ dune build --root d
|
||||
File "dune", line 3, characters 13-192:
|
||||
3 | (libraries (a
|
||||
4 | b
|
||||
5 | c
|
||||
....
|
||||
12 | j
|
||||
13 | k
|
||||
14 | l)
|
||||
Error: 'select' expected
|
||||
Hint: dune files require less parentheses than jbuild files.
|
||||
If you just converted this file from a jbuild file, try removing these parentheses.
|
||||
|
|
|
@ -9,7 +9,7 @@ Variant feature is auto enabled when virtual_modules is used
|
|||
|
||||
$ dune build --root variants-using
|
||||
File "dune-project", line 2, characters 42-45:
|
||||
2:
|
||||
2 |
|
||||
Error: Version 0.1 of in_development_do_not_use_variants is not supported.
|
||||
Supported versions:
|
||||
- 0.0
|
||||
|
|
Loading…
Reference in New Issue