forked from qt-creator/qt-creator
Speedup global completion.
Don't sort the global completion items when we have too many of them, instead populate the completion box in a way where local symbols are showed before global symbols.
This commit is contained in:
@@ -82,6 +82,10 @@ namespace {
|
|||||||
const bool debug = ! qgetenv("CPLUSPLUS_DEBUG").isEmpty();
|
const bool debug = ! qgetenv("CPLUSPLUS_DEBUG").isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MAX_COMPLETION_ITEM = 1000
|
||||||
|
};
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
@@ -654,8 +658,10 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
|
|||||||
int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||||
{
|
{
|
||||||
int index = startCompletionHelper(editor);
|
int index = startCompletionHelper(editor);
|
||||||
if (index != -1)
|
if (index != -1) {
|
||||||
|
if (m_completionOperator != T_EOF_SYMBOL)
|
||||||
qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
|
qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
|
||||||
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,9 +897,6 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addKeywords();
|
|
||||||
addMacros(context.thisDocument()->fileName(), context.snapshot());
|
|
||||||
|
|
||||||
QList<ClassOrNamespace *> usingBindings;
|
QList<ClassOrNamespace *> usingBindings;
|
||||||
ClassOrNamespace *currentBinding = 0;
|
ClassOrNamespace *currentBinding = 0;
|
||||||
|
|
||||||
@@ -916,20 +919,6 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; currentBinding; currentBinding = currentBinding->parent()) {
|
|
||||||
const QList<Symbol *> symbols = currentBinding->symbols();
|
|
||||||
|
|
||||||
if (! symbols.isEmpty()) {
|
|
||||||
if (symbols.first()->isNamespace())
|
|
||||||
completeNamespace(currentBinding);
|
|
||||||
else
|
|
||||||
completeClass(currentBinding, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (ClassOrNamespace *b, usingBindings)
|
|
||||||
completeNamespace(b);
|
|
||||||
|
|
||||||
for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) {
|
for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) {
|
||||||
if (scope->isBlockScope()) {
|
if (scope->isBlockScope()) {
|
||||||
for (unsigned i = 0; i < scope->symbolCount(); ++i) {
|
for (unsigned i = 0; i < scope->symbolCount(); ++i) {
|
||||||
@@ -945,6 +934,23 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (; currentBinding; currentBinding = currentBinding->parent()) {
|
||||||
|
const QList<Symbol *> symbols = currentBinding->symbols();
|
||||||
|
|
||||||
|
if (! symbols.isEmpty()) {
|
||||||
|
if (symbols.first()->isNamespace())
|
||||||
|
completeNamespace(currentBinding);
|
||||||
|
else
|
||||||
|
completeClass(currentBinding, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ClassOrNamespace *b, usingBindings)
|
||||||
|
completeNamespace(b);
|
||||||
|
|
||||||
|
addKeywords();
|
||||||
|
addMacros(context.thisDocument()->fileName(), context.snapshot());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &results,
|
bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &results,
|
||||||
@@ -1590,6 +1596,10 @@ QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions()
|
|||||||
|
|
||||||
completions(&completionItems);
|
completions(&completionItems);
|
||||||
|
|
||||||
|
if (m_completionOperator == T_EOF_SYMBOL && completionItems.size() < MAX_COMPLETION_ITEM) {
|
||||||
|
qStableSort(completionItems.begin(), completionItems.end(), completionItemLessThan);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove duplicates
|
// Remove duplicates
|
||||||
QString lastKey;
|
QString lastKey;
|
||||||
QList<TextEditor::CompletionItem> uniquelist;
|
QList<TextEditor::CompletionItem> uniquelist;
|
||||||
|
|||||||
Reference in New Issue
Block a user