[cfe-dev] Identifier autocompletion behaviour

Bianca-Cristina Cristescu via cfe-dev cfe-dev at lists.llvm.org
Mon Feb 1 09:20:28 PST 2016


 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160201/a5f36f4e/attachment.html>


More information about the cfe-dev mailing list