Skip to content

Commit c547087

Browse files
authored
Remove duplicated position in diagnostics severity 1 (#1322)
This PR fixes issue #1311. To do so, the position of the error in diagnostics is not included in the message when such error is in the file currently open in the editor. When the error occurs in a different file ("imported" with `open` command for instance) the position is included in the diagnostic message. The position is also maintained in the messages printed in the console. Finally, hover messages are now formatted in Markdown to allow syntax highlighting.
1 parent 53871eb commit c547087

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎CHANGES.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
88
### Changed
99

1010
- `simplify` now fails if the goal cannot be simplified.
11+
- Hover messages are now formated in Markdown. Position of the error is removed from diagnostics when the error occurs
12+
in the file currently open in the editor.
1113

1214
## 3.0.0 (2025-07-16)
1315

‎src/lsp/lp_doc.ml‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,20 @@ 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 cmd_loc, loc = match cmd_loc, loc with
124+
let cmd_loc, loc, diag, log = match cmd_loc, loc with
125125
| Some l, Some Some l' ->
126126
if l.fname = l'.fname then
127127
(* if error in the same file, use the precise location *)
128-
Some l', Some l'
128+
Some l', Some l', msg, Pos.popt_to_string (Some l') ^ msg
129129
else
130130
(* else, use the location of the command *)
131-
cmd_loc, Some l'
131+
cmd_loc, Some l', Pos.popt_to_string (Some l') ^ "\n" ^ msg
132+
, Pos.popt_to_string (Some l') ^ "\n" ^ msg
132133
(* Otherwise,
133134
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
135+
| _, Some l' -> cmd_loc, l', msg, Pos.popt_to_string (l') ^ "\n" ^ msg
136+
| _, None -> cmd_loc, cmd_loc, msg, msg in
137+
nodes, st, (cmd_loc, 1, diag, None) :: dg, ((1, log), loc) :: logs
137138

138139
let new_doc ~uri ~version ~text =
139140
let root, logs =

‎src/lsp/lp_lsp.ml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ let hover_symInfo ofmt ~id params =
450450
in
451451
let sym_type = Format.asprintf "%a" Core.Print.sym_type sym_found in
452452
let result : J.t =
453-
`Assoc [ "contents", `String sym_type; "range", range ] in
453+
`Assoc [ "contents", `String ("```lambdapi\n" ^ sym_type ^ "\n```");
454+
"range", range;
455+
"kind", `String "markdown" ] in
454456
let msg = LSP.mk_reply ~id ~result in
455457
LIO.send_json ofmt msg
456458

‎src/pure/pure.ml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let handle_command : state -> Command.t -> command_result =
159159
in
160160
Cmd_Proof(ps, d.pdata_proof, d.pdata_sym_pos, d.pdata_end_pos)
161161
with Fatal(Some p,m) ->
162-
Cmd_Error(Some p, Pos.popt_to_string p ^ " " ^ m)
162+
Cmd_Error(Some p, m)
163163

164164
let handle_tactic : proof_state -> Tactic.t -> int -> tactic_result =
165165
fun (_, ss, ps, finalize, prv, sym_pos) tac n ->
@@ -174,7 +174,7 @@ let end_proof : proof_state -> command_result =
174174
fun (_, ss, ps, finalize, _, _) ->
175175
try Cmd_OK((Time.save (), finalize ss ps), None)
176176
with Fatal(Some p,m) ->
177-
Cmd_Error(Some p, Pos.popt_to_string p ^ " " ^ m)
177+
Cmd_Error(Some p, m)
178178

179179
let get_symbols : state -> Term.sym Extra.StrMap.t =
180180
fun (_, ss) -> ss.in_scope

0 commit comments

Comments
 (0)