Commit cac3bd17 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Sort _ at the end for the code completion

The _ is usually used to prefix internal and/or private methods and
members. Having those turn up at the top of the list of suggestions for
completion isn't too useful. Improves the autocompletion for example for
the STL.

Done together with Roberto Raggi.
parent d0725e31
......@@ -42,6 +42,8 @@
#include <QString>
#include <QList>
#include <algorithm>
using namespace TextEditor;
using namespace TextEditor::Internal;
......@@ -143,11 +145,32 @@ void CompletionSupport::autoComplete(ITextEditable *editor, bool forced)
static bool compareChar(const QChar &l, const QChar &r)
if (l == QLatin1Char('_'))
return false;
else if (r == QLatin1Char('_'))
return true;
return l < r;
static bool lessThan(const QString &l, const QString &r)
return std::lexicographical_compare(l.begin(), l.end(),
r.begin(), r.end(),
static bool completionItemLessThan(const CompletionItem &i1, const CompletionItem &i2)
// The order is case-insensitive in principle, but case-sensitive when this would otherwise mean equality
const int c =, Qt::CaseInsensitive);
return c ? c < 0 : i1.m_text < i2.m_text;
const QString lower1 = i1.m_text.toLower();
const QString lower2 = i2.m_text.toLower();
if (lower1 == lower2)
return lessThan(i1.m_text, i2.m_text);
return lessThan(lower1, lower2);
QList<CompletionItem> CompletionSupport::getCompletions() const
Supports Markdown
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