Skip to content

Commit

Permalink
Merge pull request ejgallego#547 from ejgallego/fix_parsing_of_waitin…
Browse files Browse the repository at this point in the history
…g_requests

[lsp] Fix bug when retrieving URIs from document params
  • Loading branch information
ejgallego committed Sep 21, 2023
2 parents 22e773b + 21d06ac commit dc242bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
Saavedra (@Nfsaavedra, #536)
- Properly concatenate warnings from _CoqProject (@ejgallego,
reported by @mituharu, #541, fixes #540)
- Fix broken `coq/saveVo` and `coq/getDocument` requests due to a
parsing problem with extra fields in their requests (@ejgallego,
#549, reported by @Zimmi48)

# coq-lsp 0.1.7: Just-in-time
-----------------------------
Expand Down
16 changes: 13 additions & 3 deletions controller/lsp_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ module LIO = Lsp.Io
module LSP = Lsp.Base

module Helpers = struct
(* helpers; fix to have better errors on wrong protocol code *)
(* XXX helpers; fix to have better errors on wrong protocol code *)
(* Also note that rely sometimes on "subtyping" of fields, that's something to
think about better and fix, see #547 *)
let get_uri params =
let document =
field "textDocument" params
|> Lsp.Doc.TextDocumentIdentifier.of_yojson |> Result.get_ok
match
field "textDocument" params |> Lsp.Doc.TextDocumentIdentifier.of_yojson
with
| Ok uri -> uri
| Error err ->
(* ppx_deriving_yojson error messages leave a lot to be desired *)
let message = Format.asprintf "json parsing failed: %s" err in
LIO.logMessage ~lvl:1 ~message;
(* XXX Fixme *)
CErrors.user_err (Pp.str "failed to parse uri")
in
let Lsp.Doc.TextDocumentIdentifier.{ uri } = document in
uri
Expand Down
4 changes: 3 additions & 1 deletion lsp/doc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ module TextDocumentItem = struct
[@@deriving yojson]
end

(* Sometimes we use this to parse VersionedTextDocumentIdentifier, we use {
strict = false } as a quick fix *)
module TextDocumentIdentifier = struct
type t = { uri : Lang.LUri.File.t } [@@deriving yojson]
type t = { uri : Lang.LUri.File.t } [@@deriving yojson { strict = false }]
end

module OVersionedTextDocumentIdentifier = struct
Expand Down

0 comments on commit dc242bb

Please sign in to comment.