[cfe-dev] Using libclang to determine the location of a completion result

Douglas Gregor dgregor at apple.com
Thu Aug 30 12:54:54 PDT 2012


On Aug 30, 2012, at 11:50 AM, Peter Geoghegan <peter at 2ndquadrant.com> wrote:

> Hello,
> 
> I'm a user of clang_complete, a vim plugin that uses libclang's python
> bindings to provide really nice code-completion for users of the vim
> text editor:
> 
> https://github.com/Rip-Rip/clang_complete
> 
> As great as this is, it is functionally inferior to Omnicppcomplete in
> one area: The lack of information about completion results.
> Omnicppcomplete optionally provides information about the filename
> that the declaration of the just-completed/highlighted for completion
> symbol came from. As far as I can tell, it is impossible for
> clang_complete to support this, due to the lack of upstream support. I
> refer specifically to this comment within the CXCompletionResult
> struct:
> 
> 04031    * \todo In the future, we would like to provide a full cursor, to allow
> 04032    * the client to extract additional information from declaration.
> 04033    */
> 
> So, with completion implemented essentially by calling
> clang_codeCompleteAt(), I can see no way of working backwards to
> obtain some basic information pertaining to the
> just-completed/previewed token. However, I have an idea that other
> text editors do support something along the same lines. I wonder, do
> they employ some trickery like immediately obtaining a CXCursor for
> the symbol under the text editor's cursor after completion is
> finished?

I don't know of any libclang-based editors that do this.

> It would be tricky to get that to work while traversing a
> visual list of possible completions (for each completion), so I hope
> the actual trick is much cleverer than that. Also, I don't suppose
> that someone has plans to take the time to complete this todo item?

The best approach is probably just to record file/line/column in the code completion result within libclang.

	- Doug




More information about the cfe-dev mailing list