Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Features

- Allow cancellation of formatting requests (#707)

- Add `--fallback-read-dot-merlin` to the LSP Server (#705). If `ocamllsp` is
started with this new flag, it will fall back to looking for Merlin
configuration in `.merlin` files rather than calling `dune ocaml-merlin`.
Expand Down
12 changes: 12 additions & 0 deletions ocaml-lsp-server/src/ocamlformat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ let run_command prog stdin_value args : command_result Fiber.t =
Unix.close stdin_i;
Unix.close stdout_o;
Unix.close stderr_o;
let* () =
Server.on_cancel (fun () ->
Unix.kill (Pid.to_int pid) Sys.sigint;
Fiber.return ())
in
let blockity =
if Sys.win32 then `Blocking
else (
Expand Down Expand Up @@ -114,6 +119,13 @@ let exec bin args stdin =
let+ res = run_command refmt stdin args in
match res.status with
| Unix.WEXITED 0 -> Result.Ok res.stdout
| Unix.WSIGNALED s
when s = Sys.sigint
(* TODO we should really make sure the cancellation was triggered *) ->
let e =
Jsonrpc.Response.Error.make ~code:RequestCancelled ~message:"cancelled" ()
in
raise (Jsonrpc.Response.Error.E e)
| _ -> Result.Error (Unexpected_result { message = res.stderr })

let run doc : (TextEdit.t list, error) result Fiber.t =
Expand Down