forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to build and run ocamllsp
This command will exit with an error message unless it's run within a dune project with a dune.lock directory containing a lockfile for the package "ocaml" so it's not ready for use by editors. Support for falling back to a system or opam-managed installation of ocamllsp will come in a later change. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
- Loading branch information
Showing
8 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
open! Import | ||
module Pkg_dev_tool = Dune_rules.Pkg_dev_tool | ||
|
||
let ocamllsp_exe_path = Path.build @@ Pkg_dev_tool.exe_path Ocamllsp | ||
let ocamllsp_exe_name = Pkg_dev_tool.exe_name Ocamllsp | ||
|
||
(* Replace the current dune process with ocamllsp. *) | ||
let run_ocamllsp common ~args = | ||
let exe_path_string = Path.to_string ocamllsp_exe_path in | ||
Console.print_user_message | ||
(Dune_rules.Pkg_build_progress.format_user_message | ||
~verb:"Running" | ||
~object_: | ||
(User_message.command (String.concat ~sep:" " (ocamllsp_exe_name :: args)))); | ||
Console.finish (); | ||
restore_cwd_and_execve common exe_path_string (exe_path_string :: args) Env.initial | ||
;; | ||
|
||
let build_ocamllsp common = | ||
let open Fiber.O in | ||
let+ result = | ||
Build_cmd.run_build_system ~common ~request:(fun _build_system -> | ||
Action_builder.path ocamllsp_exe_path) | ||
in | ||
match result with | ||
| Error `Already_reported -> raise Dune_util.Report_error.Already_reported | ||
| Ok () -> () | ||
;; | ||
|
||
let is_in_dune_project builder = | ||
Workspace_root.create | ||
~default_is_cwd:(Common.Builder.default_root_is_cwd builder) | ||
~specified_by_user:(Common.Builder.root builder) | ||
|> Result.is_ok | ||
;; | ||
|
||
let term = | ||
let+ builder = Common.Builder.term | ||
and+ args = Arg.(value & pos_all string [] (info [] ~docv:"ARGS")) in | ||
match is_in_dune_project builder with | ||
| false -> | ||
User_error.raise | ||
[ Pp.textf | ||
"Unable to run %s as a dev-tool because you don't appear to be inside a dune \ | ||
project." | ||
ocamllsp_exe_name | ||
] | ||
| true -> | ||
let common, config = Common.init builder in | ||
Scheduler.go ~common ~config (fun () -> | ||
let open Fiber.O in | ||
let* () = Lock_dev_tool.lock_ocamllsp () |> Memo.run in | ||
let+ () = build_ocamllsp common in | ||
run_ocamllsp common ~args) | ||
;; | ||
|
||
let info = | ||
let doc = "Run ocamllsp, installing it as a dev tool if necessary." in | ||
Cmd.info "ocamllsp" ~doc | ||
;; | ||
|
||
let command = Cmd.v info term |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
open! Import | ||
|
||
(** Command to run ocamllsp, installing it if necessary *) | ||
val command : unit Cmd.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open! Import | ||
|
||
module Exec = struct | ||
let doc = "Command group for running wrapped tools." | ||
let info = Cmd.info ~doc "exec" | ||
let group = Cmd.group info [ Ocamllsp.command ] | ||
end | ||
|
||
let doc = "Command group for wrapped tools." | ||
let info = Cmd.info ~doc "tools" | ||
let group = Cmd.group info [ Exec.group ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
open Import | ||
|
||
val group : unit Cmd.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters