[cfe-dev] Identifier autocompletion behaviour

Argyrios Kyrtzidis via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 9 10:44:28 PST 2016


Hi Cristina,

There is no inherit filtering in clang code-completion, what you need to do on the client side is:

- When cursor is immediately after an identifier, invoke clang code-completion at the column location where the identifier begins
- Get all the results, then filter them using the identifier as filtering hint.

Let me know if you have any other questions.

> On Feb 1, 2016, at 9:20 AM, Bianca-Cristina Cristescu via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hello,
> 
> I am working on autocompletion in the context of cling (https://root.cern.ch/cling <https://mmm.cern.ch/owa/redir.aspx?C=uJ-aTnQK4Uuu63K_-62ZB9lhrt-KMNMISzgTuVv6J_9YwDFhO3ofuTkvJrVPSJOIGwZuUCspl3I.&URL=https%3a%2f%2froot.cern.ch%2fcling>). 
> I am trying to use clang’s autocompletion on identifiers. 
> The file that I am using as a test case is the following:
> testTabComp.cxx
> class MyClass {
> private:
>      //data members
>   int anInteger;
>        double aDouble;
> 
>    //function members
> public:
>      MyClass(int i, double d) { 
>              anInteger = i;
>             aDouble = d;
>      }     
>       int getInt() { return anInteger; }
>        double getDouble() { return aDouble; }
>     void setInt(int value) { anInteger = value; }
>       void setDouble(double value) { aDouble = value; }
> };
> 
> int main() {
> 
>   MyClass* objectMyClass = new MyClass(5, 1.0);
>         objectMyClass->set\r
>      return 0;
> }
> 
> I am invoing clang with: 
> ../Debug+Asserts/bin/clang -cc1 -code-completion-at=testTabComp.cxx:32:23 testTabComp.cxx
> 
> If I omit the "set" token then it autocompletes correctly:
> COMPLETION: aDouble : [#double#]aDouble
> COMPLETION: anInteger : [#int#]anInteger
> COMPLETION: getDouble : [#double#]getDouble()
> COMPLETION: getInt : [#int#]getInt()
> COMPLETION: MyClass : MyClass::
> COMPLETION: operator= : [#MyClass &#]operator=(<#const MyClass &#>)
> COMPLETION: setDouble : [#void#]setDouble(<#double value#>)
> COMPLETION: setInt : [#void#]setInt(<#int value#>)
> COMPLETION: ~MyClass : [#void#]~MyClass()
> 
> But if I don't then I get the whole world:
> testTabComp.cxx:32:17: error: no member named 'set' in 'MyClass'
>         objectMyClass->set
>         ~~~~~~~~~~~~~  ^
> COMPLETION: __FUNCTION__
> COMPLETION: __PRETTY_FUNCTION__
> COMPLETION: bool
> COMPLETION: char
> COMPLETION: class
> COMPLETION: int
> COMPLETION: long
> COMPLETION: main : [#int#]main()
> COMPLETION: MyClass : MyClass
> COMPLETION: MyClass : MyClass(<#int i#>, <#double d#>)
> COMPLETION: MyClass : MyClass(<#const MyClass &#>)
> ....
> 
> Is that the intended behaviour for code completion of member functions when the completion point is not immediatly after the "->"? 
> 
> If there is another way to do this I would appreciate any help! 
> PS: I tried libclang as well, but I got the same behaviour.
> 
> Thank you! 
>  
> Cheers,
> Cristina Cristescu
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160209/3cd18e0e/attachment.html>


More information about the cfe-dev mailing list