Auto completion

Ciprian Ciubotariu cheepeero at gmx.net
Sun Oct 2 11:44:16 UTC 2011



On Mon, 2011-09-26 at 20:36 +0200, Baradé wrote:
> - When implementing member functions auto completion doesn't consider 
> that it is in namespace of some identifiers already:
> namespace bla
> {
> 
> class Haha
> {
>         public:
>                 enum Test
>                 {
>                 };
> 
>                 Test test();
> };
> 
> // Here it completes:
> bla::Haha::Test test()
> {
> }
> 
> // instead of only Haha::Test
> 
> }

I am also bumping into this constant minor annoyance. Unfortunately the
rules of the C++ language are very loose with regard to namespaces, so
they allow for multiple styles and inconsistencies in referring to names
across namespaces. The way kdevelop generates it is somewhat the
"fallback" way, since it works in all situations.

Say you have class Haha in namespace bla just like a above. You can use
the following styles for the implementation, either in the .cpp or .hpp
file:

1. 

using namespace bla;

Haha::test() { ... }


2. 

namespace bla {
  Haha::test() { ... }
}


3.

bla::Haha::Test() { ... }


However, bla::Haha is also correct in case 1 because the name bla::Haha
does exist (even though the using directive imported it into the global
namespace).

In case 2 the compiler would look first for bla::bla::Haha, and since
it's not found it starts another search from the global namespace.



One implementation to remove the annoyance of deleting the extra bla::
prefix (like I do) would be to check if the name kdevelop is completing
is visible from the completion context:

namespace bla {
  Haha::   <-- here Haha is visible, so don't qualify
}

Haha::     <-- here Haha is only visible via the bla:: prefix


I might implement and contribute that if I get spare time someday in the
future.





More information about the KDevelop-devel mailing list