-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
633 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(library | ||
(name petanque_json) | ||
(public_name coq-lsp.petanque.json) | ||
(modules :standard \ pet) | ||
(preprocess | ||
(staged_pps ppx_import ppx_deriving_yojson)) | ||
(libraries cmdliner lsp petanque)) | ||
|
||
(executable | ||
(name pet) | ||
(public_name pet) | ||
(modules pet) | ||
(libraries petanque_json)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
open Protocol | ||
module A = Petanque.Agent | ||
|
||
let do_request ~token (module R : Request.S) ~id ~params = | ||
match R.Params.of_yojson (`Assoc params) with | ||
| Ok params -> ( | ||
match R.handler ~token params with | ||
| Ok result -> | ||
let result = R.Response.to_yojson result in | ||
Lsp.Base.mk_reply ~id ~result | ||
| Error err -> | ||
let message = A.Error.to_string err in | ||
let code = A.Error.to_code err in | ||
Lsp.Base.mk_request_error ~id ~code ~message) | ||
| Error message -> | ||
(* JSON-RPC Parse error *) | ||
let code = -32700 in | ||
Lsp.Base.mk_request_error ~id ~code ~message | ||
|
||
let handle_request ~token ~id ~method_ ~params = | ||
match method_ with | ||
| s when String.equal Init.method_ s -> | ||
do_request ~token (module Init) ~id ~params | ||
| s when String.equal Start.method_ s -> | ||
do_request ~token (module Start) ~id ~params | ||
| s when String.equal RunTac.method_ s -> | ||
do_request ~token (module RunTac) ~id ~params | ||
| s when String.equal Goals.method_ s -> | ||
do_request ~token (module Goals) ~id ~params | ||
| s when String.equal Premises.method_ s -> | ||
do_request ~token (module Premises) ~id ~params | ||
| _ -> | ||
(* JSON-RPC method not found *) | ||
let code = -32601 in | ||
let message = "method not found" in | ||
Lsp.Base.mk_request_error ~id ~code ~message | ||
|
||
let interp ~token (r : Lsp.Base.Message.t) : Yojson.Safe.t option = | ||
match r with | ||
| Request { id; method_; params } -> | ||
Some (handle_request ~token ~id ~method_ ~params) | ||
| Notification { method_ = _; params = _ } -> None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(* Serialization for agent types *) | ||
|
||
(* Implement State.t and Env.t serialization methods *) | ||
module State = Obj_map.Make (Petanque.Agent.State) | ||
module Env = Obj_map.Make (Petanque.Agent.Env) | ||
|
||
(* The typical protocol dance *) | ||
|
||
module Result = struct | ||
include Result | ||
|
||
type ('a, 'e) t = [%import: ('a, 'e) Result.t] [@@deriving yojson] | ||
end | ||
|
||
module Error = struct | ||
type t = [%import: Petanque.Agent.Error.t] [@@deriving yojson] | ||
end | ||
|
||
module R = struct | ||
type 'a t = [%import: 'a Petanque.Agent.R.t] [@@deriving yojson] | ||
end | ||
|
||
module Goals = struct | ||
type t = string Lsp.JCoq.Goals.reified_pp option [@@deriving yojson] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module type Obj = sig | ||
type t | ||
(* Not yet *) | ||
(* val equal : t -> t -> bool *) | ||
end | ||
|
||
module type S = sig | ||
type t [@@deriving yojson] | ||
end | ||
|
||
module Make (O : Obj) : S with type t = O.t = struct | ||
type t = O.t | ||
type _t = int [@@deriving yojson] | ||
|
||
module Memo = Hashtbl.Make (Int) | ||
|
||
let memo = Memo.create 1000 | ||
|
||
let dump_memo () = | ||
let keys = Memo.to_seq_keys memo |> List.of_seq in | ||
Format.(eprintf "@[size: %d@]@\n%!" (List.length keys)); | ||
Format.(eprintf "@[<v>%a@]@\n%!" (pp_print_list pp_print_int) keys) | ||
|
||
let last_id = ref 0 | ||
|
||
let mk_id _ = | ||
incr last_id; | ||
!last_id | ||
|
||
let of_obj (s : O.t) : int = | ||
let id = mk_id s in | ||
let () = Memo.add memo id s in | ||
id | ||
|
||
let to_obj (id : int) : O.t = | ||
try Memo.find memo id | ||
with Not_found -> | ||
dump_memo (); | ||
raise Not_found | ||
|
||
let of_yojson json = _t_of_yojson json |> Result.map to_obj | ||
let to_yojson st : Yojson.Safe.t = of_obj st |> _t_to_yojson | ||
end |
Oops, something went wrong.