Skip to content

Commit ab6f224

Browse files
committed
write functions to install dune with the dune install script
1 parent 7bf9164 commit ab6f224

File tree

1 file changed

+67
-10
lines changed

1 file changed

+67
-10
lines changed

src/extension_commands.ml

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,74 @@ let _switch_impl_intf =
249249

250250
let walkthrough_terminal_instance = ref None
251251

252-
let walkthrough_terminal instance =
252+
let walkthrough_terminal title instance =
253253
match !walkthrough_terminal_instance with
254254
| Some t -> t
255255
| None ->
256-
let t =
257-
Terminal_sandbox.create
258-
~name:"OCaml Platform Walkthrough"
259-
(Extension_instance.sandbox instance)
260-
in
256+
let t = Terminal_sandbox.create ~name:title (Extension_instance.sandbox instance) in
261257
walkthrough_terminal_instance := Some t;
262258
t
263259
;;
264260

261+
let _install_dune =
262+
let callback (instance : Extension_instance.t) () =
263+
let process_installation () =
264+
let open Promise.Syntax in
265+
let* dune = Dune.make (Sandbox.workspace_root ()) () in
266+
match dune with
267+
| None ->
268+
let options =
269+
ProgressOptions.create
270+
~location:(`ProgressLocation Notification)
271+
~title:"Installing Dune Package Management"
272+
~cancellable:false
273+
()
274+
in
275+
let task ~progress:_ ~token:_ =
276+
let+ result =
277+
match Platform.t with
278+
| Win32 ->
279+
let _ =
280+
show_message
281+
`Info
282+
"Dune Package Management is not supported on Windows yet!"
283+
in
284+
Ok () |> Promise.return
285+
| Darwin | Linux | Other ->
286+
let open Promise.Result.Syntax in
287+
let+ _ =
288+
let _ =
289+
let terminal =
290+
walkthrough_terminal "Dune Package Management Installer" instance
291+
in
292+
let _ = Terminal_sandbox.show ~preserveFocus:true terminal in
293+
Terminal_sandbox.send
294+
terminal
295+
"bash -c \"sh <(curl -fsSL \
296+
https://github.com/ocaml-dune/dune-bin-install/releases/download/v2/install.sh)\""
297+
in
298+
Ok () |> Promise.return
299+
in
300+
()
301+
in
302+
match result with
303+
| Ok () -> Ojs.null
304+
| Error err ->
305+
show_message `Error "An error occured while installing dune %s" err;
306+
Ojs.null
307+
in
308+
let+ _ = Vscode.Window.withProgress (module Ojs) ~options ~task in
309+
()
310+
| Some _ ->
311+
show_message `Info "Dune Package Management is already installed!"
312+
|> Promise.return
313+
in
314+
let (_ : unit Promise.t) = process_installation () in
315+
()
316+
in
317+
command Command_api.Internal.install_dune callback
318+
;;
319+
265320
let _install_opam =
266321
let callback (instance : Extension_instance.t) () =
267322
let process_installation () =
@@ -292,7 +347,9 @@ let _install_opam =
292347
let open Promise.Result.Syntax in
293348
let+ _ =
294349
let _ =
295-
let terminal = walkthrough_terminal instance in
350+
let terminal =
351+
walkthrough_terminal "OCaml Platform Walkthrough" instance
352+
in
296353
let _ = Terminal_sandbox.show ~preserveFocus:true terminal in
297354
Terminal_sandbox.send
298355
terminal
@@ -333,7 +390,7 @@ let _init_opam =
333390
let open Promise.Result.Syntax in
334391
let+ _ =
335392
let _ =
336-
let terminal = walkthrough_terminal instance in
393+
let terminal = walkthrough_terminal "OCaml Platform Walkthrough" instance in
337394
let _ = Terminal_sandbox.show ~preserveFocus:true terminal in
338395
Terminal_sandbox.send terminal "opam init"
339396
in
@@ -368,7 +425,7 @@ let _install_ocaml_dev =
368425
let open Promise.Result.Syntax in
369426
let+ _ =
370427
let _ =
371-
let terminal = walkthrough_terminal instance in
428+
let terminal = walkthrough_terminal "OCaml Platform Walkthrough" instance in
372429
let _ = Terminal_sandbox.show ~preserveFocus:true terminal in
373430
Terminal_sandbox.send
374431
terminal
@@ -405,7 +462,7 @@ let _open_utop =
405462
let open Promise.Result.Syntax in
406463
let+ _ =
407464
let _ =
408-
let terminal = walkthrough_terminal instance in
465+
let terminal = walkthrough_terminal "OCaml Platform Walkthrough" instance in
409466
let _ = Terminal_sandbox.show ~preserveFocus:true terminal in
410467
Terminal_sandbox.send terminal "opam exec -- utop"
411468
in

0 commit comments

Comments
 (0)