forked from qt-creator/qt-creator
		
	Sort the items lazily.
This commit is contained in:
		@@ -69,6 +69,7 @@
 | 
			
		||||
#include <QtCore/QDebug>
 | 
			
		||||
#include <QtCore/QMap>
 | 
			
		||||
#include <QtCore/QFile>
 | 
			
		||||
#include <QtCore/QtConcurrentRun>
 | 
			
		||||
#include <QtGui/QAction>
 | 
			
		||||
#include <QtGui/QApplication>
 | 
			
		||||
#include <QtGui/QDesktopWidget>
 | 
			
		||||
@@ -652,11 +653,22 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static QList<TextEditor::CompletionItem> sortCompletionItems(QList<TextEditor::CompletionItem> items)
 | 
			
		||||
{
 | 
			
		||||
    qStableSort(items.begin(), items.end(), CppCodeCompletion::completionItemLessThan);
 | 
			
		||||
    return items;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
 | 
			
		||||
{
 | 
			
		||||
    int index = startCompletionHelper(editor);
 | 
			
		||||
    if (index != -1)
 | 
			
		||||
        qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
 | 
			
		||||
    if (index != -1) {
 | 
			
		||||
        m_sortedCompletions = QtConcurrent::run(sortCompletionItems, m_completions);
 | 
			
		||||
 | 
			
		||||
        if (m_completions.size() < 1000)
 | 
			
		||||
            m_completions = m_sortedCompletions;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return index;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1568,8 +1580,14 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
 | 
			
		||||
 | 
			
		||||
    const QString key = m_editor->textAt(m_startPosition, length);
 | 
			
		||||
 | 
			
		||||
    QList<TextEditor::CompletionItem> currentCompletion;
 | 
			
		||||
    if (m_sortedCompletions.isFinished())
 | 
			
		||||
        currentCompletion = m_sortedCompletions;
 | 
			
		||||
    else
 | 
			
		||||
        currentCompletion = m_completions;
 | 
			
		||||
 | 
			
		||||
    if (length == 0)
 | 
			
		||||
        *completions = m_completions;
 | 
			
		||||
        *completions = currentCompletion;
 | 
			
		||||
    else if (length > 0) {
 | 
			
		||||
        /* Close on the trailing slash for include completion, to enable the slash to
 | 
			
		||||
         * trigger a new completion list. */
 | 
			
		||||
@@ -1578,12 +1596,12 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        if (m_completionOperator != T_LPAREN) {
 | 
			
		||||
            filter(m_completions, completions, key);
 | 
			
		||||
            filter(currentCompletion, completions, key);
 | 
			
		||||
 | 
			
		||||
        } else if (m_completionOperator == T_LPAREN ||
 | 
			
		||||
                   m_completionOperator == T_SIGNAL ||
 | 
			
		||||
                   m_completionOperator == T_SLOT) {
 | 
			
		||||
            foreach (const TextEditor::CompletionItem &item, m_completions) {
 | 
			
		||||
            foreach (const TextEditor::CompletionItem &item, currentCompletion) {
 | 
			
		||||
                if (item.text.startsWith(key, Qt::CaseInsensitive)) {
 | 
			
		||||
                    completions->append(item);
 | 
			
		||||
                }
 | 
			
		||||
@@ -1742,6 +1760,7 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem
 | 
			
		||||
 | 
			
		||||
void CppCodeCompletion::cleanup()
 | 
			
		||||
{
 | 
			
		||||
    m_sortedCompletions.cancel();
 | 
			
		||||
    m_completions.clear();
 | 
			
		||||
 | 
			
		||||
    // Set empty map in order to avoid referencing old versions of the documents
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,7 @@
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QObject>
 | 
			
		||||
#include <QtCore/QPointer>
 | 
			
		||||
#include <QtCore/QFuture>
 | 
			
		||||
 | 
			
		||||
QT_BEGIN_NAMESPACE
 | 
			
		||||
class QTextCursor;
 | 
			
		||||
@@ -149,6 +150,7 @@ private:
 | 
			
		||||
    QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
 | 
			
		||||
 | 
			
		||||
    QList<TextEditor::CompletionItem> m_completions;
 | 
			
		||||
    QFuture<QList<TextEditor::CompletionItem> > m_sortedCompletions;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace Internal
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user