Skip to content

Commit

Permalink
fix: improve error messages when merlin is absent
Browse files Browse the repository at this point in the history
ps-id: 5AE68BEC-4D7B-4289-9D58-C1D993F443F8
  • Loading branch information
rgrinberg committed Feb 4, 2022
1 parent 06f9a80 commit bb23057
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Fix infer interface code action crash when implementation source does not
exist (#597)

- Improve error message when the reason plugin for merlin is absent (#608

# 1.9.1

## Fixes
Expand Down
1 change: 1 addition & 0 deletions ocaml-lsp-server/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
lsp
lsp_fiber
dot-merlin-reader.merlin_dot_protocol
merlin.extend
merlin.analysis
merlin.kernel
merlin.merlin_utils
Expand Down
29 changes: 18 additions & 11 deletions ocaml-lsp-server/src/ocaml_lsp_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,19 @@ let set_diagnostics rpc doc =
async (fun () -> Diagnostics.send state.diagnostics (`One uri))
| Reason
| Ocaml ->
async (fun () ->
let* diagnostics =
let command =
Query_protocol.Errors
{ lexing = true; parsing = true; typing = true }
in
Document.with_pipeline_exn doc (fun pipeline ->
let errors = Query_commands.dispatch pipeline command in
let send () =
let* diagnostics =
let command =
Query_protocol.Errors { lexing = true; parsing = true; typing = true }
in
Document.with_pipeline_exn doc (fun pipeline ->
match Query_commands.dispatch pipeline command with
| exception Extend_main.Handshake.Error error ->
let message =
sprintf "%s.\nHint: install merlin-extend reason" error
in
[ create_diagnostic ~range:Range.first_line ~message () ]
| errors ->
let merlin_diagnostics =
List.rev_map errors ~f:(fun (error : Loc.error) ->
let loc = Loc.loc_of_report error in
Expand Down Expand Up @@ -244,9 +249,11 @@ let set_diagnostics rpc doc =
|> List.sort
~compare:(fun (d1 : Diagnostic.t) (d2 : Diagnostic.t) ->
Range.compare d1.range d2.range))
in
Diagnostics.set state.diagnostics (`Merlin (uri, diagnostics));
Diagnostics.send state.diagnostics (`One uri))
in
Diagnostics.set state.diagnostics (`Merlin (uri, diagnostics));
Diagnostics.send state.diagnostics (`One uri)
in
async send

let on_initialize server (ip : InitializeParams.t) =
let state : State.t = Server.state server in
Expand Down

0 comments on commit bb23057

Please sign in to comment.