forked from qt-creator/qt-creator
Always remove the duplicates from the completion, even when the items are not sorted.
This commit is contained in:
@@ -82,10 +82,6 @@ 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 {
|
||||||
@@ -660,7 +656,10 @@ 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)
|
if (m_completionOperator != T_EOF_SYMBOL)
|
||||||
qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
|
qSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
|
||||||
|
|
||||||
|
// always remove duplicates
|
||||||
|
m_completions = removeDuplicates(m_completions);
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@@ -1590,45 +1589,36 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions()
|
QList<TextEditor::CompletionItem> CppCodeCompletion::removeDuplicates(const QList<TextEditor::CompletionItem> &items)
|
||||||
{
|
{
|
||||||
QList<TextEditor::CompletionItem> 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;
|
|
||||||
QList<TextEditor::CompletionItem> uniquelist;
|
QList<TextEditor::CompletionItem> uniquelist;
|
||||||
|
QSet<QString> processed;
|
||||||
|
|
||||||
foreach (const TextEditor::CompletionItem &item, completionItems) {
|
foreach (const TextEditor::CompletionItem &item, items) {
|
||||||
if (item.text != lastKey) {
|
if (! processed.contains(item.text)) {
|
||||||
|
processed.insert(item.text);
|
||||||
uniquelist.append(item);
|
uniquelist.append(item);
|
||||||
lastKey = item.text;
|
if (Symbol *symbol = qvariant_cast<Symbol *>(item.data)) {
|
||||||
} else {
|
if (Function *funTy = symbol->type()->asFunctionType()) {
|
||||||
TextEditor::CompletionItem &lastItem = uniquelist.last();
|
if (funTy->hasArguments())
|
||||||
Symbol *symbol = qvariant_cast<Symbol *>(item.data);
|
++uniquelist.back().duplicateCount;
|
||||||
Symbol *lastSymbol = qvariant_cast<Symbol *>(lastItem.data);
|
|
||||||
|
|
||||||
if (symbol && lastSymbol) {
|
|
||||||
Function *funTy = symbol->type()->asFunctionType();
|
|
||||||
Function *lastFunTy = lastSymbol->type()->asFunctionType();
|
|
||||||
if (funTy && lastFunTy) {
|
|
||||||
if (funTy->argumentCount() == lastFunTy->argumentCount())
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++lastItem.duplicateCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return uniquelist;
|
return uniquelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions()
|
||||||
|
{
|
||||||
|
QList<TextEditor::CompletionItem> completionItems;
|
||||||
|
completions(&completionItems);
|
||||||
|
|
||||||
|
return completionItems;
|
||||||
|
}
|
||||||
|
|
||||||
void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
|
void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
|
||||||
{
|
{
|
||||||
Symbol *symbol = 0;
|
Symbol *symbol = 0;
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ private:
|
|||||||
const QString &expression,
|
const QString &expression,
|
||||||
int endOfExpression);
|
int endOfExpression);
|
||||||
|
|
||||||
|
QList<TextEditor::CompletionItem> removeDuplicates(const QList<TextEditor::CompletionItem> &items);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool objcKeywordsWanted() const;
|
bool objcKeywordsWanted() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user