Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support --clientProcessId argument #1074

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

- Fix the type of DocumentSelector in cram document registration (#1068)

- Accept the `--clientProcessId` command line argument. (#1074)

## Features
- Add "Remove type annotation" code action. (#1039)

Expand Down
18 changes: 16 additions & 2 deletions lsp/src/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,39 @@ module Arg = struct
; mutable port : int option
; mutable stdio : bool
; mutable spec : (string * Arg.spec * string) list
; mutable clientProcessId : int option
}

let create () =
let t = { pipe = None; port = None; stdio = false; spec = [] } in
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")
; ("--socket", Arg.Int (fun p -> t.port <- Some p), "set port")
; ("--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" )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should add an explicit remark about client pid being ignored. Currently, it's only mentioned in PR description. Maybe we should add it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this code is part of our general purpose lsp library. So we can't make assumptions whether it's being used or not.

]
in
t.spec <- spec;
t

let spec t = t.spec

let read { pipe; port; stdio; spec = _ } : (Channel.t, string) result =
let clientProcessId t = t.clientProcessId

let read { 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)
Expand Down
2 changes: 2 additions & 0 deletions lsp/src/cli.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ module Arg : sig
val spec : t -> (string * Arg.spec * string) list

val read : t -> (Channel.t, string) result

val clientProcessId : t -> int option
end
3 changes: 2 additions & 1 deletion ocaml-lsp-server/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ let () =
@ Cli.Arg.spec arg
in
let usage =
"ocamllsp [ --stdio | --socket SOCKET --port PORT | --pipe PIPE ]"
"ocamllsp [ --stdio | --socket SOCKET --port PORT | --pipe PIPE ] [ \
--clientProcessId pid ]"
in
Arg.parse
spec
Expand Down