package dune-rpc

  1. Overview
  2. Docs
Communicate with dune using rpc

Install

dune-project
 Dependency

Authors

Maintainers

Sources

dune-3.22.2.tbz
sha256=c2ccf8bc6b17afa47c450297357496303aa7c8680e329b79d98c68e35013a118
sha512=26d3df56a509c6e8937a9333944303bdd8800a41e1b869c3adfb76d1e1fe615b6ec41491d596bd5982e338dcf70b97c18f963f37bfbf2bd581cbd356f3d5f4e5

doc/src/dune-rpc.private/menu.ml.html

Source file menu.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
open Import
open Types

(* This list of methods and generations is exactly the list of existing methods
   as of commit [3cd240e], which the initial versioning implementation was based
   on. *)
let compatibility_menu =
  [ "ping", 1
  ; "diagnostics", 1
  ; "shutdown", 1
  ; "subscribe", 1
  ; "unsubscribe", 1
  ; "build", 1
  ; "status", 1
  ; "notify/abort", 1
  ; "notify/diagnostic", 1
  ; "notify/log", 1
  ; "notify/progress", 1
  ]
  |> List.map ~f:(fun (name, version) -> Method.Name.of_string name, version)
  |> Method.Name.Map.of_list_exn
;;

type t = Method.Version.t Method.Name.Map.t

let default = compatibility_menu
let find = Method.Name.Map.find

let select_common ~local_versions ~remote_versions =
  let selected_versions =
    List.filter_map remote_versions ~f:(fun (method_, remote_versions) ->
      let remote_versions = Method.Version.Set.of_list remote_versions in
      let open Option.O in
      let* local_versions = Method.Name.Map.find local_versions method_ in
      let+ greatest_common_version =
        Method.Version.Set.max_elt
          (Method.Version.Set.inter remote_versions local_versions)
      in
      method_, greatest_common_version)
  in
  match selected_versions with
  | [] -> None
  | _ :: _ -> Some (Method.Name.Map.of_list_exn selected_versions)
;;

let of_list = Method.Name.Map.of_list
let to_list = Method.Name.Map.to_list
let to_dyn = Method.Name.Map.to_dyn Int.to_dyn