Skip to content

Commit

Permalink
Merge pull request #766 from ejgallego/petanque_init
Browse files Browse the repository at this point in the history
[petanque] Allow `init` to be called multiple times
  • Loading branch information
ejgallego authored Jun 7, 2024
2 parents dc81772 + 898472e commit 01ddb38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
- [code] Don't start server on extension activation, unless an editor
we own is active. We also auto-start the server if a document that
we own is opened later (@ejgallego, #758, fixes #750)
- [petanque] Allow `init` to be called multiple times (@ejgallego,
@gbdrt, #766)

# coq-lsp 0.1.10: Hasta el 40 de Mayo _en effect_...
----------------------------------------------------
Expand Down
18 changes: 15 additions & 3 deletions petanque/agent.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,28 @@ let print_diags (doc : Fleche.Doc.t) =
let d = Fleche.Doc.diags doc in
Format.(eprintf "@[<v>%a@]" (pp_print_list pp_diag) d)

let init ~token ~debug ~root =
let init = init_coq ~debug in
Fleche.Io.CallBack.set io;
let setup_workspace ~token ~init ~debug ~root =
let dir = Lang.LUri.File.to_string_file root in
(let open Coq.Compat.Result.O in
let+ workspace = Coq.Workspace.guess ~token ~debug ~cmdline ~dir in
let files = Coq.Files.make () in
Fleche.Doc.Env.make ~init ~workspace ~files)
|> Result.map_error (fun msg -> Error.Coq msg)

let init_st = ref None

let init ~token ~debug ~root =
let init =
match !init_st with
| None ->
let init = init_coq ~debug in
Fleche.Io.CallBack.set io;
init_st := Some init;
init
| Some init -> init
in
setup_workspace ~token ~init ~debug ~root

let start ~token ~env ~uri ~thm =
match read_raw ~uri with
| Ok raw ->
Expand Down
2 changes: 2 additions & 0 deletions petanque/test/basic_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let start ~token =
(* Will this work on Windows? *)
let open Coq.Compat.Result.O in
let root, uri = prepare_paths () in
(* Twice to test for #766 *)
let* _env = Agent.init ~token ~debug ~root in
let* env = Agent.init ~token ~debug ~root in
Agent.start ~token ~env ~uri ~thm:"rev_snoc_cons"

Expand Down

0 comments on commit 01ddb38

Please sign in to comment.