ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.57k stars 233 forks source link

Feature request: display module/function at current cursor #414

Open ghost opened 9 years ago

ghost commented 9 years ago

I couldn't find this feature in merlin, so I'm suggesting and asking if it would be feasible:

I'd like to have a command/indicator that tells me in which function/module the cursor is.

It often happens that when reading code inside a function and/or module that is several buffers long (in the middle of which I arrived e.g. by grepping a certain word), I have to scroll up to identify in which exact function I am, and then scroll down again. And if there is just one empty line between two functions, I may miss it and think I'm inside another function.

I know that the notion of "function name" is not as well defined in OCaml as in imperative languages, but all I'd like to know is the topmost let and/or module I'm inside of.

Is there already something like this?

If not, would it be relatively simple to implement? Or perhaps this is syntactic enough that could/should be handled by Tuareg?

let-def commented 9 years ago

I don't think this should be handled by Tuareg. We have partial support for features really close to that (like outline), it shouldn't be much work to integrate that to some future version.

neojski commented 9 years ago

@thranur, I'm working on a very similar feature that I currently just call jump. You can have a look at my jump branch. Basically, it introduces a command (right now works only in vim) called :MerlinJump. You can give it an argument like fun,let,match,module (default) or subset like match,module. It'll then jump to the ancestor node that is of this type.

If you have some additional ideas, please share.

let-def commented 8 years ago

If you are still interested, there is a proof of concept for this feature. It is not yet working properly because of some assumptions made in the AST breaking the qualified path, but this shouldn't be too hard to fix.

Though, it won't make it to next release.

ghost commented 8 years ago

@neojski , sorry I didn't have much time lately to try things, especially because I don't use Vim.

@def-lkb, I'm still interested, though I'm not sure about the easiest way to try it (I believe I should use the command-line ocamlmerlin for that, no? There's no binding yet for Emacs, right?). I'll see if I find instructions on how to use it to be able to test the proof of concept.

let-def commented 8 years ago

@thranur no binding yet, feature is not finished. I will tell you when proof of concept is ready for test.

neojski commented 8 years ago

@thranur, the jump feature is not vim specific. It works in emacs as well.