mirror of
https://github.com/c-cube/linol.git
synced 2025-12-05 19:00:34 -05:00
move to ocamlformat 0.27; format
This commit is contained in:
parent
f89022e9d0
commit
075361a3b3
5 changed files with 91 additions and 88 deletions
|
|
@ -1,4 +1,4 @@
|
|||
version = 0.26.2
|
||||
version = 0.27.0
|
||||
profile=conventional
|
||||
margin=80
|
||||
if-then-else=k-r
|
||||
|
|
|
|||
|
|
@ -124,7 +124,8 @@ module Make (IO : IO) : S with module IO = IO = struct
|
|||
`Int id
|
||||
|
||||
(** Registers a new handler for a request response. The return indicates
|
||||
whether a value was inserted or not (in which case it's already present). *)
|
||||
whether a value was inserted or not (in which case it's already present).
|
||||
*)
|
||||
let register_server_request_response_handler (self : t) (id : Req_id.t)
|
||||
(handler : server_request_handler_pair) : bool =
|
||||
if Hashtbl.mem self.pending_responses id then
|
||||
|
|
@ -363,10 +364,10 @@ module Make (IO : IO) : S with module IO = IO = struct
|
|||
Req_id.t IO.t =
|
||||
server_request self (Request_and_handler (req, cb))
|
||||
|
||||
(** [shutdown ()] is called after processing each request to check if the server
|
||||
could wait for new messages.
|
||||
When launching an LSP server using [Server.Make.server], the
|
||||
natural choice for it is [s#get_status = `ReceivedExit] *)
|
||||
(** [shutdown ()] is called after processing each request to check if the
|
||||
server could wait for new messages. When launching an LSP server using
|
||||
[Server.Make.server], the natural choice for it is
|
||||
[s#get_status = `ReceivedExit] *)
|
||||
let run ?(shutdown = fun _ -> false) (self : t) : unit IO.t =
|
||||
let async f =
|
||||
self.s#spawn_query_handler f;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
(** Simple JSON-RPC2 implementation.
|
||||
|
||||
See {{: https://www.jsonrpc.org/specification} the spec} *)
|
||||
See {{:https://www.jsonrpc.org/specification} the spec} *)
|
||||
|
||||
open Common_
|
||||
|
||||
|
|
@ -42,8 +42,8 @@ module type S = sig
|
|||
'from_server Lsp.Server_request.t ->
|
||||
(('from_server, Jsonrpc.Response.Error.t) result -> unit IO.t) ->
|
||||
Req_id.t IO.t
|
||||
(** Send a request from the server, and pass a callback that will be
|
||||
called with the result in the future.
|
||||
(** Send a request from the server, and pass a callback that will be called
|
||||
with the result in the future.
|
||||
@since 0.5 *)
|
||||
|
||||
val run : ?shutdown:(unit -> bool) -> t -> unit IO.t
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
(** Linol.
|
||||
|
||||
Abstraction over The "Lsp" library, to make it easier to develop
|
||||
LSP servers in OCaml (but not necessarily {b for} OCaml). *)
|
||||
Abstraction over The "Lsp" library, to make it easier to develop LSP servers
|
||||
in OCaml (but not necessarily {b for} OCaml). *)
|
||||
|
||||
module type IO = Sigs.IO
|
||||
|
||||
|
|
|
|||
100
src/server.ml
100
src/server.ml
|
|
@ -13,7 +13,8 @@ type nonrec doc_state = {
|
|||
|
||||
(** Request ID.
|
||||
|
||||
The unique ID of a request, used by JSONRPC to map each request to its reply. *)
|
||||
The unique ID of a request, used by JSONRPC to map each request to its
|
||||
reply. *)
|
||||
module Req_id = struct
|
||||
type t = Jsonrpc.Id.t
|
||||
|
||||
|
|
@ -62,16 +63,18 @@ module Make (IO : IO) = struct
|
|||
'a Lsp.Client_request.t ->
|
||||
('a, string) result IO.t
|
||||
(** Method called to handle client requests.
|
||||
@param notify_back an object used to reply to the client, send progress
|
||||
messages, diagnostics, etc.
|
||||
@param id the query RPC ID, can be used for tracing, cancellation, etc. *)
|
||||
@param notify_back
|
||||
an object used to reply to the client, send progress messages,
|
||||
diagnostics, etc.
|
||||
@param id
|
||||
the query RPC ID, can be used for tracing, cancellation, etc. *)
|
||||
|
||||
method must_quit = false
|
||||
(** Set to true if the client requested to exit *)
|
||||
|
||||
method virtual spawn_query_handler : (unit -> unit IO.t) -> unit
|
||||
(** How to start a new future/task/thread concurrently. This is used
|
||||
to process incoming user queries.
|
||||
(** How to start a new future/task/thread concurrently. This is used to
|
||||
process incoming user queries.
|
||||
@since 0.5 *)
|
||||
end
|
||||
|
||||
|
|
@ -116,8 +119,8 @@ module Make (IO : IO) = struct
|
|||
method cancel_request (id : Jsonrpc.Id.t) : unit IO.t =
|
||||
notify_back @@ CancelRequest id
|
||||
|
||||
method work_done_progress_begin (p : Lsp.Types.WorkDoneProgressBegin.t)
|
||||
: unit IO.t =
|
||||
method work_done_progress_begin (p : Lsp.Types.WorkDoneProgressBegin.t) :
|
||||
unit IO.t =
|
||||
match workDoneToken with
|
||||
| Some token ->
|
||||
notify_back @@ WorkDoneProgress { token; value = Begin p }
|
||||
|
|
@ -130,23 +133,25 @@ module Make (IO : IO) = struct
|
|||
notify_back @@ WorkDoneProgress { value = Report p; token }
|
||||
| None -> IO.return ()
|
||||
|
||||
method work_done_progress_end (p : Lsp.Types.WorkDoneProgressEnd.t)
|
||||
: unit IO.t =
|
||||
method work_done_progress_end (p : Lsp.Types.WorkDoneProgressEnd.t) :
|
||||
unit IO.t =
|
||||
match workDoneToken with
|
||||
| Some token -> notify_back @@ WorkDoneProgress { value = End p; token }
|
||||
| None -> IO.return ()
|
||||
|
||||
method send_notification (n : Lsp.Server_notification.t) : unit IO.t =
|
||||
notify_back n
|
||||
(** Send a notification from the server to the client (general purpose method) *)
|
||||
(** Send a notification from the server to the client (general purpose
|
||||
method) *)
|
||||
|
||||
method send_request
|
||||
: 'from_server.
|
||||
method send_request :
|
||||
'from_server.
|
||||
'from_server Lsp.Server_request.t ->
|
||||
(('from_server, Jsonrpc.Response.Error.t) result -> unit IO.t) ->
|
||||
Req_id.t IO.t =
|
||||
fun r h -> server_request @@ Request_and_handler (r, h)
|
||||
(** Send a request from the server to the client (general purpose method) *)
|
||||
(** Send a request from the server to the client (general purpose method)
|
||||
*)
|
||||
end
|
||||
|
||||
type nonrec doc_state = doc_state = {
|
||||
|
|
@ -162,10 +167,10 @@ module Make (IO : IO) = struct
|
|||
let+ x = x in
|
||||
Ok x
|
||||
|
||||
(** An easily overloadable class. Pick the methods you want to support.
|
||||
The user must provide at least the callbacks for document lifecycle:
|
||||
open, close, update. The most basic LSP server should check documents
|
||||
when they're updated and report diagnostics back to the editor. *)
|
||||
(** An easily overloadable class. Pick the methods you want to support. The
|
||||
user must provide at least the callbacks for document lifecycle: open,
|
||||
close, update. The most basic LSP server should check documents when
|
||||
they're updated and report diagnostics back to the editor. *)
|
||||
class virtual server =
|
||||
object (self)
|
||||
inherit base_server
|
||||
|
|
@ -228,19 +233,18 @@ module Make (IO : IO) = struct
|
|||
method config_code_lens_options : CodeLensOptions.t option = None
|
||||
(** @since 0.3 *)
|
||||
|
||||
method config_definition
|
||||
: [ `Bool of bool | `DefinitionOptions of DefinitionOptions.t ] option
|
||||
=
|
||||
method config_definition :
|
||||
[ `Bool of bool | `DefinitionOptions of DefinitionOptions.t ] option =
|
||||
None
|
||||
(** @since 0.3 *)
|
||||
|
||||
method config_hover
|
||||
: [ `Bool of bool | `HoverOptions of HoverOptions.t ] option =
|
||||
method config_hover :
|
||||
[ `Bool of bool | `HoverOptions of HoverOptions.t ] option =
|
||||
None
|
||||
(** @since 0.3 *)
|
||||
|
||||
method config_inlay_hints
|
||||
: [ `Bool of bool
|
||||
method config_inlay_hints :
|
||||
[ `Bool of bool
|
||||
| `InlayHintOptions of InlayHintOptions.t
|
||||
| `InlayHintRegistrationOptions of InlayHintRegistrationOptions.t
|
||||
]
|
||||
|
|
@ -248,24 +252,22 @@ module Make (IO : IO) = struct
|
|||
None
|
||||
(** Configuration for the inlay hints API. *)
|
||||
|
||||
method config_symbol
|
||||
: [ `Bool of bool
|
||||
| `DocumentSymbolOptions of DocumentSymbolOptions.t
|
||||
]
|
||||
method config_symbol :
|
||||
[ `Bool of bool | `DocumentSymbolOptions of DocumentSymbolOptions.t ]
|
||||
option =
|
||||
None
|
||||
(** @since 0.3 *)
|
||||
|
||||
method config_code_action_provider
|
||||
: [ `CodeActionOptions of CodeActionOptions.t | `Bool of bool ] =
|
||||
method config_code_action_provider :
|
||||
[ `CodeActionOptions of CodeActionOptions.t | `Bool of bool ] =
|
||||
`Bool false
|
||||
(** @since 0.3 *)
|
||||
|
||||
method config_modify_capabilities (c : ServerCapabilities.t)
|
||||
: ServerCapabilities.t =
|
||||
method config_modify_capabilities (c : ServerCapabilities.t) :
|
||||
ServerCapabilities.t =
|
||||
c
|
||||
(** Modify capabilities before sending them back to the client.
|
||||
By default we just return them unmodified.
|
||||
(** Modify capabilities before sending them back to the client. By default
|
||||
we just return them unmodified.
|
||||
@since 0.3 *)
|
||||
|
||||
method config_list_commands : string list = []
|
||||
|
|
@ -304,8 +306,8 @@ module Make (IO : IO) = struct
|
|||
(** Called when the user hovers on some identifier in the document *)
|
||||
|
||||
method on_req_completion ~notify_back:(_ : notify_back) ~id:_ ~uri:_
|
||||
~pos:_ ~ctx:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state)
|
||||
: [ `CompletionList of CompletionList.t
|
||||
~pos:_ ~ctx:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) :
|
||||
[ `CompletionList of CompletionList.t
|
||||
| `List of CompletionItem.t list
|
||||
]
|
||||
option
|
||||
|
|
@ -314,14 +316,14 @@ module Make (IO : IO) = struct
|
|||
(** Called when the user requests completion in the document *)
|
||||
|
||||
method on_req_definition ~notify_back:(_ : notify_back) ~id:_ ~uri:_
|
||||
~pos:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state)
|
||||
: Locations.t option IO.t =
|
||||
~pos:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) :
|
||||
Locations.t option IO.t =
|
||||
IO.return None
|
||||
(** Called when the user wants to jump-to-definition *)
|
||||
|
||||
method on_req_code_lens ~notify_back:(_ : notify_back) ~id:_ ~uri:_
|
||||
~workDoneToken:_ ~partialResultToken:_ (_ : doc_state)
|
||||
: CodeLens.t list IO.t =
|
||||
~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) :
|
||||
CodeLens.t list IO.t =
|
||||
IO.return []
|
||||
(** List code lenses for the given document
|
||||
@since 0.3 *)
|
||||
|
|
@ -339,15 +341,15 @@ module Make (IO : IO) = struct
|
|||
@since 0.3 *)
|
||||
|
||||
method on_req_execute_command ~notify_back:(_ : notify_back) ~id:_
|
||||
~workDoneToken:_ (_c : string) (_args : Yojson.Safe.t list option)
|
||||
: Yojson.Safe.t IO.t =
|
||||
~workDoneToken:_ (_c : string) (_args : Yojson.Safe.t list option) :
|
||||
Yojson.Safe.t IO.t =
|
||||
IO.return `Null
|
||||
(** Execute a command with given arguments.
|
||||
@since 0.3 *)
|
||||
|
||||
method on_req_symbol ~notify_back:(_ : notify_back) ~id:_ ~uri:_
|
||||
~workDoneToken:_ ~partialResultToken:_ ()
|
||||
: [ `DocumentSymbol of DocumentSymbol.t list
|
||||
~workDoneToken:_ ~partialResultToken:_ () :
|
||||
[ `DocumentSymbol of DocumentSymbol.t list
|
||||
| `SymbolInformation of SymbolInformation.t list
|
||||
]
|
||||
option
|
||||
|
|
@ -361,8 +363,8 @@ module Make (IO : IO) = struct
|
|||
IO.failwith "unhandled request"
|
||||
|
||||
method on_req_inlay_hint ~notify_back:(_ : notify_back) ~id:_ ~uri:_
|
||||
~range:(_ : Lsp.Types.Range.t) ()
|
||||
: Lsp.Types.InlayHint.t list option IO.t =
|
||||
~range:(_ : Lsp.Types.Range.t) () :
|
||||
Lsp.Types.InlayHint.t list option IO.t =
|
||||
IO.return None
|
||||
(** Provide inlay hints for this document.
|
||||
@since 0.5 *)
|
||||
|
|
@ -629,8 +631,8 @@ module Make (IO : IO) = struct
|
|||
|
||||
method filter_text_document (_doc_uri : Lsp.Types.DocumentUri.t) : bool =
|
||||
true
|
||||
(** Filter the document URI to check if we want to process it or not.
|
||||
By default we accept all documents. *)
|
||||
(** Filter the document URI to check if we want to process it or not. By
|
||||
default we accept all documents. *)
|
||||
|
||||
method on_notification ~notify_back ~server_request
|
||||
(n : Lsp.Client_notification.t) : unit IO.t =
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue