Valloric/YouCompleteMe — pull request #1300 by oblitum (2014-12-29 05:34:59+00:00)
Title: RFC: Argument hints, a.k.a. parameter completions!

This week I’ve setup myself to accomplish some nice argument _completion_ that’s in line with YouCompleteMe’s spirit.

I’d like to talk about the reasoning of the design first:

- There can’t be any _argument completion_ per se, only type hints for the arguments being passed. So I’m not gonna refer to this as _parameter completion_, but as _argument hints_.

- We should stay away from a mechanism like the one employed by Jedi. It’s pure hackery and very prone to instability. I’ve tryed it and it breaks just because one is using one colorscheme or another. We should try to stick with the native popup mechanisms offered by Vim to be stable.

- We can’t start to try parsing function prototypes ourselves (I mean the Vim plugin) to provide the hints. Such semantic analysis power should come from Clang.

From these two assumptions I’ve devised the following design that can live in harmony with the rest of YCM:

- There should be a new kind of trigger for argument hints.

- Once the user starts typing text _after_ the argument hint trigger, the normal YCM completion should be able to take place. Argument hints should popup solely at the spot of an argument hint trigger, and nowhere else.

- Argument hints should not provide text for completion, just hints in the popup, but no text for completion for them.

- Example candidates for argument hints are `(` and `,`.

- libClang should be smart enough to complete after `(` and `,` to provide argument hints, if not, we should try to improve it for that and not try to hammer it on YCM’s side.

I say this’s in line with YouCompleteMe’s spirit because it doesn’t requires pressing `Enter`, etc, for some kind of selection of arguments.

[Check The Video](https://vimeo.com/115547016)

This pull is actually working for C completion with the current libclang. C++ completion requires improvements in Clang’s codebase. Argument hints are a weak point of libclang at this moment, [I’ve created a patch that makes it work for C++](https://github.com/oblitum/clang/commit/b58da472c88961d2e1c9d1d8212d375bfb7d94ae), but it doesn’t work for providing hints for template arguments, for functors, or constructors, which can all work with some bit of effort probably. Nonetheless, having it working for functions, function template instances and member variations of both is quite OK. I’ll have to discuss this on the cfe-dev mailing list later.

This pull is also targetting issue #1287. I’ve removed full prototypes from the default completion popup since they can get annoying, and are less useful with this enabled.

I’m providing this pull as an RFC at this moment. I’ve not provided any tests yet and I’d like to hear comments/suggestions/critics and the feasibility of it being merged. I’ll sign the CLA after that, or not.

On issue #234 I mention another method that resembles clang_complete, which also works and currently serves for template arguments. I also provide it for YCM in my fork.

Last but not least: for anyone out there, HIRE ME ;-)

Happy holidays!