File tree Expand file tree Collapse file tree 5 files changed +42
-22
lines changed Expand file tree Collapse file tree 5 files changed +42
-22
lines changed Original file line number Diff line number Diff line change @@ -70,16 +70,6 @@ let is_project_locked t =
7070 Fs. exists (Path. to_string dune_lock_path)
7171;;
7272
73- let is_ocamllsp_present t =
74- (* Path to the ocaml-lsp-server.pkg file *)
75- let ocamllsp =
76- Path. join
77- t.root
78- (Path. join (Path. of_string " dev-tools.locks" ) (Path. of_string " ocaml-lsp-server" ))
79- in
80- Fs. exists (Path. to_string ocamllsp)
81- ;;
82-
8373let command t ~args = Cmd. Spawn (Cmd. append t.bin args)
8474
8575let exec ~target ?(args = [] ) t =
@@ -88,8 +78,21 @@ let exec ~target ?(args = []) t =
8878
8979let exec_pkg ~cmd ?(args = [] ) t = Cmd. Spawn (Cmd. append t.bin ([ " pkg" ; cmd ] @ args))
9080
91- let exec_tool ~tool ?(args = [] ) t =
92- Cmd. Spawn (Cmd. append t.bin ([ " tools" ; " exec" ; tool; " --" ] @ args))
81+ let tools ~tool ?(args = [] ) t cmd =
82+ match cmd with
83+ | `Exec_ -> Cmd. Spawn (Cmd. append t.bin ([ " tools" ; " exec" ; tool; " --" ] @ args))
84+ | `Which -> Cmd. Spawn (Cmd. append t.bin ([ " tools" ; " which" ; tool ] @ args))
85+ | `Install -> Cmd. Spawn (Cmd. append t.bin ([ " tools" ; " install" ; tool ] @ args))
86+ ;;
87+
88+ let is_ocamllsp_present t =
89+ let open Promise.Syntax in
90+ let + ocamllsp_path = tools ~tool: " ocamllsp" t `Which |> Cmd. output ~cwd: t.root in
91+ match ocamllsp_path with
92+ | Ok _path -> true
93+ | Error err ->
94+ log_chan `Info ~section: " dune" " Ocamllsp not found with error %s" err;
95+ false
9396;;
9497
9598let equal d1 d2 = Path. equal d1.root d2.root
Original file line number Diff line number Diff line change @@ -10,9 +10,6 @@ type t =
1010 If not, user should be advised to run `dune pkg lock` *)
1111val is_project_locked : t -> bool Promise .t
1212
13- (* * Check if the dune project has ocamllsp server as a dev-tool. *)
14- val is_ocamllsp_present : t -> bool Promise .t
15-
1613(* * Generic function to execute dune commands *)
1714val command : t -> args :string list -> Cmd .t
1815
@@ -22,8 +19,16 @@ val exec : target:string -> ?args:string list -> t -> Cmd.t
2219(* * Run specific `dune pkg <foo> commands*)
2320val exec_pkg : cmd :string -> ?args : string list -> t -> Cmd .t
2421
25- (* * Execute any `dune tools exec` command*)
26- val exec_tool : tool :string -> ?args : string list -> t -> Cmd .t
22+ (* * Run `dune tools <exec/which>` *)
23+ val tools
24+ : tool:string
25+ -> ?args:string list
26+ -> t
27+ -> [< `Exec_ | `Which | `Install ]
28+ -> Cmd. t
29+
30+ (* * Check if the dune project has ocamllsp server as a dev-tool. *)
31+ val is_ocamllsp_present : t -> bool Promise .t
2732
2833(* * Check if amy two instances of dune pkg management projects are equal *)
2934val equal : t -> t -> bool
Original file line number Diff line number Diff line change @@ -114,14 +114,14 @@ let _install_dune_lsp_server =
114114 let options =
115115 ProgressOptions. create
116116 ~location: (`ProgressLocation Notification )
117- ~title: " Installing ocaml-lsp server using `dune tools exec ocamllsp`"
117+ ~title: " Installing ocaml-lsp server using `dune tools install ocamllsp`"
118118 ~cancellable: false
119119 ()
120120 in
121121 let task ~progress :_ ~token :_ =
122122 let + result =
123123 (* We first check the version so that the process can exit, otherwise the progress indicator runs forever.*)
124- Sandbox. get_command sandbox " ocamllsp" [ " --version " ] `Tool
124+ Sandbox. get_command sandbox " ocamllsp" [] `Install
125125 |> Cmd. output ~cwd: (Dune. root dune)
126126 in
127127 match result with
Original file line number Diff line number Diff line change @@ -545,13 +545,20 @@ let select_sandbox_and_save t =
545545 Some sandbox
546546;;
547547
548- let get_command sandbox bin args (dune_cmd_type : [> `Tool | `Command | `Exec ] ) : Cmd.t =
548+ let get_command
549+ sandbox
550+ bin
551+ args
552+ (dune_cmd_type : [> `Tool | `Command | `Exec | `Install ] )
553+ : Cmd. t
554+ =
549555 match sandbox with
550556 | Opam (opam , switch ) -> Opam. exec opam switch ~args: (bin :: args)
551557 | Esy (esy , manifest ) -> Esy. exec esy manifest ~args: (bin :: args)
552558 | Dune dune ->
553559 (match dune_cmd_type with
554- | `Tool -> Dune. exec_tool ~tool: bin ~args dune
560+ | `Install -> Dune. tools ~tool: bin ~args dune `Install
561+ | `Tool -> Dune. tools ~tool: bin ~args dune `Exec_
555562 | `Command -> Dune. command dune ~args
556563 | `Exec -> Dune. exec ~target: bin ~args dune)
557564 | Global -> Spawn { bin = Path. of_string bin; args }
Original file line number Diff line number Diff line change @@ -54,7 +54,12 @@ val select_sandbox : t -> t option Promise.t
5454(* Helper utils *)
5555
5656(* * Extract command to run with the sandbox *)
57- val get_command : t -> string -> string list -> [ `Command | `Exec | `Tool ] -> Cmd .t
57+ val get_command
58+ : t
59+ -> string
60+ -> string list
61+ -> [ `Command | `Exec | `Tool | `Install ]
62+ -> Cmd. t
5863
5964(* * Command to install dependencies in the sandbox *)
6065val get_install_command : t -> string list -> Cmd .t option
You can’t perform that action at this time.
0 commit comments