Skip to content

Commit

Permalink
Allowing remote LSP for superbol
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevendeo committed Oct 30, 2023
1 parent 0790171 commit c21f493
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/vscode/superbol-vscode-platform/superbol_instance.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,31 @@ let start_language_server t =
let open Promise.Syntax in
let* () = stop_language_server t in
let serverOptions = Superbol_languageclient.serverOptions () in
let clientOptions = Superbol_languageclient.clientOptions () in
let client = LanguageClient.make
~id:"cobolServer"
~name:"Cobol Server"
~serverOptions ~clientOptions () in
let client =
let cmd = Executable.command serverOptions in
if String.starts_with ~prefix:"ws://" cmd then
LanguageClient.make_
~id:"cobolServer"
~name:"Cobol Server"
(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
()
)
)
else
let clientOptions = Superbol_languageclient.clientOptions () in
LanguageClient.make
~id:"cobolServer"
~name:"Cobol Server"
~serverOptions:serverOptions
~clientOptions:clientOptions
()
in
let+ () = LanguageClient.start client in
t.language_client <- Some client
39 changes: 39 additions & 0 deletions src/vscode/vscode-languageclient-js-stubs/vscode_languageclient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@ module StaticFeature = struct
[@@js.builder]]
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 joo_global_object.webSocket (`%s`);"
str

let njs_stream_of_js = Obj.magic

let njs_stream_to_js = Obj.magic

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

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

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

val create :
writer:njs_stream
-> reader:njs_stream
-> ?detached:bool
-> unit
-> t
[@@js.builder]]
end

module LanguageClient = struct
include Class.Make ()

Expand All @@ -204,6 +236,13 @@ module LanguageClient = struct
-> t
[@@js.new "vscode_languageclient.LanguageClient"]

val make_ :
id:string
-> name:string
-> (unit -> StreamInfo.t Promise.t)
-> t
[@@js.new "vscode_languageclient.LanguageClient"]

val start : t -> unit Promise.t [@@js.call]

val isRunning : t -> bool [@@js.call]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ module StaticFeature : sig
-> t
end

module StreamInfo : sig
include Js.T

type njs_stream

val njs_stream_of_string : string -> njs_stream

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

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

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

val create :
writer:njs_stream
-> reader:njs_stream
-> ?detached:bool
-> unit
-> t
[@@js.builder]
end

module LanguageClient : sig
include Js.T

Expand All @@ -172,6 +194,12 @@ module LanguageClient : sig
-> unit
-> t

val make_ :
id:string
-> name:string
-> (unit -> StreamInfo.t Promise.t)
-> t

val start : t -> unit Promise.t

val isRunning : t -> bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
joo_global_object.vscode_languageclient = require("vscode-languageclient");
joo_global_object.webSocket = require("ws");

0 comments on commit c21f493

Please sign in to comment.