refactor: split into lwt server and abstract interface

This commit is contained in:
Simon Cruanes 2021-02-09 19:40:31 -05:00
parent 33be161bd9
commit 8dff582612
10 changed files with 47 additions and 7 deletions

View file

@ -1,2 +1,3 @@
(lang dune 2.0) (lang dune 2.0)
;(implicit_transitive_deps false)
(using menhir 2.0) (using menhir 2.0)

27
linol-lwt.opam Normal file
View file

@ -0,0 +1,27 @@
opam-version: "2.0"
version: "0.1"
maintainer: "simon.cruanes.2007@m4x.org"
author: "Simon Cruanes"
homepage: "https://github.com/c-cube/linol"
synopsis: "LSP server library (with Lwt for concurrency)"
build: [
["dune" "build" "@install" "-p" name "-j" jobs]
["dune" "build" "@runtest" "-p" name "-j" jobs] {with-test}
["dune" "build" "@doc" "-p" name "-j" jobs] {with-doc}
]
depends: [
"dune" { >= "2.0" }
"linol" { = version }
"lsp" { >= "1.4" & < "1.5" }
"jsonrpc" { >= "1.4" & < "1.5" }
"containers" { >= "3.0" & < "4.0" }
"lwt" { >= "5.1" & < "6.0" }
"yojson" { >= "1.6" }
"ocaml" { >= "4.08" }
"odoc" { with-doc }
]
tags: [ "lsp" "server" "lwt" "linol" ]
bug-reports: "https://github.com/c-cube/linol/issues"
dev-repo: "git+https://github.com/c-cube/linol.git"

View file

@ -10,10 +10,9 @@ build: [
["dune" "build" "@doc" "-p" name "-j" jobs] {with-doc} ["dune" "build" "@doc" "-p" name "-j" jobs] {with-doc}
] ]
depends: [ depends: [
"dune" { >= "1.0" } "dune" { >= "2.0" }
"containers" { >= "3.0" & < "4.0" } "containers" { >= "3.0" & < "4.0" }
"lsp" { >= "1.4" & < "1.5" } "lsp" { >= "1.4" & < "1.5" }
"lwt" { >= "5.1" & < "6.0" }
"ocaml" { >= "4.08" } "ocaml" { >= "4.08" }
"odoc" { with-doc } "odoc" { with-doc }
] ]

View file

@ -1,4 +1,10 @@
(** {1 Linol}
Abstraction over The "Lsp" library, to make it easier to develop
LSP servers in OCaml (but not necessarily {b for} OCaml). *)
(** {2 Parametrized IO Interface} *)
module type IO = sig module type IO = sig
type 'a t type 'a t
val return : 'a -> 'a t val return : 'a -> 'a t
@ -10,6 +16,7 @@ module type IO = sig
type out_channel type out_channel
end end
(** {2 Server interface for some IO substrate} *)
module Make(IO : IO) = struct module Make(IO : IO) = struct
open Lsp.Types open Lsp.Types

6
src/lwt/dune Normal file
View file

@ -0,0 +1,6 @@
(library
(name linol_lwt)
(public_name linol-lwt)
(libraries yojson containers lwt lwt.unix linol lsp jsonrpc)
(flags :standard -warn-error -a))

View file

@ -20,7 +20,7 @@ module IO = struct
type out_channel = Lwt_io.output Lwt_io.channel type out_channel = Lwt_io.output Lwt_io.channel
end end
include Lsp_server.Make(IO) include Linol.Make(IO)
type json = J.t type json = J.t
type 'a m = 'a Task.m type 'a m = 'a Task.m

View file

@ -1,5 +1,5 @@
module IO : Lsp_server.IO module IO : Linol.IO
with type 'a t = 'a Task.m with type 'a t = 'a Task.m
and type in_channel = Lwt_io.input Lwt_io.channel and type in_channel = Lwt_io.input Lwt_io.channel
and type out_channel = Lwt_io.output Lwt_io.channel and type out_channel = Lwt_io.output Lwt_io.channel
@ -9,7 +9,7 @@ type json = Yojson.Safe.t
type t type t
(** A jsonrpc2 connection. *) (** A jsonrpc2 connection. *)
include module type of Lsp_server.Make(IO) include module type of Linol.Make(IO)
val create : val create :
ic:IO.in_channel -> ic:IO.in_channel ->

View file

@ -1,6 +1,6 @@
module type IO = Lsp_server.IO module type IO = Linol.IO
module Make = Lsp_server.Make module Make = Linol.Make
module Jsonrpc2 = Jsonrpc2 module Jsonrpc2 = Jsonrpc2
module Task = Task module Task = Task