mirror of
https://github.com/c-cube/linol.git
synced 2025-12-06 11:15:46 -05:00
Compare commits
5 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6e84391e7 | ||
|
|
705cc47ddf | ||
|
|
40843b81db | ||
|
|
fb49472f34 | ||
|
|
00479b0f05 |
5 changed files with 27 additions and 20 deletions
|
|
@ -1,4 +1,9 @@
|
||||||
|
|
||||||
|
# 0.11
|
||||||
|
|
||||||
|
- breaking: the Eio library now needs the output channel to be paired with
|
||||||
|
an `Eio.Mutex.t` to prevent race conditions (#58)
|
||||||
|
|
||||||
# 0.10
|
# 0.10
|
||||||
|
|
||||||
- use `git subtree` to vendor lsp+jsonrpc, so that they
|
- use `git subtree` to vendor lsp+jsonrpc, so that they
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
(synopsis "LSP server library")
|
(synopsis "LSP server library")
|
||||||
(depends
|
(depends
|
||||||
("yojson"
|
("yojson"
|
||||||
(>= "1.6"))
|
(and (>= "1.6") (< "3.0")))
|
||||||
"logs"
|
"logs"
|
||||||
("trace"
|
("trace"
|
||||||
(>= "0.4"))
|
(>= "0.4"))
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ let diagnostics (_state : state_after_processing) : Lsp.Types.Diagnostic.t list
|
||||||
so that users only need to override methods that they want the server to
|
so that users only need to override methods that they want the server to
|
||||||
actually meaningfully interpret and respond to.
|
actually meaningfully interpret and respond to.
|
||||||
*)
|
*)
|
||||||
class lsp_server =
|
class lsp_server ~(sw: Eio.Switch.t) =
|
||||||
object (self)
|
object (self)
|
||||||
inherit Linol_eio.Jsonrpc2.server
|
inherit Linol_eio.Jsonrpc2.server
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ class lsp_server =
|
||||||
val buffers : (Lsp.Types.DocumentUri.t, state_after_processing) Hashtbl.t =
|
val buffers : (Lsp.Types.DocumentUri.t, state_after_processing) Hashtbl.t =
|
||||||
Hashtbl.create 32
|
Hashtbl.create 32
|
||||||
|
|
||||||
method spawn_query_handler f = Linol_eio.spawn f
|
method spawn_query_handler f = Linol_eio.spawn ~sw f
|
||||||
|
|
||||||
(* We define here a helper method that will:
|
(* We define here a helper method that will:
|
||||||
- process a document
|
- process a document
|
||||||
|
|
@ -82,7 +82,8 @@ class lsp_server =
|
||||||
and runs it as a task. *)
|
and runs it as a task. *)
|
||||||
let run () =
|
let run () =
|
||||||
Eio_main.run @@ fun env ->
|
Eio_main.run @@ fun env ->
|
||||||
let s = new lsp_server in
|
Eio.Switch.run @@ fun sw ->
|
||||||
|
let s = new lsp_server ~sw in
|
||||||
let server = Linol_eio.Jsonrpc2.create_stdio ~env s in
|
let server = Linol_eio.Jsonrpc2.create_stdio ~env s in
|
||||||
let task () =
|
let task () =
|
||||||
let shutdown () = s#get_status = `ReceivedExit in
|
let shutdown () = s#get_status = `ReceivedExit in
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ homepage: "https://github.com/c-cube/linol"
|
||||||
bug-reports: "https://github.com/c-cube/linol/issues"
|
bug-reports: "https://github.com/c-cube/linol/issues"
|
||||||
depends: [
|
depends: [
|
||||||
"dune" {>= "2.0"}
|
"dune" {>= "2.0"}
|
||||||
"yojson" {>= "1.6"}
|
"yojson" {>= "1.6" & < "3.0"}
|
||||||
"logs"
|
"logs"
|
||||||
"trace" {>= "0.4"}
|
"trace" {>= "0.4"}
|
||||||
"ocaml" {>= "4.14"}
|
"ocaml" {>= "4.14"}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module IO_eio :
|
||||||
with type 'a t = 'a
|
with type 'a t = 'a
|
||||||
and type env = Eio_unix.Stdenv.base
|
and type env = Eio_unix.Stdenv.base
|
||||||
and type in_channel = Eio.Buf_read.t
|
and type in_channel = Eio.Buf_read.t
|
||||||
and type out_channel = Eio_unix.sink_ty Eio.Std.r = struct
|
and type out_channel = Eio.Mutex.t * Eio_unix.sink_ty Eio.Std.r = struct
|
||||||
type 'a t = 'a
|
type 'a t = 'a
|
||||||
|
|
||||||
let ( let+ ) x f = f x
|
let ( let+ ) x f = f x
|
||||||
|
|
@ -28,17 +28,21 @@ module IO_eio :
|
||||||
let stdin env =
|
let stdin env =
|
||||||
Eio.Buf_read.of_flow ~max_size:1_000_000 (Eio.Stdenv.stdin env)
|
Eio.Buf_read.of_flow ~max_size:1_000_000 (Eio.Stdenv.stdin env)
|
||||||
|
|
||||||
let stdout = Eio.Stdenv.stdout
|
let stdout_mutex = Eio.Mutex.create ()
|
||||||
|
let stdout env = stdout_mutex, Eio.Stdenv.stdout env
|
||||||
|
|
||||||
type env = Eio_unix.Stdenv.base
|
type env = Eio_unix.Stdenv.base
|
||||||
type in_channel = Eio.Buf_read.t
|
type in_channel = Eio.Buf_read.t
|
||||||
type out_channel = Eio_unix.sink_ty Eio.Std.r
|
type out_channel = Eio.Mutex.t * Eio_unix.sink_ty Eio.Std.r
|
||||||
|
|
||||||
let write_string out_ch str = Eio.Flow.copy_string str out_ch
|
let write_string (mutex, out_ch) str =
|
||||||
|
Eio.Mutex.use_rw ~protect:false mutex (fun () ->
|
||||||
|
Eio.Flow.copy_string str out_ch)
|
||||||
|
|
||||||
let write out_ch bytes off len =
|
let write (mutex, out_ch) bytes off len =
|
||||||
Eio.Buf_write.with_flow out_ch @@ fun w ->
|
Eio.Mutex.use_rw ~protect:false mutex (fun () ->
|
||||||
Eio.Buf_write.bytes w ~off ~len bytes
|
Eio.Buf_write.with_flow out_ch @@ fun w ->
|
||||||
|
Eio.Buf_write.bytes w ~off ~len bytes)
|
||||||
|
|
||||||
let read in_ch bytes off len =
|
let read in_ch bytes off len =
|
||||||
let str = Eio.Buf_read.take len in_ch in
|
let str = Eio.Buf_read.take len in_ch in
|
||||||
|
|
@ -48,17 +52,14 @@ module IO_eio :
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Spawn function. *)
|
(** Spawn function. *)
|
||||||
let spawn f =
|
let spawn ~sw f =
|
||||||
let promise, resolver = Eio.Promise.create () in
|
Eio.Fiber.fork ~sw (fun () ->
|
||||||
(try
|
try
|
||||||
f ();
|
f ()
|
||||||
Eio.Promise.resolve_ok resolver ()
|
|
||||||
with exn ->
|
with exn ->
|
||||||
Printf.eprintf "uncaught exception in `spawn`:\n%s\n%!"
|
Printf.eprintf "uncaught exception in `spawn`:\n%s\n%!"
|
||||||
(Printexc.to_string exn);
|
(Printexc.to_string exn);
|
||||||
Eio.Promise.resolve_error resolver exn);
|
raise exn)
|
||||||
|
|
||||||
Eio.Promise.await_exn promise
|
|
||||||
|
|
||||||
include Lsp.Types
|
include Lsp.Types
|
||||||
include IO_eio
|
include IO_eio
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue