Commit eb5afed1 authored by Marco Bubke's avatar Marco Bubke
Browse files

Clang: Add sorting by priority



The priority is adjusted too provide a better completion list.

Change-Id: I1ebed1996f660046843e0c5249a91e8c2b1eeb88
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent dd89d731
......@@ -32,6 +32,10 @@
#include "clangassistproposalmodel.h"
#include <texteditor/codeassist/assistproposalitem.h>
#include <algorithm>
namespace ClangCodeModel {
namespace Internal {
......@@ -56,6 +60,19 @@ bool ClangAssistProposalModel::isSortable(const QString &/*prefix*/) const
return true;
}
void ClangAssistProposalModel::sort(const QString &/*prefix*/)
{
using TextEditor::AssistProposalItem;
auto currentItemsCompare = [](AssistProposalItem *first, AssistProposalItem *second) {
return (first->order() > 0
&& (first->order() < second->order()
|| (first->order() == second->order() && first->text() < second->text())));
};
std::sort(m_currentItems.begin(), m_currentItems.end(), currentItemsCompare);
}
} // namespace Internal
} // namespace ClangCodeModel
......@@ -48,6 +48,7 @@ public:
{}
bool isSortable(const QString &prefix) const override;
void sort(const QString &prefix) override;
static bool replaceDotForArrow(IAssistProposalModel *model);
......
......@@ -64,6 +64,7 @@ bool CodeCompletionsExtractor::next()
extractAvailability();
extractHasParameters();
extractCompletionChunks();
adaptPriority();
return true;
}
......@@ -251,6 +252,48 @@ void CodeCompletionsExtractor::extractCompletionChunks()
currentCodeCompletion_.setChunks(CodeCompletionChunkConverter::extract(currentCxCodeCompleteResult.CompletionString));
}
void CodeCompletionsExtractor::adaptPriority()
{
decreasePriorityForDestructors();
decreasePriorityForNonAvailableCompletions();
decreasePriorityForQObjectInternals();
decreasePriorityForSignals();
}
void CodeCompletionsExtractor::decreasePriorityForNonAvailableCompletions()
{
if (currentCodeCompletion_.availability() != CodeCompletion::Available)
currentCodeCompletion_.setPriority(currentCodeCompletion_.priority() * 100);
}
void CodeCompletionsExtractor::decreasePriorityForDestructors()
{
if (currentCodeCompletion_.completionKind() == CodeCompletion::DestructorCompletionKind)
currentCodeCompletion_.setPriority(currentCodeCompletion_.priority() * 100);
}
void CodeCompletionsExtractor::decreasePriorityForSignals()
{
if (currentCodeCompletion_.completionKind() == CodeCompletion::SignalCompletionKind)
currentCodeCompletion_.setPriority(currentCodeCompletion_.priority() * 100);
}
void CodeCompletionsExtractor::decreasePriorityForQObjectInternals()
{
quint32 priority = currentCodeCompletion_.priority();
if (currentCodeCompletion_.text().startsWith("qt_"))
priority *= 100;
if (currentCodeCompletion_.text() == Utf8StringLiteral("metaObject"))
priority *= 10;
if (currentCodeCompletion_.text() == Utf8StringLiteral("staticMetaObject"))
priority *= 100;
currentCodeCompletion_.setPriority(priority);
}
bool CodeCompletionsExtractor::hasText(const Utf8String &text, CXCompletionString cxCompletionString) const
{
const uint completionChunkCount = clang_getNumCompletionChunks(cxCompletionString);
......
......@@ -67,6 +67,12 @@ private:
void extractHasParameters();
void extractCompletionChunks();
void adaptPriority();
void decreasePriorityForNonAvailableCompletions();
void decreasePriorityForDestructors();
void decreasePriorityForSignals();
void decreasePriorityForQObjectInternals();
bool hasText(const Utf8String &text, CXCompletionString cxCompletionString) const;
private:
......
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