Commit 9d5705a7 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Stop trying to remove duplicate completion items

We assume that libclang does not return any duplicates, at least we
never noticed any so far. For the concrete test below no duplicates were
removed.

Function overloads are not problematic because they are folded into one
ClangAssistProposalItem (addOverload()).

To the completion items from libclang we add the Qt Creator snippets as
items. Those might have the same text in the completion list view, but
their icon is different (e.g. consider the keyword completion "class"
and the Qt Creator snippet "class"), thus the user can still tell them
apart.

Test:
 1. Open src/plugins/clangstaticanalyzer/unit-tests/qt-essential-includes.pro
 2. Open main.cpp
 3. Complete in the main function

Measured with a timer in IpcReceiver::codeCompleted.

On Linux, for 20637 completion items:
 Before: 74ms (avg)
    Now: 66ms (avg)
   Gain: 11%

Change-Id: I524eaa09f8d9e07c78dc9efcc77f7e021c6f37f7
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent ead6853b
......@@ -40,6 +40,11 @@ ClangAssistProposalModel::ClangAssistProposalModel(
{
}
bool ClangAssistProposalModel::containsDuplicates() const
{
return false;
}
bool ClangAssistProposalModel::isSortable(const QString &/*prefix*/) const
{
return true;
......
......@@ -39,6 +39,8 @@ class ClangAssistProposalModel : public TextEditor::GenericProposalModel
public:
ClangAssistProposalModel(ClangBackEnd::CompletionCorrection neededCorrection);
bool containsDuplicates() const override;
bool isSortable(const QString &prefix) const override;
void sort(const QString &prefix) override;
......
......@@ -170,7 +170,6 @@ QString GenericProposalModel::detail(int index) const
return m_currentItems.at(index)->detail();
}
// make it optional because it is not needed in many cases
void GenericProposalModel::removeDuplicates()
{
QHash<QString, quint64> unique;
......@@ -272,6 +271,11 @@ int GenericProposalModel::persistentId(int index) const
return m_idByText.value(m_currentItems.at(index)->text());
}
bool GenericProposalModel::containsDuplicates() const
{
return true;
}
bool GenericProposalModel::supportsPrefixExpansion() const
{
return true;
......
......@@ -53,6 +53,7 @@ public:
virtual QIcon icon(int index) const;
virtual QString detail(int index) const;
virtual int persistentId(int index) const;
virtual bool containsDuplicates() const;
virtual void removeDuplicates();
virtual void filter(const QString &prefix);
virtual bool isSortable(const QString &prefix) const;
......
......@@ -407,7 +407,8 @@ void GenericProposalWidget::setIsSynchronized(bool isSync)
void GenericProposalWidget::showProposal(const QString &prefix)
{
ensurePolished();
d->m_model->removeDuplicates();
if (d->m_model->containsDuplicates())
d->m_model->removeDuplicates();
if (!updateAndCheck(prefix))
return;
show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment