Commit c2eb4532 authored by Christian Kamm's avatar Christian Kamm
Browse files

QuickFixes: Sort by priority.



* Generally changes the BasicProposalItemListModel's sort to take the
  BasicProposalItem::order member into account.
* Currently only the QML completion and quick fixes set the order.
* This means the 'Apply signature changes' quick fix is now further up
  than the 'add definition' quick fix.

Change-Id: I7b5bc82aa37fca232fddd630ab3273437e1bcc09
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent dbc84d8c
......@@ -746,9 +746,8 @@ class ApplyDeclDefLinkOperation : public CppQuickFixOperation
public:
explicit ApplyDeclDefLinkOperation(
const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface,
const QSharedPointer<FunctionDeclDefLink> &link,
int priority = -1)
: CppQuickFixOperation(interface, priority)
const QSharedPointer<FunctionDeclDefLink> &link)
: CppQuickFixOperation(interface, 10)
, m_link(link)
{}
......@@ -780,7 +779,6 @@ QList<CppQuickFixOperation::Ptr> ApplyDeclDefLinkChanges::match(const QSharedPoi
QSharedPointer<ApplyDeclDefLinkOperation> op(new ApplyDeclDefLinkOperation(interface, link));
op->setDescription(FunctionDeclDefLink::tr("Apply function signature changes"));
op->setPriority(0);
results += op;
return results;
......
......@@ -55,11 +55,10 @@ class InsertDeclOperation: public CppQuickFixOperation
{
public:
InsertDeclOperation(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface,
int priority,
const QString &targetFileName, const Class *targetSymbol,
InsertionPointLocator::AccessSpec xsSpec,
const QString &decl)
: CppQuickFixOperation(interface, priority)
: CppQuickFixOperation(interface, 0)
, m_targetFileName(targetFileName)
, m_targetSymbol(targetSymbol)
, m_xsSpec(xsSpec)
......@@ -183,7 +182,7 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
method,
binding);
return singleResult(
new InsertDeclOperation(interface, idx, fn, matchingClass,
new InsertDeclOperation(interface, fn, matchingClass,
InsertionPointLocator::Public,
decl));
}
......@@ -216,9 +215,9 @@ namespace {
class InsertDefOperation: public CppQuickFixOperation
{
public:
InsertDefOperation(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface, int priority,
InsertDefOperation(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface,
Declaration *decl, const InsertionLocation &loc)
: CppQuickFixOperation(interface, priority)
: CppQuickFixOperation(interface, 0)
, m_decl(decl)
, m_loc(loc)
{
......@@ -304,7 +303,7 @@ QList<CppQuickFixOperation::Ptr> DefFromDecl::match(
QList<CppQuickFixOperation::Ptr> results;
foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) {
if (loc.isValid())
results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(interface, idx, decl, loc)));
results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(interface, decl, loc)));
}
return results;
}
......
......@@ -58,6 +58,10 @@ struct ContentLessThan
{
bool operator()(const BasicProposalItem *a, const BasicProposalItem *b)
{
// If order is different, show higher ones first.
if (a->order() != b->order())
return a->order() > b->order();
// The order is case-insensitive in principle, but case-sensitive when this
// would otherwise mean equality
const QString &lowera = a->text().toLower();
......
......@@ -58,33 +58,12 @@ IAssistProposal *QuickFixAssistProcessor::perform(const IAssistInterface *interf
QSharedPointer<const IAssistInterface> assistInterface(interface);
QList<QuickFixOperation::Ptr> quickFixes;
const QuickFixAssistProvider *quickFixProvider =
static_cast<const QuickFixAssistProvider *>(provider());
QMap<int, QList<QuickFixOperation::Ptr> > matchedOps;
foreach (QuickFixFactory *factory, quickFixProvider->quickFixFactories()) {
QList<QuickFixOperation::Ptr> ops = factory->matchingOperations(assistInterface);
foreach (QuickFixOperation::Ptr op, ops) {
const int priority = op->priority();
if (priority != -1)
matchedOps[priority].append(op);
}
}
QList<QuickFixOperation::Ptr> quickFixes;
// ### As the list of quick fixes grows, introduce some way of only showing relevant ones.
// The old priority-based way where the priority is the matching ast-node depth does not
// work well.
foreach (const QList<QuickFixOperation::Ptr> &fixes, matchedOps)
quickFixes += fixes;
#if 0
QMapIterator<int, QList<QuickFixOperation::Ptr> > it(matchedOps);
it.toBack();
if (it.hasPrevious()) {
it.previous();
quickFixes = it.value();
}
#endif
foreach (QuickFixFactory *factory, quickFixProvider->quickFixFactories())
quickFixes += factory->matchingOperations(assistInterface);
if (!quickFixes.isEmpty()) {
QList<BasicProposalItem *> items;
......@@ -94,6 +73,7 @@ IAssistProposal *QuickFixAssistProcessor::perform(const IAssistInterface *interf
BasicProposalItem *item = new BasicProposalItem;
item->setText(op->description());
item->setData(v);
item->setOrder(op->priority());
items.append(item);
}
return new GenericProposal(interface->position(), new BasicProposalItemListModel(items));
......
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