Bug 203954

Summary: Please add an option to hide duplicates in code completion
Product: [Applications] kdevelop Reporter: Alexander <ashaduri>
Component: Language Support: CPP (old)Assignee: kdevelop-bugs-null
Status: REPORTED ---    
Severity: wishlist CC: bufalo1973, david.nolden.kde, vdboor
Priority: LO    
Version First Reported In: git master   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Alexander 2009-08-15 15:30:07 UTC
Version:           SVN (using KDE 4.3.0)
Compiler:          gcc 4.3.2 
OS:                Linux
Installed from:    SuSE RPMs

The following example illustrates the problem:

struct A {
	void g(int) { }
	void g(float) { }
	void g(short) { }
	void g(double) { }
	void g(bool) { }
	void g2(bool) { }
};

void f()
{
	A a;
	a.  // a minimal code completion pops up, containing 5 similar entries for "g".
}


With minimal completion, typing "a." (without quotes) always pops up a completion window with 5 "g" entries which look exactly the same. Pressing enter on any of them does exactly the same thing, types "g()" and places the cursor inside ().

The only different behaviour is when g is a function template (the cursor is placed inside <>) or if it doesn't have any parameters (the cursor is placed after ()). Note that there are no visual clues which function I'm actually selecting.

Most of time time, people don't care how many overloaded functions are there, they just want to get to g2() or pick any of them.

While clicking the entries shows their details (not sure how to do that with the keyboard though), I think a better way needs to be developed, so that the completion doesn't get polluted with entries which are identical in 90% of the cases.

This whole bugreport could be considered as a wish for a more usable code completion popup.
Comment 1 David Nolden 2009-08-15 15:39:25 UTC
You can expand the items by keyboard using the ALT key (See http://zwabel.wordpress.com/2008/12/10/code-navigation-in-kdevelop4-meet-the-magic-modifier/).

Generally, the minimal completion mode is mainly ment as a kind of 'typing assistant', it doesn't contain any information with the items, and isn't ment to be used for browsing. So why is it such a problem here if the items are there multiple times? At least for the typing assistance, it doesn't make a big difference.
Comment 2 Alexander 2009-08-15 16:02:52 UTC
(In reply to comment #1)
> You can expand the items by keyboard using the ALT key (See
> http://zwabel.wordpress.com/2008/12/10/code-navigation-in-kdevelop4-meet-the-magic-modifier/).

Thanks. However, releasing the alt key moves the cursor to the File menu, and pressing arrows while Alt is pressed scrolls the expanded description (documentation), not the cursor across the entries. Are these bugs I should file?

> Generally, the minimal completion mode is mainly ment as a kind of 'typing
> assistant', it doesn't contain any information with the items, and isn't ment
> to be used for browsing. So why is it such a problem here if the items are
> there multiple times? At least for the typing assistance, it doesn't make a big
> difference.

Yes, the thing is, as a typing assistant, it should allow me to quickly scroll and select the desired item. However, as with example above, I have to press the down arrow 5 times just to get to g2(). Since the 5 g() entries do exactly the same, it just doesn't make sense to have them there.

Of course, expanding them shows different results, but I think that could be dealt with some other way. For example, show the duplicates only after expanding (not sure about the details though). The full completion would still show all the signatures.

With the following code:

struct A {
	void g(int) { }
	void g(float) { }
	void g(short) { }
	void g(double) { }
	void g(bool) { }
	void g() { }
	template <typename T> void g() { };
};

the minimal completion could show only "g()", "g(args)", "g<>()", which would really improve the usability of this feature. There are less things to read and select from this way.

The current completion dialog doesn't even show which ones are templates, so the selection process is somewhat blind (choose the sixth "g" to have the template, etc...).

With large classes with lots of overloaded functions the popup gets real messy. For example,

#include <QString>

void f()
{
    QString s;
    s.  // shows 6 compare entries, 18 (!!) arg entries, etc...
}
Comment 3 David Nolden 2009-08-15 16:27:12 UTC
Releasing ALT should definitely not move you into the file menu.

But ALT+Arrow allows you to navigate within the expanded information, so that one is not a bug.

About the completion: 'Typing assistant' to me means that you type, and at some point maybe press 'enter' to speed it up a bit. Scrolling through a list and selecting an item is not really assisted typing, but rather a kind of 'browsing', and that is what the full completion mode should be used for.

Additionally it could lead to other problems: For example, overloaded functions may return different types, and then the context type-matching cannot pick the correct one any more to highlight entries.

Overall I agree, it would be good if the minimal completion would merge items with the same name at some point. But it's such a low benefit given the needed work that it probably won't happen any time soon.
Comment 4 Alexander 2009-08-15 17:03:46 UTC
(In reply to comment #3)
> Releasing ALT should definitely not move you into the file menu.

Filed as bug # 203962.

> About the completion: 'Typing assistant' to me means that you type, and at some
> point maybe press 'enter' to speed it up a bit. Scrolling through a list and
> selecting an item is not really assisted typing, but rather a kind of
> 'browsing', and that is what the full completion mode should be used for.

Yes, but when there are similarily named functions (at least if they start similarily) and you want to select the second one, pressing enter on the first one is not something you want. And to get to the second one, you have to scroll.
Plus, it's a subjective thing. Some people use it only occasionally, and some people use it all time time, as a real fast assistant (especially when not not at expert level with a new API).
It's like "I don't care how many overloads are there, I just want a quick list to choose from, not 18 entries for arg()". Full completion doesn't meet this criteria.

> Additionally it could lead to other problems: For example, overloaded functions
> may return different types, and then the context type-matching cannot pick the
> correct one any more to highlight entries.

I don't think I understand this. By highlight you mean the yellow background that I get when I move the mouse over something? How is that tied to code completion? I thought it was a parser feature - I open a file and it does that, not depending on my choices which I may or may not have made in the past when typing that code.

If you mean that you somehow filter the function list by return type if I type:
int i = a.  // shows only the ones returning int
then I still don't see a problem - you can still filter them and then collapse the similar entries into one.

> Overall I agree, it would be good if the minimal completion would merge items
> with the same name at some point. But it's such a low benefit given the needed
> work that it probably won't happen any time soon.

Well, the work part I understand :)
I think the "low benefit" is a subjective thing though.
Comment 5 Olivier.jg 2010-12-19 08:28:30 UTC
*** Bug 215202 has been marked as a duplicate of this bug. ***
Comment 6 Miguel Angel Lopez 2025-05-17 18:56:51 UTC
Maybe a good way to deal with this could be having a multilevel menu.

First level shows method names without overloads and, if you select one with overloads another level is expanded with all the overloads of that method.