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 =
70
70
Fs. exists (Path. to_string dune_lock_path)
71
71
;;
72
72
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
-
83
73
let command t ~args = Cmd. Spawn (Cmd. append t.bin args)
84
74
85
75
let exec ~target ?(args = [] ) t =
@@ -88,8 +78,21 @@ let exec ~target ?(args = []) t =
88
78
89
79
let exec_pkg ~cmd ?(args = [] ) t = Cmd. Spawn (Cmd. append t.bin ([ " pkg" ; cmd ] @ args))
90
80
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
93
96
;;
94
97
95
98
let 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 =
10
10
If not, user should be advised to run `dune pkg lock` *)
11
11
val is_project_locked : t -> bool Promise .t
12
12
13
- (* * Check if the dune project has ocamllsp server as a dev-tool. *)
14
- val is_ocamllsp_present : t -> bool Promise .t
15
-
16
13
(* * Generic function to execute dune commands *)
17
14
val command : t -> args :string list -> Cmd .t
18
15
@@ -22,8 +19,16 @@ val exec : target:string -> ?args:string list -> t -> Cmd.t
22
19
(* * Run specific `dune pkg <foo> commands*)
23
20
val exec_pkg : cmd :string -> ?args : string list -> t -> Cmd .t
24
21
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
27
32
28
33
(* * Check if amy two instances of dune pkg management projects are equal *)
29
34
val equal : t -> t -> bool
Original file line number Diff line number Diff line change @@ -114,14 +114,14 @@ let _install_dune_lsp_server =
114
114
let options =
115
115
ProgressOptions. create
116
116
~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`"
118
118
~cancellable: false
119
119
()
120
120
in
121
121
let task ~progress :_ ~token :_ =
122
122
let + result =
123
123
(* 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
125
125
|> Cmd. output ~cwd: (Dune. root dune)
126
126
in
127
127
match result with
Original file line number Diff line number Diff line change @@ -545,13 +545,20 @@ let select_sandbox_and_save t =
545
545
Some sandbox
546
546
;;
547
547
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
+ =
549
555
match sandbox with
550
556
| Opam (opam , switch ) -> Opam. exec opam switch ~args: (bin :: args)
551
557
| Esy (esy , manifest ) -> Esy. exec esy manifest ~args: (bin :: args)
552
558
| Dune dune ->
553
559
(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_
555
562
| `Command -> Dune. command dune ~args
556
563
| `Exec -> Dune. exec ~target: bin ~args dune)
557
564
| 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
54
54
(* Helper utils *)
55
55
56
56
(* * 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
58
63
59
64
(* * Command to install dependencies in the sandbox *)
60
65
val get_install_command : t -> string list -> Cmd .t option
You can’t perform that action at this time.
0 commit comments