diff --git a/src-bindings/vscode/vscode.ml b/src-bindings/vscode/vscode.ml index b66baf528..1d79dbdce 100644 --- a/src-bindings/vscode/vscode.ml +++ b/src-bindings/vscode/vscode.ml @@ -189,19 +189,21 @@ module LightDarkIcon = struct let light_js = Ojs.get_prop_ascii js_val "light" in let dark_js = Ojs.get_prop_ascii js_val "dark" in let light = - if Ojs.has_property light_js "parse" then `Uri ([%js.to: Uri.t] light_js) + if Ojs.has_property light_js "parse" + then `Uri ([%js.to: Uri.t] light_js) else `String ([%js.to: string] light_js) in let dark = - if Ojs.has_property dark_js "parse" then `Uri ([%js.to: Uri.t] dark_js) + if Ojs.has_property dark_js "parse" + then `Uri ([%js.to: Uri.t] dark_js) else `String ([%js.to: string] dark_js) in { light; dark } + ;; end module ThemeColor = struct include Class.Make () - include [%js: val make : id:string -> t [@@js.new "vscode.ThemeColor"]] end @@ -210,16 +212,13 @@ module ThemeIcon = struct include [%js: - val make : id:string -> ?color:ThemeColor.t -> unit -> t - [@@js.new "vscode.ThemeIcon"] - - val file : t [@@js.global "vscode.ThemeIcon.File"] - - val folder : t [@@js.global "vscode.ThemeIcon.Folder"] - - val id : t -> string [@@js.get] + val make : id:string -> ?color:ThemeColor.t -> unit -> t + [@@js.new "vscode.ThemeIcon"] - val color : t -> ThemeColor.t or_undefined [@@js.get]] + val file : t [@@js.global "vscode.ThemeIcon.File"] + val folder : t [@@js.global "vscode.ThemeIcon.Folder"] + val id : t -> string [@@js.get] + val color : t -> ThemeColor.t or_undefined [@@js.get]] end module TextDocument = struct @@ -469,11 +468,6 @@ module MarkdownString = struct val appendCodeblock : t -> value:string -> ?language:string -> unit -> t [@@js.call]] end -module ThemeColor = struct - include Class.Make () - include [%js: val make : id:string -> t [@@js.new "vscode.ThemeColor"]] -end - module ThemableDecorationAttachmentRenderOptions = struct include Interface.Make () @@ -953,50 +947,20 @@ module QuickInputButton = struct [@@js] let iconPath_of_js js_val = - if Ojs.has_property js_val "path" then `Uri ([%js.to: Uri.t] js_val) - else if Ojs.has_property js_val "id" then - `ThemeIcon ([%js.to: ThemeIcon.t] js_val) - else if Ojs.has_property js_val "light" then - `LightDark ([%js.to: LightDarkIcon.t] js_val) - else assert false - - include - [%js: - val iconPath : t -> iconPath [@@js.get] - - val tooltip : t -> string or_undefined [@@js.get] - - val create : iconPath:iconPath -> ?tooltip:string -> unit -> t - [@@js.builder]] -end - -module QuickInputButton = struct - include Interface.Make () - - type iconPath = - ([ `Uri of Uri.t - | `LightDark of LightDarkIcon.t - | `ThemeIcon of ThemeIcon.t - ] - [@js.union]) - [@@js] - - let iconPath_of_js js_val = - if Ojs.has_property js_val "path" then `Uri ([%js.to: Uri.t] js_val) - else if Ojs.has_property js_val "id" then - `ThemeIcon ([%js.to: ThemeIcon.t] js_val) - else if Ojs.has_property js_val "light" then - `LightDark ([%js.to: LightDarkIcon.t] js_val) + if Ojs.has_property js_val "path" + then `Uri ([%js.to: Uri.t] js_val) + else if Ojs.has_property js_val "id" + then `ThemeIcon ([%js.to: ThemeIcon.t] js_val) + else if Ojs.has_property js_val "light" + then `LightDark ([%js.to: LightDarkIcon.t] js_val) else assert false + ;; include [%js: - val iconPath : t -> iconPath [@@js.get] - - val tooltip : t -> string or_undefined [@@js.get] - - val create : iconPath:iconPath -> ?tooltip:string -> unit -> t - [@@js.builder]] + val iconPath : t -> iconPath [@@js.get] + val tooltip : t -> string or_undefined [@@js.get] + val create : iconPath:iconPath -> ?tooltip:string -> unit -> t [@@js.builder]] end module QuickPickItem = struct @@ -1069,93 +1033,68 @@ module QuickPick = struct include [%js: - val onDidAccept : t -> unit Event.t [@@js.get] - - val onDidChangeActive : t -> T.t list Event.t [@@js.get] - - val onDidChangeSelection : t -> T.t list Event.t [@@js.get] - - val onDidChangeValue : t -> string Event.t [@@js.get] - - val onDidHide : t -> unit Event.t [@@js.get] - - val onDidTriggerButton : t -> QuickInputButton.t Event.t [@@js.get] - - val activeItems : t -> T.t list or_undefined [@@js.get] - - val set_activeItems : t -> T.t list or_undefined -> unit [@@js.set] - - val busy : t -> bool or_undefined [@@js.get] - - val set_busy : t -> bool or_undefined -> unit [@@js.set] - - val buttons : t -> QuickInputButton.t list or_undefined [@@js.get] - - val set_buttons : t -> QuickInputButton.t list or_undefined -> unit - [@@js.set] - - val canSelectMany : t -> bool or_undefined [@@js.get] - - val set_canSelectMany : t -> bool or_undefined -> unit [@@js.set] - - val enabled : t -> bool or_undefined [@@js.get] - - val set_enabled : t -> bool or_undefined -> unit [@@js.set] - - val ignoreFocusOut : t -> bool or_undefined [@@js.get] - - val set_ignoreFocusOut : t -> bool or_undefined -> unit [@@js.set] - - val items : t -> T.t list or_undefined [@@js.get] - - val set_items : t -> T.t list or_undefined -> unit [@@js.set] - - val keepScrollPosition : t -> bool or_undefined [@@js.get] - - val set_keepScrollPosition : t -> bool or_undefined -> unit [@@js.set] - - val matchOnDescription : t -> bool or_undefined [@@js.get] - - val set_matchOnDescription : t -> bool or_undefined -> unit [@@js.set] - - val matchOnDetail : t -> bool or_undefined [@@js.get] - - val set_matchOnDetail : t -> bool or_undefined -> unit [@@js.set] - - val placeholder : t -> string or_undefined [@@js.get] - - val set_placeholder : t -> string or_undefined -> unit [@@js.set] - - val selectedItems : t -> T.t list or_undefined [@@js.get] - - val set_selectedItems : t -> T.t list or_undefined -> unit [@@js.set] - - val step : t -> int or_undefined [@@js.get] - - val set_step : t -> int or_undefined -> unit [@@js.set] - - val title : t -> string or_undefined [@@js.get] - - val set_title : t -> string or_undefined -> unit [@@js.set] - - val totalSteps : t -> int or_undefined [@@js.get] - - val set_totalSteps : t -> int or_undefined -> unit [@@js.set] - - val value : t -> string or_undefined [@@js.get] - - val set_value : t -> string or_undefined -> unit [@@js.set] - - val dispose : t -> unit [@@js.call] - - val hide : t -> unit [@@js.call] - - val show : t -> unit [@@js.call]] - - let set t ?activeItems ?busy ?buttons ?canSelectMany ?enabled - ?ignoreFocusOut ?items ?keepScrollPosition ?matchOnDescription - ?matchOnDetail ?placeholder ?selectedItems ?step ?title ?totalSteps - ?value () = + val onDidAccept : t -> unit Event.t [@@js.get] + val onDidChangeActive : t -> T.t list Event.t [@@js.get] + val onDidChangeSelection : t -> T.t list Event.t [@@js.get] + val onDidChangeValue : t -> string Event.t [@@js.get] + val onDidHide : t -> unit Event.t [@@js.get] + val onDidTriggerButton : t -> QuickInputButton.t Event.t [@@js.get] + val activeItems : t -> T.t list or_undefined [@@js.get] + val set_activeItems : t -> T.t list or_undefined -> unit [@@js.set] + val busy : t -> bool or_undefined [@@js.get] + val set_busy : t -> bool or_undefined -> unit [@@js.set] + val buttons : t -> QuickInputButton.t list or_undefined [@@js.get] + val set_buttons : t -> QuickInputButton.t list or_undefined -> unit [@@js.set] + val canSelectMany : t -> bool or_undefined [@@js.get] + val set_canSelectMany : t -> bool or_undefined -> unit [@@js.set] + val enabled : t -> bool or_undefined [@@js.get] + val set_enabled : t -> bool or_undefined -> unit [@@js.set] + val ignoreFocusOut : t -> bool or_undefined [@@js.get] + val set_ignoreFocusOut : t -> bool or_undefined -> unit [@@js.set] + val items : t -> T.t list or_undefined [@@js.get] + val set_items : t -> T.t list or_undefined -> unit [@@js.set] + val keepScrollPosition : t -> bool or_undefined [@@js.get] + val set_keepScrollPosition : t -> bool or_undefined -> unit [@@js.set] + val matchOnDescription : t -> bool or_undefined [@@js.get] + val set_matchOnDescription : t -> bool or_undefined -> unit [@@js.set] + val matchOnDetail : t -> bool or_undefined [@@js.get] + val set_matchOnDetail : t -> bool or_undefined -> unit [@@js.set] + val placeholder : t -> string or_undefined [@@js.get] + val set_placeholder : t -> string or_undefined -> unit [@@js.set] + val selectedItems : t -> T.t list or_undefined [@@js.get] + val set_selectedItems : t -> T.t list or_undefined -> unit [@@js.set] + val step : t -> int or_undefined [@@js.get] + val set_step : t -> int or_undefined -> unit [@@js.set] + val title : t -> string or_undefined [@@js.get] + val set_title : t -> string or_undefined -> unit [@@js.set] + val totalSteps : t -> int or_undefined [@@js.get] + val set_totalSteps : t -> int or_undefined -> unit [@@js.set] + val value : t -> string or_undefined [@@js.get] + val set_value : t -> string or_undefined -> unit [@@js.set] + val dispose : t -> unit [@@js.call] + val hide : t -> unit [@@js.call] + val show : t -> unit [@@js.call]] + + let set + t + ?activeItems + ?busy + ?buttons + ?canSelectMany + ?enabled + ?ignoreFocusOut + ?items + ?keepScrollPosition + ?matchOnDescription + ?matchOnDetail + ?placeholder + ?selectedItems + ?step + ?title + ?totalSteps + ?value + () + = set_activeItems t activeItems; set_busy t busy; set_buttons t buttons; @@ -1173,6 +1112,7 @@ module QuickPick = struct set_totalSteps t totalSteps; set_value t value; t + ;; end end @@ -1207,35 +1147,11 @@ module InputBoxValidationMessage = struct include [%js: - val message : t -> string [@@js.get] - - val severity : t -> InputBoxValidationSeverity.t [@@js.get] - - val create : - message:string -> severity:InputBoxValidationSeverity.t -> unit -> t - [@@js.builder]] -end - -module InputBoxValidationSeverity = struct - type t = - | Info [@js 1] - | Warning [@js 2] - | Error [@js 3] - [@@js.enum] [@@js] -end - -module InputBoxValidationMessage = struct - include Interface.Make () - - include - [%js: - val message : t -> string [@@js.get] - - val severity : t -> InputBoxValidationSeverity.t [@@js.get] + val message : t -> string [@@js.get] + val severity : t -> InputBoxValidationSeverity.t [@@js.get] - val create : - message:string -> severity:InputBoxValidationSeverity.t -> unit -> t - [@@js.builder]] + val create : message:string -> severity:InputBoxValidationSeverity.t -> unit -> t + [@@js.builder]] end module InputBoxOptions = struct @@ -1271,59 +1187,46 @@ module InputBox = struct include [%js: - val title : t -> string or_undefined [@@js.get] - - val set_title : t -> string or_undefined -> unit [@@js.set] - - val enabled : t -> bool [@@js.get] - - val set_enabled : t -> bool -> unit [@@js.set] - - val busy : t -> bool [@@js.get] - - val set_busy : t -> bool -> unit [@@js.set] - - val ignoreFocusOut : t -> bool or_undefined [@@js.get] - - val set_ignoreFocusOut : t -> bool or_undefined -> unit [@@js.set] - - val onDidHide : t -> unit Event.t [@@js.get] - - val value : t -> string or_undefined [@@js.get] - - val set_value : t -> string or_undefined -> unit [@@js.set] - - val valueSelection : t -> (int * int) or_undefined [@@js.get] - - val set_valueSelection : t -> (int * int) or_undefined -> unit [@@js.set] - - val placeholder : t -> string or_undefined [@@js.get] - - val set_placeholder : t -> string or_undefined -> unit [@@js.set] - - val password : t -> bool or_undefined [@@js.get] - - val set_password : t -> bool or_undefined -> unit [@@js.set] - - val onDidChangeValue : t -> string Event.t [@@js.get] - - val onDidAccept : t -> unit Event.t [@@js.get] - - val prompt : t -> string or_undefined [@@js.get] - - val set_prompt : t -> string or_undefined -> unit [@@js.set] - - val validationMessage : t -> InputBoxValidationMessage.t or_undefined - [@@js.get] + val title : t -> string or_undefined [@@js.get] + val set_title : t -> string or_undefined -> unit [@@js.set] + val enabled : t -> bool [@@js.get] + val set_enabled : t -> bool -> unit [@@js.set] + val busy : t -> bool [@@js.get] + val set_busy : t -> bool -> unit [@@js.set] + val ignoreFocusOut : t -> bool or_undefined [@@js.get] + val set_ignoreFocusOut : t -> bool or_undefined -> unit [@@js.set] + val onDidHide : t -> unit Event.t [@@js.get] + val value : t -> string or_undefined [@@js.get] + val set_value : t -> string or_undefined -> unit [@@js.set] + val valueSelection : t -> (int * int) or_undefined [@@js.get] + val set_valueSelection : t -> (int * int) or_undefined -> unit [@@js.set] + val placeholder : t -> string or_undefined [@@js.get] + val set_placeholder : t -> string or_undefined -> unit [@@js.set] + val password : t -> bool or_undefined [@@js.get] + val set_password : t -> bool or_undefined -> unit [@@js.set] + val onDidChangeValue : t -> string Event.t [@@js.get] + val onDidAccept : t -> unit Event.t [@@js.get] + val prompt : t -> string or_undefined [@@js.get] + val set_prompt : t -> string or_undefined -> unit [@@js.set] + val validationMessage : t -> InputBoxValidationMessage.t or_undefined [@@js.get] - val set_validationMessage : - t -> InputBoxValidationMessage.t or_undefined -> unit - [@@js.set] + val set_validationMessage : t -> InputBoxValidationMessage.t or_undefined -> unit + [@@js.set] - val show : t -> unit [@@js.call]] + val show : t -> unit [@@js.call]] - let set t ?title ?ignoreFocusOut ?value ?valueSelection ?placeholder ?password - ?prompt ?validationMessage () = + let set + t + ?title + ?ignoreFocusOut + ?value + ?valueSelection + ?placeholder + ?password + ?prompt + ?validationMessage + () + = set_title t title; set_ignoreFocusOut t ignoreFocusOut; set_value t value; @@ -1333,6 +1236,7 @@ module InputBox = struct set_prompt t prompt; set_validationMessage t validationMessage; t + ;; end module OpenDialogOptions = struct @@ -2500,20 +2404,6 @@ module TreeItemLabel = struct [@@js.builder]] end -module ThemeIcon = struct - include Class.Make () - - include - [%js: - val make : id:string -> ?color:ThemeColor.t -> unit -> t - [@@js.new "vscode.ThemeIcon"] - - val file : t [@@js.global "vscode.ThemeIcon.File"] - val folder : t [@@js.global "vscode.ThemeIcon.Folder"] - val id : t -> string [@@js.get] - val color : t -> ThemeColor.t or_undefined [@@js.get]] -end - module TreeItem = struct include Class.Make () @@ -2532,30 +2422,6 @@ module TreeItem = struct else assert false ;; - module LightDarkIcon = struct - type t = - { light : ([ `String of string | `Uri of Uri.t ][@js.union]) - ; dark : ([ `String of string | `Uri of Uri.t ][@js.union]) - } - [@@js] - - let t_of_js js_val = - let light_js = Ojs.get_prop_ascii js_val "light" in - let dark_js = Ojs.get_prop_ascii js_val "dark" in - let light = - if Ojs.has_property light_js "parse" - then `Uri ([%js.to: Uri.t] light_js) - else `String ([%js.to: string] light_js) - in - let dark = - if Ojs.has_property dark_js "parse" - then `Uri ([%js.to: Uri.t] dark_js) - else `String ([%js.to: string] dark_js) - in - { light; dark } - ;; - end - type iconPath = ([ `String of string | `Uri of Uri.t @@ -3089,9 +2955,11 @@ module Window = struct -> MessageItem.t or_undefined Promise.t [@@js.global "vscode.window.showErrorMessage"] - val createQuickPick : - ((module Ojs.T with type t = 'a)[@js]) -> unit -> 'a QuickPick.t - [@@js.global "vscode.window.createQuickPick"] + val createQuickPick + : ((module Ojs.T with type t = 'a)[@js]) + -> unit + -> 'a QuickPick.t + [@@js.global "vscode.window.createQuickPick"] val showQuickPickItems : choices:QuickPickItem.t list @@ -3109,8 +2977,8 @@ module Window = struct -> string or_undefined Promise.t [@@js.global "vscode.window.showQuickPick"] - val quickInputButtonBack : QuickInputButton.t - [@@js.global "vscode.QuickInputButtons.Back"] + val quickInputButtonBack : QuickInputButton.t + [@@js.global "vscode.QuickInputButtons.Back"] val showInputBox : ?options:InputBoxOptions.t @@ -3119,8 +2987,7 @@ module Window = struct -> string or_undefined Promise.t [@@js.global "vscode.window.showInputBox"] - val createInputBox : unit -> InputBox.t - [@@js.global "vscode.window.createInputBox"] + val createInputBox : unit -> InputBox.t [@@js.global "vscode.window.createInputBox"] val showOpenDialog : ?options:OpenDialogOptions.t diff --git a/src-bindings/vscode/vscode.mli b/src-bindings/vscode/vscode.mli index e95655bf3..514e8664b 100644 --- a/src-bindings/vscode/vscode.mli +++ b/src-bindings/vscode/vscode.mli @@ -163,13 +163,9 @@ module ThemeIcon : sig include Ojs.T val make : id:string -> ?color:ThemeColor.t -> unit -> t - val file : t - val folder : t - val id : t -> string - val color : t -> ThemeColor.t option end @@ -701,9 +697,7 @@ module QuickInputButton : sig ] val iconPath : t -> iconPath - val tooltip : t -> string option - val create : iconPath:iconPath -> ?tooltip:string -> unit -> t end @@ -761,89 +755,49 @@ module QuickPick : sig type nonrec t = T.t t val onDidAccept : t -> unit Event.t - val onDidChangeActive : t -> T.t list Event.t - val onDidChangeSelection : t -> T.t list Event.t - val onDidChangeValue : t -> string Event.t - val onDidHide : t -> unit Event.t - val onDidTriggerButton : t -> QuickInputButton.t Event.t - val activeItems : t -> T.t list option - val set_activeItems : t -> T.t list option -> unit - val busy : t -> bool option - val set_busy : t -> bool option -> unit - val buttons : t -> QuickInputButton.t list option - val set_buttons : t -> QuickInputButton.t list option -> unit - val canSelectMany : t -> bool option - val set_canSelectMany : t -> bool option -> unit - val enabled : t -> bool option - val set_enabled : t -> bool option -> unit - val ignoreFocusOut : t -> bool option - val set_ignoreFocusOut : t -> bool option -> unit - val items : t -> T.t list option - val set_items : t -> T.t list option -> unit - val keepScrollPosition : t -> bool option - val set_keepScrollPosition : t -> bool option -> unit - val matchOnDescription : t -> bool option - val set_matchOnDescription : t -> bool option -> unit - val matchOnDetail : t -> bool option - val set_matchOnDetail : t -> bool option -> unit - val placeholder : t -> string option - val set_placeholder : t -> string option -> unit - val selectedItems : t -> T.t list option - val set_selectedItems : t -> T.t list option -> unit - val step : t -> int option - val set_step : t -> int option -> unit - val title : t -> string option - val set_title : t -> string option -> unit - val totalSteps : t -> int option - val set_totalSteps : t -> int option -> unit - val value : t -> string option - val set_value : t -> string option -> unit - val dispose : t -> unit - val hide : t -> unit - val show : t -> unit - val set : - t + val set + : t -> ?activeItems:T.t list -> ?busy:bool -> ?buttons:QuickInputButton.t list @@ -887,11 +841,8 @@ module InputBoxValidationMessage : sig include Ojs.T val message : t -> string - val severity : t -> InputBoxValidationSeverity.t - - val create : - message:string -> severity:InputBoxValidationSeverity.t -> unit -> t + val create : message:string -> severity:InputBoxValidationSeverity.t -> unit -> t end module InputBoxOptions : sig @@ -923,56 +874,32 @@ module InputBox : sig include Ojs.T val title : t -> string option - val set_title : t -> string option -> unit - val enabled : t -> bool - val set_enabled : t -> bool -> unit - val busy : t -> bool - val set_busy : t -> bool -> unit - val ignoreFocusOut : t -> bool option - val set_ignoreFocusOut : t -> bool option -> unit - val onDidHide : t -> unit Event.t - val value : t -> string option - val set_value : t -> string option -> unit - val valueSelection : t -> (int * int) option - val set_valueSelection : t -> (int * int) option -> unit - val placeholder : t -> string option - val set_placeholder : t -> string option -> unit - val password : t -> bool option - val set_password : t -> bool option -> unit - val onDidChangeValue : t -> string Event.t - val onDidAccept : t -> unit Event.t - val prompt : t -> string option - val set_prompt : t -> string option -> unit - val validationMessage : t -> InputBoxValidationMessage.t or_undefined - - val set_validationMessage : - t -> InputBoxValidationMessage.t or_undefined -> unit - + val set_validationMessage : t -> InputBoxValidationMessage.t or_undefined -> unit val show : t -> unit - val set : - t + val set + : t -> ?title:string -> ?ignoreFocusOut:bool -> ?value:string @@ -1798,16 +1725,6 @@ module TreeItemLabel : sig val highlights : t -> (int * int) list option end -module ThemeIcon : sig - include Ojs.T - - val make : id:string -> ?color:ThemeColor.t -> unit -> t - val file : t - val folder : t - val id : t -> string - val color : t -> ThemeColor.t option -end - module TreeItem : sig include Ojs.T @@ -2214,7 +2131,6 @@ module Window : sig -> 'a option Promise.t val createQuickPick : 'a Js.t -> unit -> 'a QuickPick.t - val quickInputButtonBack : QuickInputButton.t val showQuickPick @@ -2231,7 +2147,6 @@ module Window : sig -> string option Promise.t val createInputBox : unit -> InputBox.t - val showOpenDialog : ?options:OpenDialogOptions.t -> unit -> Uri.t list option Promise.t val createOutputChannel : name:string -> OutputChannel.t diff --git a/src/custom_requests.ml b/src/custom_requests.ml index cfdaece17..d3e27da15 100644 --- a/src/custom_requests.ml +++ b/src/custom_requests.ml @@ -180,19 +180,17 @@ module Type_search = struct let encode_params { uri; position; limit; query; with_doc; doc_format } = let open Jsonoo.Encode in - let uri = - ("textDocument", object_ [ ("uri", string @@ Uri.toString uri ()) ]) - in - let position = ("position", Position.json_of_t position) in - let query = ("query", string query) in - let limit = ("limit", int limit) in - let with_doc = ("with_doc", bool with_doc) in + let uri = "textDocument", object_ [ "uri", string @@ Uri.toString uri () ] in + let position = "position", Position.json_of_t position in + let query = "query", string query in + let limit = "limit", int limit in + let with_doc = "with_doc", bool with_doc in let doc_format = ( "doc_format" - , MarkupKind.json_of_t - (Option.value ~default:MarkupKind.Markdown doc_format) ) + , MarkupKind.json_of_t (Option.value ~default:MarkupKind.Markdown doc_format) ) in object_ [ uri; position; query; limit; with_doc; doc_format ] + ;; let decode_response response = let open Jsonoo.Decode in @@ -206,11 +204,19 @@ module Type_search = struct { name; typ; loc; doc; cost; constructible } in list decode_res response + ;; - let make ~uri ~position ~limit ~query ~with_doc - ?(doc_format = Some MarkupKind.Markdown) () = + let make + ~uri + ~position + ~limit + ~query + ~with_doc + ?(doc_format = Some MarkupKind.Markdown) + () + = { uri; position; limit; query; with_doc; doc_format } + ;; - let request = - { meth = ocamllsp_prefixed "typeSearch"; encode_params; decode_response } + let request = { meth = ocamllsp_prefixed "typeSearch"; encode_params; decode_response } end diff --git a/src/custom_requests.mli b/src/custom_requests.mli index 88128ea6d..3bdbdfe42 100644 --- a/src/custom_requests.mli +++ b/src/custom_requests.mli @@ -76,11 +76,10 @@ module Type_search : sig } type params - type response = type_search_result list - val make : - uri:Uri.t + val make + : uri:Uri.t -> position:Position.t -> limit:int -> query:string diff --git a/src/extension_commands.ml b/src/extension_commands.ml index 77400958a..0b658aa96 100644 --- a/src/extension_commands.ml +++ b/src/extension_commands.ml @@ -760,9 +760,11 @@ module Search_by_type = struct match TextDocument.languageId textdoc with | "ocaml" | "ocaml.interface" | "reason" | "ocaml.ocamllex" -> true | _ -> false + ;; let ocaml_lsp_doesnt_support_search_by_type ocaml_lsp = not (Ocaml_lsp.can_handle_search_by_type ocaml_lsp) + ;; let get_search_results ~query ~limit ~with_doc ~position text_editor client = let doc = TextEditor.document text_editor in @@ -773,6 +775,7 @@ module Search_by_type = struct Type_search.request (Type_search.make ~uri ~position ~limit ~query ~with_doc ())) |> Promise.catch ~rejected:(fun _ -> Promise.return []) + ;; let input_box = (* Re-using the same instance of the input box allows us to remember the @@ -784,8 +787,7 @@ module Search_by_type = struct ~ignoreFocusOut:false ~placeholder:"int -> string / -int +string" ~prompt: - "Perform a search by type request by providing a type signature to \ - look for" + "Perform a search by type request by providing a type signature to look for" () in let _disposable = @@ -795,6 +797,7 @@ module Search_by_type = struct () in box + ;; let rec display_search_results query results text_editor position client = let format_doc (doc : MarkupContent.t option) = @@ -803,14 +806,12 @@ module Search_by_type = struct | None -> "" in let quickPickItems = - List.map - results - ~f:(fun (res : Custom_requests.Type_search.type_search_result) -> - QuickPickItem.create - ~label:res.name - ~description:res.typ - ~detail:(format_doc res.doc) - ()) + List.map results ~f:(fun (res : Custom_requests.Type_search.type_search_result) -> + QuickPickItem.create + ~label:res.name + ~description:res.typ + ~detail:(format_doc res.doc) + ()) in let module QuickPick = Vscode.QuickPick.Make (QuickPickItem) in let quickPick = @@ -844,20 +845,15 @@ module Search_by_type = struct Vscode.TextEditor.edit text_editor ~callback:(fun ~editBuilder -> - Vscode.TextEditorEdit.insert - editBuilder - ~location:position - ~value) + Vscode.TextEditorEdit.insert editBuilder ~location:position ~value) () in QuickPick.hide quickPick - | _ -> - display_search_results query results text_editor position client) + | _ -> display_search_results query results text_editor position client) () in let _disposable = - QuickPick.onDidHide quickPick ~listener:(fun () -> - QuickPick.dispose quickPick) + QuickPick.onDidHide quickPick ~listener:(fun () -> QuickPick.dispose quickPick) in QuickPick.show quickPick @@ -872,12 +868,11 @@ module Search_by_type = struct in let _update_input_box = let validationMessage = - if empty_result then + if empty_result + then Some (InputBoxValidationMessage.create - ~message: - "No result found. Check the syntax or use a more general \ - query." + ~message:"No result found. Check the syntax or use a more general query." ~severity:Warning ()) else None @@ -894,9 +889,7 @@ module Search_by_type = struct | Some query -> let () = InputBox.set_busy input_box true in let () = InputBox.set_enabled input_box false in - let position = - TextEditor.selection text_editor |> Selection.active - in + let position = TextEditor.selection text_editor |> Selection.active in ignore (let+ query_results = get_search_results @@ -913,26 +906,20 @@ module Search_by_type = struct let results = List.remove_consecutive_duplicates ~which_to_keep:`First - ~equal:(fun - (left : - Custom_requests.Type_search.type_search_result) - right - -> - String.equal left.name right.name - && left.cost = right.cost) + ~equal: + (fun + (left : Custom_requests.Type_search.type_search_result) + right -> + String.equal left.name right.name && left.cost = right.cost) results in - display_search_results - query - results - text_editor - position - client) + display_search_results query results text_editor position client) | None -> ()) () in previous := Some onDidAccept_disposable; InputBox.show input_box + ;; let _search_by_type = let handler (instance : Extension_instance.t) ~args:_ = @@ -941,26 +928,26 @@ module Search_by_type = struct Extension_consts.Command_errors.text_editor_must_be_active extension_name ~expl: - "The cursor position is used to determine the correct environment \ - and insert the result." + "The cursor position is used to determine the correct environment and insert \ + the result." |> show_message `Error "%s" - | Some text_editor - when not (is_valid_text_doc (TextEditor.document text_editor)) -> + | Some text_editor when not (is_valid_text_doc (TextEditor.document text_editor)) -> show_message `Error - "Invalid file type. This command only works in ocaml files, ocaml \ - interface files, reason files or ocamllex files." - | Some text_editor -> ( - match Extension_instance.lsp_client instance with - | None -> show_message `Warn "ocamllsp is not running" - | Some (_client, ocaml_lsp) - when ocaml_lsp_doesnt_support_search_by_type ocaml_lsp -> - show_message - `Warn - "The installed version of `ocamllsp` does not support type search" - | Some (client, _) -> show_query_input text_editor client) + "Invalid file type. This command only works in ocaml files, ocaml interface \ + files, reason files or ocamllex files." + | Some text_editor -> + (match Extension_instance.lsp_client instance with + | None -> show_message `Warn "ocamllsp is not running" + | Some (_client, ocaml_lsp) + when ocaml_lsp_doesnt_support_search_by_type ocaml_lsp -> + show_message + `Warn + "The installed version of `ocamllsp` does not support type search" + | Some (client, _) -> show_query_input text_editor client) in command Extension_consts.Commands.search_by_type handler + ;; end let register extension instance = function diff --git a/src/extension_consts.ml b/src/extension_consts.ml index b7c7c67cb..3c311d42a 100644 --- a/src/extension_consts.ml +++ b/src/extension_consts.ml @@ -35,7 +35,6 @@ module Commands = struct let copy_type_under_cursor = ocaml_prefixed "copy-type-under-cursor" let construct = ocaml_prefixed "construct" let merlin_jump = ocaml_prefixed "jump" - let search_by_type = ocaml_prefixed "search-by-type" end diff --git a/src/import.ml b/src/import.ml index 871c743f1..cdb6586c3 100644 --- a/src/import.ml +++ b/src/import.ml @@ -186,6 +186,7 @@ module MarkupKind = struct match t with | PlainText -> Jsonoo.Encode.string "plaintext" | Markdown -> Jsonoo.Encode.string "markdown" + ;; let t_of_json (json : Jsonoo.t) : t = match Jsonoo.Decode.string json with @@ -193,6 +194,7 @@ module MarkupKind = struct | "markdown" -> Markdown (* Default to plaintext *) | _ -> PlainText + ;; end module MarkupContent = struct @@ -206,6 +208,7 @@ module MarkupContent = struct let kind = field "kind" MarkupKind.t_of_json json in let value = field "value" string json in { kind; value } + ;; end module Promise = struct diff --git a/src/ocaml_lsp.ml b/src/ocaml_lsp.ml index 2ca001ff4..cda1f1477 100644 --- a/src/ocaml_lsp.ml +++ b/src/ocaml_lsp.ml @@ -242,5 +242,4 @@ let can_handle_typed_holes t = t.experimental_capabilities.handleTypedHoles let can_handle_type_enclosing t = t.experimental_capabilities.handleTypeEnclosing let can_handle_construct t = t.experimental_capabilities.handleConstruct let can_handle_merlin_jump t = t.experimental_capabilities.handleJump - let can_handle_search_by_type t = t.experimental_capabilities.handleSearchByType diff --git a/src/ocaml_lsp.mli b/src/ocaml_lsp.mli index a57ff6968..afecac1df 100644 --- a/src/ocaml_lsp.mli +++ b/src/ocaml_lsp.mli @@ -10,7 +10,6 @@ val can_handle_typed_holes : t -> bool val can_handle_type_enclosing : t -> bool val can_handle_construct : t -> bool val can_handle_merlin_jump : t -> bool - val can_handle_search_by_type : t -> bool module OcamllspSettingEnable : sig diff --git a/src/treeview_commands.ml b/src/treeview_commands.ml index 6b34e5ed9..66ab4f187 100644 --- a/src/treeview_commands.ml +++ b/src/treeview_commands.ml @@ -66,22 +66,11 @@ let jump_item = item ;; -let items = [ select_sandbox_item; terminal_item; construct_item; jump_item ] -let perform_type_search = - let icon = - `LightDark - Vscode.LightDarkIcon. - { light = - `String (Path.asset "document-search-light.svg" |> Path.to_string) - ; dark = - `String (Path.asset "document-search-dark.svg" |> Path.to_string) - } - in +let type_search_item = + let icon = `ThemeIcon (Vscode.ThemeIcon.make ~id:"search-view-icon" ()) in let label = `TreeItemLabel - (Vscode.TreeItemLabel.create - ~label:"Search a value by type or polarity" - ()) + (Vscode.TreeItemLabel.create ~label:"Search a value by type or polarity" ()) in let item = Vscode.TreeItem.make_label ~label () in let command = @@ -93,8 +82,11 @@ let perform_type_search = Vscode.TreeItem.set_iconPath item icon; Vscode.TreeItem.set_command item command; item +;; -let items = [ select_sandbox_item; terminal_item; perform_type_search ] +let items = + [ select_sandbox_item; terminal_item; construct_item; jump_item; type_search_item ] +;; let getTreeItem ~element = `Value element