File tree Expand file tree Collapse file tree 3 files changed +32
-7
lines changed
Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,8 @@ navigating through errors:
4343In ` ocaml-eglot ` one can display the type of the expression below the cursor and
4444navigate the enclosing nodes while increasing or decreasing verbosity:
4545
46- - ` ocaml-eglot-type-enclosing ` (<kbd >C-c</kbd > <kbd >C-t</kbd >)
47- Display the type of the selection and start a "type enclosing" session.
46+ - ` ocaml-eglot-type-enclosing ` (<kbd >C-c</kbd > <kbd >C-t</kbd >):
47+ display the type of the selection and start a "type enclosing" session.
4848
4949During a "type enclosing" session the following commands are available:
5050
@@ -59,6 +59,12 @@ During a "type enclosing" session the following commands are available:
5959 expression
6060- ` ocaml-eglot-type-enclosing-copy ` (<kbd >C-w</kbd >): to copy the
6161 type expression to the _ kill-ring_ (clipboard)
62+
63+ You can also enter an expression in the mini-buffer for which you want
64+ to display the type:
65+
66+ - ` ocaml-eglot-type-expression ` (<kbd >C-u</kbd > <kbd >C-c</kbd > <kbd >C-t</kbd >)
67+
6268
6369![ Type Enclosings example] ( media/type-enclosing.gif )
6470
Original file line number Diff line number Diff line change @@ -196,10 +196,17 @@ ARGV is the list of arguments."
196196
197197(defun ocaml-eglot-req--phrase (target )
198198 " Compute the beginning of the phrase referenced by TARGET."
199- ; TODO: use a dedicated custom request instead of tunneling
199+ ; ; TODO: use a dedicated custom request instead of tunneling
200200 (let ((argv (vector " -position" (ocaml-eglot-util-point-as-arg (point ))
201201 " -target" target)))
202202 (ocaml-eglot-req--merlin-call " phrase" argv)))
203203
204+ (defun ocaml-eglot-req--type-expression (expression )
205+ " Get the type of EXPRESSION inside the local context."
206+ ; ; TODO: use a dedicated custom request instead of tunneling
207+ (let ((argv (vector " -position" (ocaml-eglot-util-point-as-arg (point ))
208+ " -expression" expression)))
209+ (ocaml-eglot-req--merlin-call " type-expression" argv)))
210+
204211(provide 'ocaml-eglot-req )
205212; ;; ocaml-eglot-req.el ends here
Original file line number Diff line number Diff line change @@ -473,11 +473,23 @@ It use the ARG to use local values or not."
473473
474474; ; Type Enclosings
475475
476- (defun ocaml-eglot-type-enclosing ()
476+ (defun ocaml-eglot-type-expression (expression )
477+ " Prompt the user for expression EXPRESSION and print its type."
478+ (interactive " sExpression: " )
479+ (let* ((result (ocaml-eglot-req--type-expression expression))
480+ (type-expr (ocaml-eglot-util--merlin-call-result result)))
481+ (ocaml-eglot-type-enclosing--display type-expr nil )))
482+
483+ (defun ocaml-eglot-type-enclosing (&optional prefix )
477484 " Print the type of the expression under point (or of the region, if it exists).
478- If called repeatedly, increase the verbosity of the type shown."
479- (interactive )
480- (ocaml-eglot-type-enclosing--call))
485+ If called repeatedly, increase the verbosity of the type shown.
486+ if PREFIX is given, prompt the user for expression EXPRESSION
487+ and print its type."
488+ (interactive " P" )
489+ (if prefix
490+ (call-interactively #'ocaml-eglot-type-expression )
491+ (ocaml-eglot-type-enclosing--call)))
492+
481493
482494; ; Case Analysis
483495
You can’t perform that action at this time.
0 commit comments