hackwaly / vscode-ocaml

An extension for VS Code which provides support for the OCaml language.
MIT License
170 stars 26 forks source link

Jump to enclosing fun, let, module or match #95

Open Khady opened 7 years ago

Khady commented 7 years ago

This is a feature request

In merlin mode for emacs, there is a function to jump to enclosing fun, let, module or match, which is very convenient. I would love to have it in vscode too.

https://github.com/ocaml/merlin/blob/master/doc/dev/PROTOCOL.md#jump--target-string--position-position

Not present in the old protocol doc, but the command is available. I think it is something like ["jump", "fun let module match", "at", POSITION]

(defun merlin/jump (&optional target)
  "Jump to the TARGET"
  (let ((result (merlin/send-command
                  (list 'jump (if (equal target "") "fun let module match" target)
                        'at (merlin/unmake-point (point))))))
    (unless result
      (error "Not found. (Check *Messages* for potential errors)"))
    (unless (listp result)
      (error result))
    result))
C-c C-j runs the command merlin-jump, which is an interactive Lisp
function in `merlin.el'.

It is bound to C-c C-j.

(merlin-jump &optional TARGET)

Jump to enclosing fun, let, module or match.

Any combination of the above may be entered, separated by spaces, ex.:

fun let or module or module fun match

Empty string defaults to jumping to all these.