forked from qt-creator/qt-creator
Clang: change global completions order
Give CamelCase completions lower priority Task-number: QTCREATORBUG-18319 Change-Id: I812d22616e8ab0e3d186bcf7a6a569de22be2a07 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
const int SORT_LIMIT = 30000;
|
||||
constexpr int SORT_LIMIT = 30000;
|
||||
|
||||
ClangAssistProposalModel::ClangAssistProposalModel(
|
||||
ClangBackEnd::CompletionCorrection neededCorrection)
|
||||
@@ -58,6 +58,10 @@ void ClangAssistProposalModel::sort(const QString &/*prefix*/)
|
||||
|
||||
auto currentItemsCompare = [](AssistProposalItemInterface *first,
|
||||
AssistProposalItemInterface *second) {
|
||||
if (first->prefixMatch() != second->prefixMatch()) {
|
||||
return static_cast<int>(first->prefixMatch())
|
||||
< static_cast<int>(second->prefixMatch());
|
||||
}
|
||||
return (first->order() > 0
|
||||
&& (first->order() < second->order()
|
||||
|| (first->order() == second->order() && first->text() < second->text())));
|
||||
|
||||
@@ -44,6 +44,14 @@ class TextEditorWidget;
|
||||
class TEXTEDITOR_EXPORT AssistProposalItemInterface
|
||||
{
|
||||
public:
|
||||
// We compare proposals by enum values, be careful changing their values
|
||||
enum class PrefixMatch
|
||||
{
|
||||
Exact = 0,
|
||||
Lower = 1,
|
||||
None = 2
|
||||
};
|
||||
|
||||
AssistProposalItemInterface() = default;
|
||||
virtual ~AssistProposalItemInterface() Q_DECL_NOEXCEPT = default;
|
||||
|
||||
@@ -59,11 +67,14 @@ public:
|
||||
virtual bool isValid() const = 0;
|
||||
virtual quint64 hash() const = 0; // it is only for removing duplicates
|
||||
|
||||
int order() const { return m_order; }
|
||||
void setOrder(int order) { m_order = order; }
|
||||
inline int order() const { return m_order; }
|
||||
inline void setOrder(int order) { m_order = order; }
|
||||
inline PrefixMatch prefixMatch() { return m_prefixMatch; }
|
||||
inline void setPrefixMatch(PrefixMatch match) { m_prefixMatch = match; }
|
||||
|
||||
private:
|
||||
int m_order = 0;
|
||||
PrefixMatch m_prefixMatch = PrefixMatch::None;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
@@ -45,8 +45,8 @@ uint qHash(const AssistProposalItem &item)
|
||||
|
||||
namespace {
|
||||
|
||||
const int kMaxSort = 1000;
|
||||
const int kMaxPrefixFilter = 100;
|
||||
constexpr int kMaxSort = 1000;
|
||||
constexpr int kMaxPrefixFilter = 100;
|
||||
|
||||
struct ContentLessThan
|
||||
{
|
||||
@@ -309,9 +309,20 @@ void GenericProposalModel::filter(const QString &prefix)
|
||||
QRegExp regExp(keyRegExp);
|
||||
|
||||
m_currentItems.clear();
|
||||
const QString lowerPrefix = prefix.toLower();
|
||||
foreach (const auto &item, m_originalItems) {
|
||||
if (regExp.indexIn(item->text()) == 0)
|
||||
const QString &text = item->text();
|
||||
if (regExp.indexIn(text) == 0) {
|
||||
m_currentItems.append(item);
|
||||
if (text.startsWith(prefix)) {
|
||||
// Direct match
|
||||
item->setPrefixMatch(AssistProposalItemInterface::PrefixMatch::Exact);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (text.startsWith(lowerPrefix, Qt::CaseInsensitive))
|
||||
item->setPrefixMatch(AssistProposalItemInterface::PrefixMatch::Lower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user