Merge pull request #1143 from anuragsoni/highlight-multi-line-errors
multi line error highlights
This commit is contained in:
commit
6e7778c413
|
@ -19,6 +19,7 @@ next
|
||||||
|
|
||||||
- Fix parsing `ocamllex` stanza in jbuild files (#1150, @rgrinberg)
|
- Fix parsing `ocamllex` stanza in jbuild files (#1150, @rgrinberg)
|
||||||
|
|
||||||
|
- Highlight multi-line errors (#1131, @anuragsoni)
|
||||||
|
|
||||||
1.1.1 (08/08/2018)
|
1.1.1 (08/08/2018)
|
||||||
------------------
|
------------------
|
||||||
|
|
25
src/loc.ml
25
src/loc.ml
|
@ -70,10 +70,27 @@ let file_line path n =
|
||||||
input_line ic
|
input_line ic
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let file_lines path ~start ~stop =
|
||||||
|
Io.with_file_in ~binary:true path
|
||||||
|
~f:(fun ic ->
|
||||||
|
let rec aux acc lnum =
|
||||||
|
if lnum > stop then
|
||||||
|
List.rev acc
|
||||||
|
else if lnum < start then
|
||||||
|
(ignore (input_line ic);
|
||||||
|
aux acc (lnum + 1))
|
||||||
|
else
|
||||||
|
let line = input_line ic in
|
||||||
|
aux ((string_of_int lnum, line) :: acc) (lnum + 1)
|
||||||
|
in
|
||||||
|
aux [] 1
|
||||||
|
)
|
||||||
|
|
||||||
let print ppf loc =
|
let print ppf loc =
|
||||||
let { start; stop } = loc in
|
let { start; stop } = loc in
|
||||||
let start_c = start.pos_cnum - start.pos_bol in
|
let start_c = start.pos_cnum - start.pos_bol in
|
||||||
let stop_c = stop.pos_cnum - start.pos_bol in
|
let stop_c = stop.pos_cnum - start.pos_bol in
|
||||||
|
let num_lines = stop.pos_lnum - start.pos_lnum in
|
||||||
let pp_file_excerpt pp () =
|
let pp_file_excerpt pp () =
|
||||||
let whole_file = start_c = 0 && stop_c = 0 in
|
let whole_file = start_c = 0 && stop_c = 0 in
|
||||||
if not whole_file then
|
if not whole_file then
|
||||||
|
@ -85,6 +102,14 @@ let print ppf loc =
|
||||||
Format.fprintf pp "%s\n%*s\n" line
|
Format.fprintf pp "%s\n%*s\n" line
|
||||||
stop_c
|
stop_c
|
||||||
(String.make len '^')
|
(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
|
||||||
|
List.iter ~f:(fun (lnum, l) ->
|
||||||
|
Format.fprintf pp "%*s: %s\n" padding_width lnum l)
|
||||||
|
lines
|
||||||
in
|
in
|
||||||
Format.fprintf ppf
|
Format.fprintf ppf
|
||||||
"@{<loc>File \"%s\", line %d, characters %d-%d:@}@\n%a"
|
"@{<loc>File \"%s\", line %d, characters %d-%d:@}@\n%a"
|
||||||
|
|
|
@ -24,6 +24,8 @@ Errors:
|
||||||
$ dune build --display short --root a foo.cma
|
$ dune build --display short --root a foo.cma
|
||||||
Entering directory 'a'
|
Entering directory 'a'
|
||||||
File "dune", line 1, characters 0-21:
|
File "dune", line 1, characters 0-21:
|
||||||
|
1: (library
|
||||||
|
2: (name foo))
|
||||||
Warning: Some modules don't have an implementation.
|
Warning: Some modules don't have an implementation.
|
||||||
You need to add the following field to this stanza:
|
You need to add the following field to this stanza:
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ Exact path provided by the user:
|
||||||
$ dune runtest --root precise-path
|
$ dune runtest --root precise-path
|
||||||
Entering directory 'precise-path'
|
Entering directory 'precise-path'
|
||||||
File "dune", line 1, characters 0-49:
|
File "dune", line 1, characters 0-49:
|
||||||
|
1: (alias
|
||||||
|
2: (name runtest)
|
||||||
|
3: (action (run ./foo.exe)))
|
||||||
Error: No rule found for foo.exe
|
Error: No rule found for foo.exe
|
||||||
[1]
|
[1]
|
||||||
|
|
||||||
|
@ -21,5 +24,8 @@ Path in deps field of alias stanza
|
||||||
$ dune runtest --root alias-deps-field
|
$ dune runtest --root alias-deps-field
|
||||||
Entering directory 'alias-deps-field'
|
Entering directory 'alias-deps-field'
|
||||||
File "dune", line 1, characters 0-38:
|
File "dune", line 1, characters 0-38:
|
||||||
|
1: (alias
|
||||||
|
2: (name runtest)
|
||||||
|
3: (deps foobar))
|
||||||
Error: No rule found for foobar
|
Error: No rule found for foobar
|
||||||
[1]
|
[1]
|
||||||
|
|
|
@ -3,6 +3,11 @@ message is displayed:
|
||||||
|
|
||||||
$ dune build --root=public --display=short
|
$ dune build --root=public --display=short
|
||||||
File "jbuild", line 4, characters 2-74:
|
File "jbuild", line 4, characters 2-74:
|
||||||
|
4: (
|
||||||
|
5: (name mylib)
|
||||||
|
6: (public_name mylib)
|
||||||
|
7: (modes (shared_object))
|
||||||
|
8: )
|
||||||
Error: No installable mode found for this executable.
|
Error: No installable mode found for this executable.
|
||||||
One of the following modes is required:
|
One of the following modes is required:
|
||||||
- exe
|
- exe
|
||||||
|
|
|
@ -5,6 +5,9 @@ displayed. This can happen for:
|
||||||
|
|
||||||
$ dune build --root executable
|
$ dune build --root executable
|
||||||
File "dune", line 1, characters 0-43:
|
File "dune", line 1, characters 0-43:
|
||||||
|
1: (executable
|
||||||
|
2: (public_name an_executable)
|
||||||
|
3: )
|
||||||
Error: I can't determine automatically which package this stanza is for.
|
Error: I can't determine automatically which package this stanza is for.
|
||||||
I have the choice between these ones:
|
I have the choice between these ones:
|
||||||
- pkg1 (because of pkg1.opam)
|
- pkg1 (because of pkg1.opam)
|
||||||
|
@ -29,6 +32,10 @@ displayed. This can happen for:
|
||||||
|
|
||||||
$ dune build --root install
|
$ dune build --root install
|
||||||
File "dune", line 1, characters 0-44:
|
File "dune", line 1, characters 0-44:
|
||||||
|
1: (install
|
||||||
|
2: (section etc)
|
||||||
|
3: (files file.conf)
|
||||||
|
4: )
|
||||||
Error: I can't determine automatically which package this stanza is for.
|
Error: I can't determine automatically which package this stanza is for.
|
||||||
I have the choice between these ones:
|
I have the choice between these ones:
|
||||||
- pkg1 (because of pkg1.opam)
|
- pkg1 (because of pkg1.opam)
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
(executable
|
||||||
|
(name hello)
|
||||||
|
(libraries (a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
d
|
||||||
|
e
|
||||||
|
f
|
||||||
|
g
|
||||||
|
h
|
||||||
|
i
|
||||||
|
j
|
||||||
|
k
|
||||||
|
l)
|
||||||
|
))
|
|
@ -0,0 +1 @@
|
||||||
|
(lang dune 1.0)
|
|
@ -3,6 +3,11 @@ are readable.
|
||||||
|
|
||||||
$ dune build --root a
|
$ dune build --root a
|
||||||
File "dune", line 1, characters 12-72:
|
File "dune", line 1, characters 12-72:
|
||||||
|
1: (executable (
|
||||||
|
2: (name hello)
|
||||||
|
3: (public_name hello)
|
||||||
|
4: (libraries (lib))
|
||||||
|
5: ))
|
||||||
These parentheses are no longer necessary with dune, please remove them.
|
These parentheses are no longer necessary with dune, please remove them.
|
||||||
[1]
|
[1]
|
||||||
|
|
||||||
|
@ -19,3 +24,9 @@ are readable.
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
These parentheses are no longer necessary with dune, please remove them.
|
These parentheses are no longer necessary with dune, please remove them.
|
||||||
[1]
|
[1]
|
||||||
|
|
||||||
|
Checking that extra long stanzas (over 10 lines) are not printed
|
||||||
|
$ dune build --root d
|
||||||
|
File "dune", line 3, characters 13-192:
|
||||||
|
These parentheses are no longer necessary with dune, please remove them.
|
||||||
|
[1]
|
||||||
|
|
Loading…
Reference in New Issue