[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [KDevelop] 6f7a147: - Always cache the name of completion-items in the
From:       David nolden <david.nolden.kde () art-master ! de>
Date:       2010-11-27 20:58:12
Message-ID: 20101127205812.B1AFBA60A6 () git ! kde ! org
[Download RAW message or body]

commit 6f7a1478dd5dc7e1ea6f34cd0f2d782b19925e8c
branch master
Author: David nolden <david.nolden.kde@art-master.de>
Date:   Sat Nov 27 21:54:13 2010 +0100

    - Always cache the name of completion-items in the "alternativeText" member, so \
                at least the text can still properly be returned when the declaration \
                disappears.
    - When executing a completion item with a disappeared declaration, at least \
                insert the stored name.
    - Copy in about 40 lines of code from the kdevplatform base class. This split was \
non-logical and random (purely based on code similarity), and also lead to twice as \
many duchain locks as required for code completion. Now the base class function is \
not called any more from here.  BUG: 257740

diff --git a/languages/cpp/codecompletion/item.cpp \
b/languages/cpp/codecompletion/item.cpp index 2d2374b..6122d7b 100644
--- a/languages/cpp/codecompletion/item.cpp
+++ b/languages/cpp/codecompletion/item.cpp
@@ -113,7 +113,10 @@ void \
NormalDeclarationCompletionItem::execute(KTextEditor::Document* document, c  newText \
= m_declaration->identifier().toString();  } else {
       kDebug() << "Declaration disappeared";
-      return;
+      if(!alternativeText.isEmpty())
+        newText = alternativeText;
+      else
+        return;
     }
   }else{
     newText = alternativeText;
@@ -126,6 +129,10 @@ void \
NormalDeclarationCompletionItem::execute(KTextEditor::Document* document, c  bool \
jumpForbidden = false;  
   KDevelop::DUChainReadLocker lock(KDevelop::DUChain::lock());
+  
+  if(!m_declaration.data())
+    return;
+  
   Cpp::TemplateDeclaration* templateDecl = \
dynamic_cast<Cpp::TemplateDeclaration*>(m_declaration.data());  if(templateDecl) {
     DUContext* context = templateDecl->templateContext(m_declaration->topContext());
@@ -421,8 +428,42 @@ QVariant NormalDeclarationCompletionItem::data(const \
QModelIndex& index, int rol  }
             return QVariant();
           }
-          break;
+          if (m_declaration->abstractType()) {
+            if(EnumeratorType::Ptr enumerator = \
m_declaration->type<EnumeratorType>()) { +              \
if(m_declaration->context()->owner() && \
m_declaration->context()->owner()->abstractType()) { +                \
if(!m_declaration->context()->owner()->identifier().isEmpty()) +                  \
return shortenedTypeString(DeclarationPointer(m_declaration->context()->owner()), \
desiredTypeLength); +                else
+                  return "enum";
+              }
+            }
+            if (FunctionType::Ptr functionType = \
m_declaration->type<FunctionType>()) { +              ClassFunctionDeclaration* \
funDecl = dynamic_cast<ClassFunctionDeclaration*>(m_declaration.data()); +
+              if (functionType->returnType()) {
+                QString ret = shortenedTypeString(m_declaration, desiredTypeLength);
+                if(shortenArgumentHintReturnValues && argumentHintDepth() && \
ret.length() > maximumArgumentHintReturnValueLength) +                  return \
QString("..."); +                else
+                  return ret;
+              }else if(argumentHintDepth()) {
+                return QString();//Don't show useless prefixes in the argument-hints
+              }else if(funDecl && funDecl->isConstructor() )
+                return "<constructor>";
+              else if(funDecl && funDecl->isDestructor() )
+                return "<destructor>";
+              else
+                return "<incomplete type>";
+
+            } else {
+              return shortenedTypeString(m_declaration, desiredTypeLength);
+            }
+          } else {
+            return "<incomplete type>";
+          }
+          return QVariant();
         }
+        break;
         case CodeCompletionModel::Scope: {
           //The scopes are not needed
           return QVariant();
@@ -451,6 +492,20 @@ QVariant NormalDeclarationCompletionItem::data(const \
QModelIndex& index, int rol  return ret;
         }
         break;
+        case CodeCompletionModel::Name:
+        {
+          if(alternativeText.isEmpty())
+            alternativeText = declarationName();
+          return alternativeText;
+        }
+        case CodeCompletionModel::Postfix:
+        {
+            if (FunctionType::Ptr functionType = \
m_declaration->type<FunctionType>()) { +              // Retrieve const/volatile \
string +              return functionType->AbstractType::toString();
+            }
+            return QVariant();
+        }
       }
       break;
     case CodeCompletionModel::HighlightingMethod:
@@ -504,10 +559,27 @@ QVariant NormalDeclarationCompletionItem::data(const \
QModelIndex& index, int rol  }
       break;
     }
-  }
-  lock.unlock();
+    case CodeCompletionModel::BestMatchesCount:
+      return QVariant(normalBestMatchesCount);
+    break;
+    case CodeCompletionModel::IsExpandable:
+      return QVariant(createsExpandingWidget());
+    case CodeCompletionModel::ExpandingWidget: {
+      QWidget* nav = createExpandingWidget(model);
+      Q_ASSERT(nav);
+      model->addNavigationWidget(this, nav);
+
+      QVariant v;
+      v.setValue<QWidget*>(nav);
+      return v;
+    }
+    case CodeCompletionModel::ScopeIndex:
+      return static_cast<int>(reinterpret_cast<long>(m_declaration->context()));
 
-  return KDevelop::NormalDeclarationCompletionItem::data(index, role, model);
+    case CodeCompletionModel::CompletionRole:
+      return (int)completionProperties();
+  }
+  return QVariant();
 }
 
 void NormalDeclarationCompletionItem::needCachedArgumentList() const
diff --git a/languages/cpp/codecompletion/item.h \
b/languages/cpp/codecompletion/item.h index 08fda69..360e16e 100644
--- a/languages/cpp/codecompletion/item.h
+++ b/languages/cpp/codecompletion/item.h
@@ -70,7 +70,7 @@ public:
   
   bool completingTemplateParameters() const;
   
-  QString alternativeText; //Text shown when declaration is zero
+  mutable QString alternativeText; //Text shown when declaration is zero
   
   //If this is true, alternativeText will be shown in the list, and will be inserted \
on execution.  //Also the scope will be set to LocalScope when this attribute is \
true.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic