Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Add jump to enclosing fun, let, module or match #60

Open
Khady opened this issue May 26, 2017 · 3 comments
Open

Add jump to enclosing fun, let, module or match #60

Khady opened this issue May 26, 2017 · 3 comments

Comments

@Khady
Copy link
Collaborator

Khady commented May 26, 2017

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.

In addition, it could be nice to display somewhere those information (in which enclosing fun, let, module, match, the cursor currently is), maybe in the status bar.

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.
@ghost
Copy link

ghost commented May 26, 2017

I think it is possible to add this. I've experimented with a similar feature for Reason but I ended up not publishing it because there were reliability issues. I think the problems were specific to Merlin/Reason though so it would probably have been fine with plain OCaml.

As far as signifying where the cursor will jump to, we could probably do that too but I'm not sure that using the status bar for that is ideal. I'd rather try to have some sort of faint outline or similar decoration around the enclosing scope if possible. The problem with the status bar is that there's already a lot of contention with other extensions for space and stuff like that and the API for it just isn't all that flexible to begin with.

I'll take a look at getting something like this implemented in an upcoming release.

@Khady
Copy link
Collaborator Author

Khady commented Sep 13, 2017

If this is implemented, is it possible to put it in the language server so that all the editors using the language server benefit from this or it has to be in this extension? I don't know if the language server protocol is "extensible" to support such additions.

@ghost
Copy link

ghost commented Sep 13, 2017

It is possible to implement on the server using custom RPC messages. This would be available to all clients, but they would still need to have some minimal support code to send the command and respond to the result.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants
@Khady and others