Bug 215206 - If there are too many overloads, KDevelop no longer shows which arguments are possible
Summary: If there are too many overloads, KDevelop no longer shows which arguments are...
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (old) (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR wishlist
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-19 00:03 UTC by Diederik van der Boor
Modified: 2010-05-15 13:54 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Diederik van der Boor 2009-11-19 00:03:48 UTC
Version:           3.9.96 (beta6) (using KDE 4.3.3)
Compiler:          gcc
OS:                Linux (i686) release 2.6.31.5-0.1-desktop
Installed from:    openSUSE RPMs

If there are many overloads of a method, e.g. QString::append() KDevelop no longer shows which options are possible.

When pressing Ctrl+Space, KDevelop will show "6 overloads of append". I'd really like to see which overloads exist, or at least the first 10-15 possible options. 

Showing "6 overloads of append" is imho a bug, because you ask explicitly for the possible suggestions.
Comment 1 David Nolden 2009-11-19 00:28:34 UTC
That's a feature, not a bug. It did show all the overloads before, but in some cases it ment that you have your whole screen full of overloads, which was extremely annoying when you're not interested in the argument-hints but just in the completions.

Although I think that it was mainly problematic with _automatic_ completion, so it might make sense treating it differently in the CTRL+Space case.
Comment 2 Andreas Pakulat 2009-11-19 00:57:36 UTC
Yeah, I think for manual argument hints via ctrl+space we should always show them. Additionally I think 5 (or whatever the limit is now) is too small, it should at least be 7 or 8.
Comment 3 Diederik van der Boor 2009-11-26 23:45:29 UTC
Thanks for the support!

If there are too many overloads, could you at least show a few? (and with "x more overloads...")
Comment 4 David Nolden 2010-05-15 13:54:13 UTC
commit 056b8ac022b11a0db548d55a99d8e04f8841f37c
Author: David nolden <david.nolden.kde@art-master.de>
Date:   Sat May 15 13:50:43 2010 +0200

    Allow the user to get more argument-hints by executing the "X more overloads of Y" completion item, and increase the default number of shown overloads to 8.
    BUG: 215206

diff --git a/languages/cpp/codecompletion/context.cpp b/languages/cpp/codecompletion/context.cpp
index 79ed5f0..a0dc08e 100644
--- a/languages/cpp/codecompletion/context.cpp
+++ b/languages/cpp/codecompletion/context.cpp
@@ -95,13 +95,6 @@ QStringList arithmeticComparisonOperators = QString("!= <= >= < >" ).split( ' ',
 
 QStringList allOperators = QString("++ + -- += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= && || [ - * / % & | = < >" ).split( ' ', QString::SkipEmptyParts );
 
-
-
-//Whether the list of argument-hints should contain all overloaded versions of operators.
-//Disabled for now, because there is usually a huge list of overloaded operators.
-const int maxOverloadedOperatorArgumentHints = 5;
-const int maxOverloadedArgumentHints = 20;
-
 //Whether identifiers starting with "__" or "_Uppercase" and that are not declared in the current file should be excluded from the code completion
 const bool excludeReservedIdentifiers = true;
 
@@ -1269,6 +1262,8 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::completionItems(bool& sh
           {
             ifDebug( kDebug() << "functionCallAccess" << functions().count() << m_expression; )
             
+            uint max = MoreArgumentHintsCompletionItem::resetMaxArgumentHints();
+            
             //Don't show annoying empty argument-hints
 /*            if(parentContext->m_contextType != BinaryOperatorFunctionCall && parentContext->functions().size() == 0)
               break;*/
@@ -1277,10 +1272,9 @@ QList<CompletionTreeItemPointer> CodeCompletionContext::completionItems(bool& sh
             }else if(!functions().isEmpty()) {
               int num = 0;
               foreach( const Cpp::CodeCompletionContext::Function &function, functions() ) {
-                if (num == maxOverloadedOperatorArgumentHints) {
+                if (num == max) {
                   //When there are too many overloaded functions, do not show them all if completion was invoked automatically
-                  CompletionTreeItemPointer item( new NormalDeclarationCompletionItem( KDevelop::DeclarationPointer(),  KSharedPtr <KDevelop::CodeCompletionContext >(this), 0, 0 ) );
-                  item->asItem<NormalDeclarationCompletionItem>()->alternativeText = i18ncp("Here, overload is used as a programming term.  This string is used to display how many overloaded versions there are of the function whose name is the second argument.", "1 more overload of %2", "%1 more overloads of %2", functions().count() - num, functionName());
+                  CompletionTreeItemPointer item( new MoreArgumentHintsCompletionItem( KSharedPtr <KDevelop::CodeCompletionContext >(this), i18ncp("Here, overload is used as a programming term.  This string is used to display how many overloaded versions there are of the function whose name is the second argument.", "1 more overload of %2 (show more)", "%1 more overloads of %2 (show more)", functions().count() - num, functionName()), num ) );
                   items << item;
                   break;
                 }
diff --git a/languages/cpp/codecompletion/item.cpp b/languages/cpp/codecompletion/item.cpp
index fc18de1..6c6966b 100644
--- a/languages/cpp/codecompletion/item.cpp
+++ b/languages/cpp/codecompletion/item.cpp
@@ -41,6 +41,7 @@
 #include <templatedeclaration.h>
 #include <language/codecompletion/codecompletionhelper.h>
 #include "context.h"
+#include <ktexteditor/codecompletioninterface.h>
 
 using namespace KDevelop;
 
@@ -634,4 +635,34 @@ int TypeConversionCompletionItem::argumentHintDepth() const {
 TypeConversionCompletionItem::TypeConversionCompletionItem(QString text, KDevelop::IndexedType type, int argumentHintDepth, KSharedPtr<Cpp::CodeCompletionContext> _completionContext) : m_text(text), m_type(type), m_argumentHintDepth(argumentHintDepth), completionContext(_completionContext) {
 }
 
+MoreArgumentHintsCompletionItem::MoreArgumentHintsCompletionItem(KSharedPtr< KDevelop::CodeCompletionContext > context, QString text, uint oldNumber) : NormalDeclarationCompletionItem(DeclarationPointer(), context) {
+  alternativeText = text;
+  m_oldNumber = oldNumber;
+}
+
+namespace {
+  const uint defaultMaxArgumentHints = 8;
+  const uint maxArgumentHintsExtensionSteps = 20;
+  uint currentMaxArgumentHints = defaultMaxArgumentHints;
+};
+
+uint MoreArgumentHintsCompletionItem::resetMaxArgumentHints()
+{
+  uint ret = currentMaxArgumentHints;
+  currentMaxArgumentHints = defaultMaxArgumentHints;
+  return ret;
+}
+
+void MoreArgumentHintsCompletionItem::execute(KTextEditor::Document* document, const KTextEditor::Range& word)
+{
+  currentMaxArgumentHints = m_oldNumber + maxArgumentHintsExtensionSteps;
+  
+  // Restart code-completion
+  KTextEditor::CodeCompletionInterface* iface = dynamic_cast<KTextEditor::CodeCompletionInterface*>(document->activeView());
+  Q_ASSERT(iface);
+  iface->abortCompletion();
+    ///@todo 1. This is a non-public interface, and 2. Completion should be started in "automatic invocation" mode
+  QMetaObject::invokeMethod(document->activeView(), "userInvokedCompletion", Qt::QueuedConnection);
+}
+
 }
diff --git a/languages/cpp/codecompletion/item.h b/languages/cpp/codecompletion/item.h
index 0bd2a36..08fda69 100644
--- a/languages/cpp/codecompletion/item.h
+++ b/languages/cpp/codecompletion/item.h
@@ -103,6 +103,23 @@ private:
   mutable KSharedPtr<CachedArgumentList> m_cachedArgumentList;
 };
 
+// Helper-item that manages the number of shown argument-hints
+// When the user selects the item, the item stores an increased maximum in resetMaxArgumentHints()
+// The number is reset after resetMaxArgumentHints() was called the next time.
+class MoreArgumentHintsCompletionItem : public NormalDeclarationCompletionItem {
+public:
+  MoreArgumentHintsCompletionItem(KSharedPtr<KDevelop::CodeCompletionContext> context, QString text, uint oldNumber);
+  
+  virtual void execute(KTextEditor::Document* document, const KTextEditor::Range& word);
+  
+  // Maximum number of argument-hints that should be shown by code completion
+  // Whenever this is called, the maximum number of arguments is reset afterwards,
+  // so make sure you call it only once in the correct place.
+  static uint resetMaxArgumentHints();
+private:
+  uint m_oldNumber;
+};
+
 typedef KDevelop::AbstractIncludeFileCompletionItem<Cpp::NavigationWidget> BaseIncludeFileCompletionItem;
 
 class IncludeFileCompletionItem : public BaseIncludeFileCompletionItem {