Skip to content

Commit

Permalink
Version with proper types
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevendeo committed Aug 26, 2024
1 parent b4c5ba4 commit d8248be
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 34 deletions.
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)

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

0 comments on commit d8248be

Please sign in to comment.