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

Allowing remote LSP connection in vscode API #102

Merged
merged 15 commits into from
Sep 6, 2024
2 changes: 2 additions & 0 deletions src/vendor/vscode-ocaml-platform/src-bindings/node/node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ module Net = struct
module Socket = struct
include Class.Make ()

let to_ojs (t : t) : Ojs.t = (t :> Ojs.t)

Stevendeo marked this conversation as resolved.
Show resolved Hide resolved
include
[%js:
val make : unit -> t [@@js.new "net.Socket"]
Expand Down
2 changes: 2 additions & 0 deletions src/vendor/vscode-ocaml-platform/src-bindings/node/node.mli
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ module Net : sig
module Socket : sig
type t

val to_ojs : t -> Ojs.t

val make : unit -> t

val isPaused : t -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,31 +193,17 @@ end
module StreamInfo = struct
include Interface.Make ()

type njs_stream

let njs_stream_of_string str : njs_stream =
Format.ksprintf
Js_of_ocaml.Js.Unsafe.eval_string
"new webSocket (`%s`);"
str

let njs_stream_of_js = Obj.magic

let njs_stream_to_js = Obj.magic

let njs_stream_of_socket: _ -> njs_stream = njs_stream_of_js

include
[%js:
val writer : t -> njs_stream [@@js.get]
val writer : t -> Ojs.t [@@js.get]

val reader : t -> njs_stream [@@js.get]
val reader : t -> Ojs.t [@@js.get]

val detached : t -> bool option [@@js.get]

val create :
writer:njs_stream
-> reader:njs_stream
writer:Ojs.t
-> reader:Ojs.t
-> ?detached:bool
-> unit
-> t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,15 @@ end
module StreamInfo: sig
include Js.T

type njs_stream
val writer : t -> Ojs.t [@@js.get]

val njs_stream_of_string : string -> njs_stream
val njs_stream_of_socket : 'a -> njs_stream

val writer : t -> njs_stream [@@js.get]

val reader : t -> njs_stream [@@js.get]
val reader : t -> Ojs.t [@@js.get]

val detached : t -> bool option [@@js.get]

val create :
writer:njs_stream
-> reader:njs_stream
writer:Ojs.t
-> reader:Ojs.t
-> ?detached:bool
-> unit
-> t
Expand Down
12 changes: 5 additions & 7 deletions src/vscode/superbol-vscode-platform/superbol_instance.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ let start_language_server ({ context; _ } as t) =
| Some url ->
let host, port = host_and_port url in
LanguageClient.make_stream ~id ~name begin fun () ->
let njs_stream =
Vscode_languageclient.StreamInfo.njs_stream_of_socket @@
Node.Net.Socket.(connect (make ()))
~host
~port
let socket =
(* Vscode_languageclient.StreamInfo.njs_stream_of_socket @@ *)
Node.Net.Socket.(to_ojs (connect (make ()) ~host ~port))
in
Promise.return @@
Vscode_languageclient.StreamInfo.create ()
~writer:njs_stream
~reader:njs_stream
~writer:socket
~reader:socket
end
| None ->
let clientOptions = Superbol_languageclient.client_options () in
Expand Down
Loading