Update dunefmt

This commit is contained in:
nojaf 2025-04-05 12:32:56 +02:00
parent a63ac9b5cb
commit 902baf11d2
5 changed files with 89 additions and 86 deletions

View file

@ -1,4 +1,4 @@
version = 0.26.2 version = 0.27.0
profile=conventional profile=conventional
margin=80 margin=80
if-then-else=k-r if-then-else=k-r

View file

@ -124,7 +124,8 @@ module Make (IO : IO) : S with module IO = IO = struct
`Int id `Int id
(** Registers a new handler for a request response. The return indicates (** 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) let register_server_request_response_handler (self : t) (id : Req_id.t)
(handler : server_request_handler_pair) : bool = (handler : server_request_handler_pair) : bool =
if Hashtbl.mem self.pending_responses id then 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 = Req_id.t IO.t =
server_request self (Request_and_handler (req, cb)) server_request self (Request_and_handler (req, cb))
(** [shutdown ()] is called after processing each request to check if the server (** [shutdown ()] is called after processing each request to check if the
could wait for new messages. server could wait for new messages. When launching an LSP server using
When launching an LSP server using [Server.Make.server], the [Server.Make.server], the natural choice for it is
natural choice for it is [s#get_status = `ReceivedExit] *) [s#get_status = `ReceivedExit] *)
let run ?(shutdown = fun _ -> false) (self : t) : unit IO.t = let run ?(shutdown = fun _ -> false) (self : t) : unit IO.t =
let async f = let async f =
self.s#spawn_query_handler f; self.s#spawn_query_handler f;

View file

@ -1,6 +1,6 @@
(** Simple JSON-RPC2 implementation. (** Simple JSON-RPC2 implementation.
See {{: https://www.jsonrpc.org/specification} the spec} *) See {{:https://www.jsonrpc.org/specification} the spec} *)
type json = Yojson.Safe.t type json = Yojson.Safe.t
@ -40,13 +40,13 @@ module type S = sig
'from_server Lsp.Server_request.t -> 'from_server Lsp.Server_request.t ->
(('from_server, Jsonrpc.Response.Error.t) result -> unit IO.t) -> (('from_server, Jsonrpc.Response.Error.t) result -> unit IO.t) ->
Req_id.t IO.t Req_id.t IO.t
(** Send a request from the server, and pass a callback that will be (** Send a request from the server, and pass a callback that will be called
called with the result in the future. with the result in the future.
@since 0.5 *) @since 0.5 *)
val run : ?shutdown:(unit -> bool) -> t -> unit IO.t val run : ?shutdown:(unit -> bool) -> t -> unit IO.t
(** Listen for incoming messages and responses. (** Listen for incoming messages and responses.
@param shutdown if true, tells the server to shut down *) @param shutdown if true, tells the server to shut down *)
end end
module Make (IO : IO) : S with module IO = IO module Make (IO : IO) : S with module IO = IO

View file

@ -1,7 +1,7 @@
(** Linol. (** Linol.
Abstraction over The "Lsp" library, to make it easier to develop Abstraction over The "Lsp" library, to make it easier to develop LSP servers
LSP servers in OCaml (but not necessarily {b for} OCaml). *) in OCaml (but not necessarily {b for} OCaml). *)
module type IO = Sigs.IO module type IO = Sigs.IO

View file

@ -13,7 +13,8 @@ type nonrec doc_state = {
(** Request ID. (** 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 module Req_id = struct
type t = Jsonrpc.Id.t type t = Jsonrpc.Id.t
@ -62,16 +63,18 @@ module Make (IO : IO) = struct
'a Lsp.Client_request.t -> 'a Lsp.Client_request.t ->
('a, string) result IO.t ('a, string) result IO.t
(** Method called to handle client requests. (** Method called to handle client requests.
@param notify_back an object used to reply to the client, send progress @param notify_back
messages, diagnostics, etc. an object used to reply to the client, send progress messages,
@param id the query RPC ID, can be used for tracing, cancellation, etc. *) diagnostics, etc.
@param id
the query RPC ID, can be used for tracing, cancellation, etc. *)
method must_quit = false method must_quit = false
(** Set to true if the client requested to exit *) (** Set to true if the client requested to exit *)
method virtual spawn_query_handler : (unit -> unit IO.t) -> unit method virtual spawn_query_handler : (unit -> unit IO.t) -> unit
(** How to start a new future/task/thread concurrently. This is used (** How to start a new future/task/thread concurrently. This is used to
to process incoming user queries. process incoming user queries.
@since 0.5 *) @since 0.5 *)
end end
@ -116,8 +119,8 @@ module Make (IO : IO) = struct
method cancel_request (id : Jsonrpc.Id.t) : unit IO.t = method cancel_request (id : Jsonrpc.Id.t) : unit IO.t =
notify_back @@ CancelRequest id notify_back @@ CancelRequest id
method work_done_progress_begin (p : Lsp.Types.WorkDoneProgressBegin.t) method work_done_progress_begin (p : Lsp.Types.WorkDoneProgressBegin.t) :
: unit IO.t = unit IO.t =
match workDoneToken with match workDoneToken with
| Some token -> | Some token ->
notify_back @@ WorkDoneProgress { token; value = Begin p } notify_back @@ WorkDoneProgress { token; value = Begin p }
@ -130,23 +133,25 @@ module Make (IO : IO) = struct
notify_back @@ WorkDoneProgress { value = Report p; token } notify_back @@ WorkDoneProgress { value = Report p; token }
| None -> IO.return () | None -> IO.return ()
method work_done_progress_end (p : Lsp.Types.WorkDoneProgressEnd.t) method work_done_progress_end (p : Lsp.Types.WorkDoneProgressEnd.t) :
: unit IO.t = unit IO.t =
match workDoneToken with match workDoneToken with
| Some token -> notify_back @@ WorkDoneProgress { value = End p; token } | Some token -> notify_back @@ WorkDoneProgress { value = End p; token }
| None -> IO.return () | None -> IO.return ()
method send_notification (n : Lsp.Server_notification.t) : unit IO.t = method send_notification (n : Lsp.Server_notification.t) : unit IO.t =
notify_back n 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 method send_request :
: 'from_server. 'from_server.
'from_server Lsp.Server_request.t -> 'from_server Lsp.Server_request.t ->
(('from_server, Jsonrpc.Response.Error.t) result -> unit IO.t) -> (('from_server, Jsonrpc.Response.Error.t) result -> unit IO.t) ->
Req_id.t IO.t = Req_id.t IO.t =
fun r h -> server_request @@ Request_and_handler (r, h) 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 end
type nonrec doc_state = doc_state = { type nonrec doc_state = doc_state = {
@ -162,10 +167,10 @@ module Make (IO : IO) = struct
let+ x = x in let+ x = x in
Ok x Ok x
(** An easily overloadable class. Pick the methods you want to support. (** An easily overloadable class. Pick the methods you want to support. The
The user must provide at least the callbacks for document lifecycle: user must provide at least the callbacks for document lifecycle: open,
open, close, update. The most basic LSP server should check documents close, update. The most basic LSP server should check documents when
when they're updated and report diagnostics back to the editor. *) they're updated and report diagnostics back to the editor. *)
class virtual server = class virtual server =
object (self) object (self)
inherit base_server inherit base_server
@ -178,7 +183,7 @@ module Make (IO : IO) = struct
method get_status = status method get_status = status
(** Check if exit or shutdown request was made by the client. (** Check if exit or shutdown request was made by the client.
@since 0.5 *) @since 0.5 *)
method find_doc (uri : DocumentUri.t) : doc_state option = method find_doc (uri : DocumentUri.t) : doc_state option =
try Some (Hashtbl.find docs uri) with Not_found -> None try Some (Hashtbl.find docs uri) with Not_found -> None
@ -223,50 +228,47 @@ module Make (IO : IO) = struct
method config_completion : CompletionOptions.t option = None method config_completion : CompletionOptions.t option = None
(** Configuration for the completion API. (** Configuration for the completion API.
@since 0.4 *) @since 0.4 *)
method config_code_lens_options : CodeLensOptions.t option = None method config_code_lens_options : CodeLensOptions.t option = None
(** @since 0.3 *) (** @since 0.3 *)
method config_definition method config_definition :
: [ `Bool of bool | `DefinitionOptions of DefinitionOptions.t ] option [ `Bool of bool | `DefinitionOptions of DefinitionOptions.t ] option =
=
None None
(** @since 0.3 *) (** @since 0.3 *)
method config_hover method config_hover :
: [ `Bool of bool | `HoverOptions of HoverOptions.t ] option = [ `Bool of bool | `HoverOptions of HoverOptions.t ] option =
None None
(** @since 0.3 *) (** @since 0.3 *)
method config_inlay_hints method config_inlay_hints :
: [ `Bool of bool [ `Bool of bool
| `InlayHintOptions of InlayHintOptions.t | `InlayHintOptions of InlayHintOptions.t
| `InlayHintRegistrationOptions of InlayHintRegistrationOptions.t | `InlayHintRegistrationOptions of InlayHintRegistrationOptions.t
] ]
option = option =
None None
(** Configuration for the inlay hints API. *) (** Configuration for the inlay hints API. *)
method config_symbol method config_symbol :
: [ `Bool of bool [ `Bool of bool | `DocumentSymbolOptions of DocumentSymbolOptions.t ]
| `DocumentSymbolOptions of DocumentSymbolOptions.t option =
]
option =
None None
(** @since 0.3 *) (** @since 0.3 *)
method config_code_action_provider method config_code_action_provider :
: [ `CodeActionOptions of CodeActionOptions.t | `Bool of bool ] = [ `CodeActionOptions of CodeActionOptions.t | `Bool of bool ] =
`Bool false `Bool false
(** @since 0.3 *) (** @since 0.3 *)
method config_modify_capabilities (c : ServerCapabilities.t) method config_modify_capabilities (c : ServerCapabilities.t) :
: ServerCapabilities.t = ServerCapabilities.t =
c c
(** Modify capabilities before sending them back to the client. (** Modify capabilities before sending them back to the client. By default
By default we just return them unmodified. we just return them unmodified.
@since 0.3 *) @since 0.3 *)
method config_list_commands : string list = [] method config_list_commands : string list = []
(** List of commands available *) (** List of commands available *)
@ -304,73 +306,73 @@ module Make (IO : IO) = struct
(** Called when the user hovers on some identifier in the document *) (** Called when the user hovers on some identifier in the document *)
method on_req_completion ~notify_back:(_ : notify_back) ~id:_ ~uri:_ method on_req_completion ~notify_back:(_ : notify_back) ~id:_ ~uri:_
~pos:_ ~ctx:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) ~pos:_ ~ctx:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) :
: [ `CompletionList of CompletionList.t [ `CompletionList of CompletionList.t
| `List of CompletionItem.t list | `List of CompletionItem.t list
] ]
option option
IO.t = IO.t =
IO.return None IO.return None
(** Called when the user requests completion in the document *) (** Called when the user requests completion in the document *)
method on_req_definition ~notify_back:(_ : notify_back) ~id:_ ~uri:_ method on_req_definition ~notify_back:(_ : notify_back) ~id:_ ~uri:_
~pos:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) ~pos:_ ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) :
: Locations.t option IO.t = Locations.t option IO.t =
IO.return None IO.return None
(** Called when the user wants to jump-to-definition *) (** Called when the user wants to jump-to-definition *)
method on_req_code_lens ~notify_back:(_ : notify_back) ~id:_ ~uri:_ method on_req_code_lens ~notify_back:(_ : notify_back) ~id:_ ~uri:_
~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) ~workDoneToken:_ ~partialResultToken:_ (_ : doc_state) :
: CodeLens.t list IO.t = CodeLens.t list IO.t =
IO.return [] IO.return []
(** List code lenses for the given document (** List code lenses for the given document
@since 0.3 *) @since 0.3 *)
method on_req_code_lens_resolve ~notify_back:(_ : notify_back) ~id:_ method on_req_code_lens_resolve ~notify_back:(_ : notify_back) ~id:_
(cl : CodeLens.t) : CodeLens.t IO.t = (cl : CodeLens.t) : CodeLens.t IO.t =
IO.return cl IO.return cl
(** Code lens resolution, must return a code lens with non null "command" (** Code lens resolution, must return a code lens with non null "command"
@since 0.3 *) @since 0.3 *)
method on_req_code_action ~notify_back:(_ : notify_back) ~id:_ method on_req_code_action ~notify_back:(_ : notify_back) ~id:_
(_c : CodeActionParams.t) : CodeActionResult.t IO.t = (_c : CodeActionParams.t) : CodeActionResult.t IO.t =
IO.return None IO.return None
(** Code action. (** Code action.
@since 0.3 *) @since 0.3 *)
method on_req_execute_command ~notify_back:(_ : notify_back) ~id:_ method on_req_execute_command ~notify_back:(_ : notify_back) ~id:_
~workDoneToken:_ (_c : string) (_args : Yojson.Safe.t list option) ~workDoneToken:_ (_c : string) (_args : Yojson.Safe.t list option) :
: Yojson.Safe.t IO.t = Yojson.Safe.t IO.t =
IO.return `Null IO.return `Null
(** Execute a command with given arguments. (** Execute a command with given arguments.
@since 0.3 *) @since 0.3 *)
method on_req_symbol ~notify_back:(_ : notify_back) ~id:_ ~uri:_ method on_req_symbol ~notify_back:(_ : notify_back) ~id:_ ~uri:_
~workDoneToken:_ ~partialResultToken:_ () ~workDoneToken:_ ~partialResultToken:_ () :
: [ `DocumentSymbol of DocumentSymbol.t list [ `DocumentSymbol of DocumentSymbol.t list
| `SymbolInformation of SymbolInformation.t list | `SymbolInformation of SymbolInformation.t list
] ]
option option
IO.t = IO.t =
IO.return None IO.return None
(** List symbols in this document. (** List symbols in this document.
@since 0.3 *) @since 0.3 *)
method on_unknown_request ~notify_back:(_ : notify_back) ~server_request:_ method on_unknown_request ~notify_back:(_ : notify_back) ~server_request:_
~id:_ _meth _params : Yojson.Safe.t IO.t = ~id:_ _meth _params : Yojson.Safe.t IO.t =
IO.failwith "unhandled request" IO.failwith "unhandled request"
method on_req_inlay_hint ~notify_back:(_ : notify_back) ~id:_ ~uri:_ method on_req_inlay_hint ~notify_back:(_ : notify_back) ~id:_ ~uri:_
~range:(_ : Lsp.Types.Range.t) () ~range:(_ : Lsp.Types.Range.t) () :
: Lsp.Types.InlayHint.t list option IO.t = Lsp.Types.InlayHint.t list option IO.t =
IO.return None IO.return None
(** Provide inlay hints for this document. (** Provide inlay hints for this document.
@since 0.5 *) @since 0.5 *)
method on_req_shutdown ~notify_back:(_ : notify_back) ~id:_ : unit IO.t = method on_req_shutdown ~notify_back:(_ : notify_back) ~id:_ : unit IO.t =
IO.return () IO.return ()
(** Process a shutdown request. (** Process a shutdown request.
@since 0.7 *) @since 0.7 *)
method on_request : type r. method on_request : type r.
notify_back:_ -> notify_back:_ ->