Skip to content

Commit 1db22dc

Browse files
authored
Fix location when reporting errors in another file (#1310)
This PR fixes the issue #1299 . The new solution checks the error is located in the same file. If not, the error is reported on the import command displaying the location in the imported file
1 parent 4c20b63 commit 1db22dc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/lsp/lp_doc.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,19 @@ let process_cmd _file (nodes,st,dg,logs) ast =
121121

122122
| Cmd_Error(loc, msg) ->
123123
let nodes = { ast; exec = false; goals = [] } :: nodes in
124-
let loc = option_default loc Command.(get_pos ast) in
125-
nodes, st, (loc, 1, msg, None) :: dg, ((1, msg), loc) :: logs
124+
let cmd_loc, loc = match cmd_loc, loc with
125+
| Some l, Some Some l' ->
126+
if l.fname = l'.fname then
127+
(* if error in the same file, use the precise location *)
128+
Some l', Some l'
129+
else
130+
(* else, use the location of the command *)
131+
cmd_loc, Some l'
132+
(* Otherwise,
133+
cmd_loc doesn't change and loc is : option_default loc cmd_loc *)
134+
| _, Some l' -> cmd_loc, l'
135+
| _, None -> cmd_loc, cmd_loc in
136+
nodes, st, (cmd_loc, 1, msg, None) :: dg, ((1, msg), loc) :: logs
126137

127138
let new_doc ~uri ~version ~text =
128139
let root, logs =

0 commit comments

Comments
 (0)