forked from qt-creator/qt-creator
Clang: Add sorting by priority
The priority is adjusted too provide a better completion list. Change-Id: I1ebed1996f660046843e0c5249a91e8c2b1eeb88 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user