Skip to content

Commit

Permalink
remove duneContexts and call describe contexts from the vscode extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavarri committed May 3, 2024
1 parent 18e4a38 commit 9d34868
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 43 deletions.
6 changes: 0 additions & 6 deletions src/custom_requests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,3 @@ let typedHoles =
Jsonoo.Encode.(object_ [ ("uri", string @@ Uri.toString uri ()) ]))
; decode_response = Jsonoo.Decode.list Range.t_of_json
}

let getDuneContexts =
{ meth = ocamllsp_prefixed "duneContexts"
; encode_params = (fun () -> Jsonoo.Encode.null)
; decode_response = Jsonoo.Decode.(list string)
}
2 changes: 0 additions & 2 deletions src/custom_requests.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ val switchImplIntf : (string, string array) custom_request
val inferIntf : (string, string) custom_request

val typedHoles : (Uri.t, Range.t list) custom_request

val getDuneContexts : (unit, string list) custom_request
60 changes: 37 additions & 23 deletions src/extension_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,30 +191,44 @@ let _set_dune_context =
in
Window.showQuickPickItems ~choices ~options ()
in
let select_dune_context client =
let* candidates =
Custom_requests.send_request client Custom_requests.getDuneContexts ()
in
let* context = select_context candidates in
match context with
| None (* context selection cancelled *) -> Promise.return ()
| Some new_context ->
let* () = Settings.set Settings.dune_context_setting new_context in
Extension_instance.start_language_server instance
let select_dune_context () =
match Workspace.rootPath () with
| None ->
(* Assumes that Dune root matches the workspace root *)
Promise.return
(show_message
`Warn
"Project root wasn't found. Can't select Dune context without \
project root.")
| Some root -> (
let* result =
let sandbox = Extension_instance.sandbox instance in
let cmd =
Sandbox.get_command sandbox "dune" [ "describe"; "contexts" ]
in
let env =
Interop.Dict.of_alist [ ("DUNE_CONFIG__GLOBAL_LOCK", "disabled") ]
in
Cmd.output ~env ~cwd:(Path.of_string root) cmd
in
match result with
| Error msg ->
Promise.return
(show_message
`Warn
"Error when calling `dune describe contexts': %s"
msg)
| Ok output -> (
let candidates = String.split output ~on:'\n' in
let* context = select_context candidates in
match context with
| None (* context selection cancelled *) -> Promise.return ()
| Some new_context ->
let* () = Settings.set Settings.dune_context_setting new_context in
Extension_instance.start_language_server instance))
in
match Extension_instance.lsp_client instance with
| None -> show_message `Warn "ocamllsp is not running."
| Some (client, ocaml_lsp) ->
if Ocaml_lsp.can_handle_dune_contexts ocaml_lsp then
let (_ : unit Promise.t) = select_dune_context client in
()
else
(* if ocamllsp doesn't have the capability, recommend updating
ocamllsp*)
show_message
`Warn
"The installed version of ocamllsp does not support setting the Dune \
context. Consider updating ocamllsp."
let (_ : unit Promise.t) = select_dune_context () in
()
in
command Extension_consts.Commands.select_dune_context handler

Expand Down
4 changes: 0 additions & 4 deletions src/extension_instance.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ end = struct
let server_options sandbox =
let args = Settings.(get server_args_setting) |> Option.value ~default:[] in
let args =
(* `handleDuneContexts` capability is already checked when getting the
contexts for the `ocaml.select-dune-context` command, so the only way
to get here with a version of ocamllsp that doesn't support contexts is
if the user adds the `dune.context` setting manually *)
match Settings.get Settings.dune_context_setting with
| None -> args
| Some context -> "--context" :: context :: args
Expand Down
6 changes: 0 additions & 6 deletions src/ocaml_lsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ module Experimental_capabilities = struct
; handleSwitchImplIntf : bool
; handleInferIntf : bool
; handleTypedHoles : bool
; handleDuneContexts : bool
}

let default =
{ interfaceSpecificLangId = false
; handleSwitchImplIntf = false
; handleInferIntf = false
; handleTypedHoles = false
; handleDuneContexts = false
}

(** Creates [t] given a JSON of form [{ 'handleSwitchImplIntf' : true, .... }] *)
Expand All @@ -67,12 +65,10 @@ module Experimental_capabilities = struct
let handleSwitchImplIntf = has_capability "handleSwitchImplIntf" in
let handleInferIntf = has_capability "handleInferIntf" in
let handleTypedHoles = has_capability "handleTypedHoles" in
let handleDuneContexts = has_capability "handleDuneContexts" in
{ interfaceSpecificLangId
; handleSwitchImplIntf
; handleInferIntf
; handleTypedHoles
; handleDuneContexts
}
with Jsonoo.Decode_error err ->
show_message
Expand Down Expand Up @@ -234,5 +230,3 @@ let can_handle_switch_impl_intf t =
let can_handle_infer_intf t = t.experimental_capabilities.handleSwitchImplIntf

let can_handle_typed_holes t = t.experimental_capabilities.handleTypedHoles

let can_handle_dune_contexts t = t.experimental_capabilities.handleDuneContexts
2 changes: 0 additions & 2 deletions src/ocaml_lsp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ val can_handle_infer_intf : t -> bool

val can_handle_typed_holes : t -> bool

val can_handle_dune_contexts : t -> bool

module OcamllspSettingEnable : sig
include Ojs.T

Expand Down

0 comments on commit 9d34868

Please sign in to comment.