Skip to content

Commit

Permalink
Draft: connecting to the LSP server via a TCP socket
Browse files Browse the repository at this point in the history
  • Loading branch information
nberth authored and Stevendeo committed Aug 26, 2024
1 parent 9b711ee commit 72fb347
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ module StreamInfo = struct
let njs_stream_of_string str : njs_stream =
Format.ksprintf
Js_of_ocaml.Js.Unsafe.eval_string
"new joo_global_object.webSocket (`%s`);"
"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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ module DidChangeConfiguration : sig
val create : settings:Ojs.t -> unit -> t
end

module StreamInfo : sig
module StreamInfo: sig
include Js.T

type njs_stream

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
joo_global_object.vscode_languageclient = require("vscode-languageclient");
joo_global_object.webSocket = require("ws");
// joo_global_object.webSocket = require("ws");
25 changes: 13 additions & 12 deletions src/vscode/superbol-vscode-platform/superbol_instance.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ let start_language_server ({ context; _ } as t) =
in
let client =
let cmd = Executable.command serverOptions in
if String.starts_with ~prefix:"ws://" cmd then
LanguageClient.make_stream ~id ~name
(fun () ->
let njs_stream =
Vscode_languageclient.StreamInfo.njs_stream_of_string cmd
in
Promise.return (
Vscode_languageclient.StreamInfo.create ()
~writer:njs_stream
~reader:njs_stream
)
)
if String.starts_with ~prefix:"tcp://" cmd then
LanguageClient.make_stream ~id ~name begin fun () ->
let njs_stream =
Vscode_languageclient.StreamInfo.njs_stream_of_socket @@
Node.Net.Socket.(connect (make ()))
~host:"localhost"
~port:8000
in
Promise.return @@
Vscode_languageclient.StreamInfo.create ()
~writer:njs_stream
~reader:njs_stream
end
else
let clientOptions = Superbol_languageclient.client_options () in
LanguageClient.make () ~id ~name ~serverOptions ~clientOptions
Expand Down

0 comments on commit 72fb347

Please sign in to comment.