package linol

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file cli.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module Channel = struct
  type t =
    | Stdio
    | Pipe of string
    | Socket of int
end

module Arg = struct
  type t =
    { mutable pipe : string option
    ; mutable port : int option
    ; mutable stdio : bool
    ; mutable spec : (string * Arg.spec * string) list
    ; mutable clientProcessId : int option
    }

  let port t ~name ~description =
    ( name
    , Arg.Int
        (fun p ->
          match t.port with
          | Some _ -> raise @@ Arg.Bad "port is already set once"
          | None -> t.port <- Some p)
    , description )
  ;;

  let create () =
    let t =
      { pipe = None; port = None; stdio = false; spec = []; clientProcessId = None }
    in
    let spec =
      [ "--pipe", Arg.String (fun p -> t.pipe <- Some p), "set pipe path"
      ; port t ~name:"--socket" ~description:"set the port"
      ; port t ~name:"--port" ~description:"synonym for --socket"
      ; "--stdio", Arg.Unit (fun () -> t.stdio <- true), "set stdio"
      ; ( "--node-ipc"
        , Arg.Unit (fun () -> raise @@ Arg.Bad "node-ipc isn't supported")
        , "not supported" )
      ; ( "--clientProcessId"
        , Arg.Int (fun pid -> t.clientProcessId <- Some pid)
        , "set the pid of the lsp client" )
      ]
    in
    t.spec <- spec;
    t
  ;;

  let spec t = t.spec
  let clientProcessId t = t.clientProcessId

  let channel { pipe; port; stdio; spec = _; clientProcessId = _ }
    : (Channel.t, string) result
    =
    match pipe, port, stdio with
    | None, None, _ -> Ok Stdio
    | Some p, None, false -> Ok (Pipe p)
    | None, Some s, false -> Ok (Socket s)
    | _, _, _ -> Error "invalid arguments"
  ;;
end

let args ?channel ?clientProcessId () =
  let args =
    match clientProcessId with
    | None -> []
    | Some pid -> [ "--clientProcessId"; string_of_int pid ]
  in
  match (channel : Channel.t option) with
  | None -> args
  | Some Stdio -> "--stdio" :: args
  | Some (Pipe pipe) -> "--pipe" :: pipe :: args
  | Some (Socket port) -> "--socket" :: string_of_int port :: args
;;
OCaml

Innovation. Community. Security.