Skip to content

Commit

Permalink
Refactor type enclosing custom request (ocamllabs#1623)
Browse files Browse the repository at this point in the history
* refactor type enclosing

* Update src/custom_requests.ml

---------

Co-authored-by: Ulysse <5031221+voodoos@users.noreply.github.com>
  • Loading branch information
PizieDust and voodoos committed Oct 23, 2024
1 parent e4bf80c commit 9637b14
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/custom_requests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let typedHoles =
}

module Type_enclosing = struct
type request_params =
type params =
{ uri : Uri.t
; at : [ `Position of Position.t | `Range of Range.t ]
; index : int
Expand Down Expand Up @@ -68,9 +68,8 @@ module Type_enclosing = struct
let enclosings = field "enclosings" (list Range.t_of_json) response in
{ index; type_; enclosings }

let make ~uri ~at ~index ~verbosity = { uri; at; index; verbosity }

let request =
{ meth = ocamllsp_prefixed "typeEnclosing"; encode_params; decode_response }

let send ~uri ~at ~index ~verbosity client =
send_request client request { uri; at; index; verbosity }
end
9 changes: 6 additions & 3 deletions src/custom_requests.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ val inferIntf : (string, string) custom_request
val typedHoles : (Uri.t, Range.t list) custom_request

module Type_enclosing : sig
type params

type response =
{ index : int
; type_ : string
; enclosings : Range.t list
}

val send :
val make :
uri:Uri.t
-> at:[ `Position of Position.t | `Range of Range.t ]
-> index:int
-> verbosity:int
-> LanguageClient.t
-> response Promise.t
-> params

val request : (params, response) custom_request
end
15 changes: 9 additions & 6 deletions src/extension_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,15 @@ module Copy_type_under_cursor = struct
let doc = TextEditor.document text_editor in
let uri = TextDocument.uri doc in
let selection = TextEditor.selection text_editor in
Custom_requests.Type_enclosing.send
~uri
~at:(`Range (Selection.to_range selection))
~index:0
~verbosity:0
client
Custom_requests.(
send_request
client
Type_enclosing.request
(Type_enclosing.make
~uri
~at:(`Range (Selection.to_range selection))
~index:0
~verbosity:0))

let _copy_type_under_cursor =
let handler (instance : Extension_instance.t) ~args:_ =
Expand Down

0 comments on commit 9637b14

Please sign in to comment.