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

ml/mli completion #282

Open dbuenzli opened 9 years ago

dbuenzli commented 9 years ago

Suppose you just defined a name in an mli file and then go into the ml file to implement it, it would be nice to be able to complete it by typing let prefix... and vice versa in an mli file from a ml.

let-def commented 9 years ago

You don't suggest always having those names in the environment, only when completing a top-lvel pattern / declaration ?

dbuenzli commented 9 years ago

Sorry, didn't understand your comment.

gasche commented 9 years ago

@def-lkb wonders whether you would like the names declared in the .mli to be available for completion everywhere in the .ml file, or only when declaring toplevel names (let here ... = ..;;).

dbuenzli commented 9 years ago

Ah heu, oh I don't know, I just want to complete when it's time to complete, so I guess everywhere; but once you defined the toplevel declaration it should be available no ?

gasche commented 9 years ago

When completing in a .mli it makes sense to have access to all names from the .ml at all times. When completing from a .ml, there is a difference. As you note, once a definition is done in the .ml, it is avaiable to all successive phrases -- but right now it is not available "before" in the buffer and that is probably the right behavior, at least I personally would find it a bit surprising. Completing with the .mli names at the place of a new declaration makes sense (especially at the toplevel), that is in a pattern, but in expressions it seems strange to suggest a completion that doesn't type-check because the name is not yet in the current environment.

trefis commented 9 years ago

Completing with the .mli names at the place of a new declaration makes sense (especially at the toplevel), that is in a pattern, but in expressions it seems strange to suggest a completion that doesn't type-check because the name is not yet in the current environment.

Agreed.

dbuenzli commented 9 years ago

I don't think you should follow the idea that you complete only sound things. The way we (or at least I) program is not by constantly having a type-checkable source (see e.g. #273). Before @def-lkb made me switch to company-mode I have been using auto-complete mode for a long time and it had heuristics on how to find identifiers in my open buffers without knowing anything about language. There would occasionnally be noise or bogus suggestions, but there was always the right identifier in the mix and this was already a huge productivity improvement. Just let me complete that unsound thing, the next save will tell me I have to actually declare that identifier somewhere.

dbuenzli commented 9 years ago

I.e. the tool should help me to write code, not interfere with my thinking/problem solving by mandating that I declare the identifier formally before being able to complete it.

hcarty commented 9 years ago

If the change is made to show everything when performing a completion please make it optional. Most editors' built-in completion can handle context-free word completion well enough. merlin adds typing and other niceties, but those become less useful if they aren't "true" in the completion's context.

dbuenzli commented 9 years ago

Le lundi, 27 octobre 2014 à 04:26, Hezekiah M. Carty a écrit :

If the change is made to show everything when performing a completion please make it optional.

I'm not asking for everything, I'm asking for what's in the mli.

Most editors' built-in completion can handle context-free word completion well enough. merlin adds typing and other niceties, but those become less useful if they aren't "true" in the completion's context.

As suggested above, for identifier completion, I think it's a bad idea to ask for type-checking truth in the context of code editing. Not every of your editing operations makes your source type checkable. Failing to take that into account makes the tool less useful, it's eventual type checkability your after.

Daniel

let-def commented 9 years ago

(ignore last reference, I referenced wrong issue -_-)

dbuenzli commented 9 years ago

In the same vein I notice that merlin won't allow me to complete the name of a recursive function if the rec keyword is absent.

Again I think it's wrong. By refusing to do so you are interrupting my stream of thought which is about implementing a recursive function to solve a problem, not about the minutiae of having that rec keyword at the right place which is an insignificant problem that can be fixed later compared to the one I'm trying to solve. This insignificant problem will be immediately highlighted in red at the next save when, having written my function, my brain will be ready for fixing insignificant errors.

Good editor assistance is not to refuse to complete that identifier. Good editor assistance would tell me on the next save "here it seems you are trying to implement a recursive function but you forgot the rec keyword, do you want me to introduce it for you ?".

In general merlin completion seems to be to the service of the typechecker rather than the (human) programmer and that feels completely wrong. It makes me bother about things at times when as a programmer trying to solve a problem I don't want to bother about but fix later.