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 ClangCodeModel {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
const int SORT_LIMIT = 30000;
|
constexpr int SORT_LIMIT = 30000;
|
||||||
|
|
||||||
ClangAssistProposalModel::ClangAssistProposalModel(
|
ClangAssistProposalModel::ClangAssistProposalModel(
|
||||||
ClangBackEnd::CompletionCorrection neededCorrection)
|
ClangBackEnd::CompletionCorrection neededCorrection)
|
||||||
@@ -58,9 +58,13 @@ void ClangAssistProposalModel::sort(const QString &/*prefix*/)
|
|||||||
|
|
||||||
auto currentItemsCompare = [](AssistProposalItemInterface *first,
|
auto currentItemsCompare = [](AssistProposalItemInterface *first,
|
||||||
AssistProposalItemInterface *second) {
|
AssistProposalItemInterface *second) {
|
||||||
|
if (first->prefixMatch() != second->prefixMatch()) {
|
||||||
|
return static_cast<int>(first->prefixMatch())
|
||||||
|
< static_cast<int>(second->prefixMatch());
|
||||||
|
}
|
||||||
return (first->order() > 0
|
return (first->order() > 0
|
||||||
&& (first->order() < second->order()
|
&& (first->order() < second->order()
|
||||||
|| (first->order() == second->order() && first->text() < second->text())));
|
|| (first->order() == second->order() && first->text() < second->text())));
|
||||||
};
|
};
|
||||||
|
|
||||||
std::sort(m_currentItems.begin(), m_currentItems.end(), currentItemsCompare);
|
std::sort(m_currentItems.begin(), m_currentItems.end(), currentItemsCompare);
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ class TextEditorWidget;
|
|||||||
class TEXTEDITOR_EXPORT AssistProposalItemInterface
|
class TEXTEDITOR_EXPORT AssistProposalItemInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// We compare proposals by enum values, be careful changing their values
|
||||||
|
enum class PrefixMatch
|
||||||
|
{
|
||||||
|
Exact = 0,
|
||||||
|
Lower = 1,
|
||||||
|
None = 2
|
||||||
|
};
|
||||||
|
|
||||||
AssistProposalItemInterface() = default;
|
AssistProposalItemInterface() = default;
|
||||||
virtual ~AssistProposalItemInterface() Q_DECL_NOEXCEPT = default;
|
virtual ~AssistProposalItemInterface() Q_DECL_NOEXCEPT = default;
|
||||||
|
|
||||||
@@ -59,11 +67,14 @@ public:
|
|||||||
virtual bool isValid() const = 0;
|
virtual bool isValid() const = 0;
|
||||||
virtual quint64 hash() const = 0; // it is only for removing duplicates
|
virtual quint64 hash() const = 0; // it is only for removing duplicates
|
||||||
|
|
||||||
int order() const { return m_order; }
|
inline int order() const { return m_order; }
|
||||||
void setOrder(int order) { m_order = order; }
|
inline void setOrder(int order) { m_order = order; }
|
||||||
|
inline PrefixMatch prefixMatch() { return m_prefixMatch; }
|
||||||
|
inline void setPrefixMatch(PrefixMatch match) { m_prefixMatch = match; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_order = 0;
|
int m_order = 0;
|
||||||
|
PrefixMatch m_prefixMatch = PrefixMatch::None;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ uint qHash(const AssistProposalItem &item)
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const int kMaxSort = 1000;
|
constexpr int kMaxSort = 1000;
|
||||||
const int kMaxPrefixFilter = 100;
|
constexpr int kMaxPrefixFilter = 100;
|
||||||
|
|
||||||
struct ContentLessThan
|
struct ContentLessThan
|
||||||
{
|
{
|
||||||
@@ -309,9 +309,20 @@ void GenericProposalModel::filter(const QString &prefix)
|
|||||||
QRegExp regExp(keyRegExp);
|
QRegExp regExp(keyRegExp);
|
||||||
|
|
||||||
m_currentItems.clear();
|
m_currentItems.clear();
|
||||||
|
const QString lowerPrefix = prefix.toLower();
|
||||||
foreach (const auto &item, m_originalItems) {
|
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);
|
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