MCPcopy Create free account
hub / github.com/KDE/kdevelop / findProblemsCloseToCursor

Function findProblemsCloseToCursor

plugins/contextbrowser/contextbrowser.cpp:481–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479}
480
481static QVector<KDevelop::IProblem::Ptr> findProblemsCloseToCursor(const TopDUContext* topContext,
482 KTextEditor::Cursor position,
483 KTextEditor::Range& handleRange)
484{
485 handleRange = KTextEditor::Range::invalid();
486
487 QVector<KDevelop::IProblem::Ptr> allProblems;
488 const auto modelsData = ICore::self()->languageController()->problemModelSet()->models();
489 for (const auto& modelData : modelsData) {
490 const auto problems = modelData.model->problems(topContext->url());
491 allProblems.reserve(allProblems.size() + problems.size());
492 for (const auto& problem : problems) {
493 allProblems += problem;
494 }
495 }
496
497 if (allProblems.isEmpty())
498 return allProblems;
499
500 std::sort(allProblems.begin(), allProblems.end(),
501 [position](const KDevelop::IProblem::Ptr& a, const KDevelop::IProblem::Ptr& b) {
502 const auto aRange = a->finalLocation();
503 const auto bRange = b->finalLocation();
504
505 const auto aLineDistance = qMin(qAbs(aRange.start().line() - position.line()),
506 qAbs(aRange.end().line() - position.line()));
507 const auto bLineDistance = qMin(qAbs(bRange.start().line() - position.line()),
508 qAbs(bRange.end().line() - position.line()));
509 if (aLineDistance != bLineDistance) {
510 return aLineDistance < bLineDistance;
511 }
512
513 if (aRange.start().line() == bRange.start().line()) {
514 return qAbs(aRange.start().column() - position.column()) <
515 qAbs(bRange.start().column() - position.column());
516 }
517 return qAbs(aRange.end().column() - position.column()) <
518 qAbs(bRange.end().column() - position.column());
519 });
520
521 QVector<KDevelop::IProblem::Ptr> closestProblems;
522
523 // Show problems, located on the same line
524 for (auto& problem : std::as_const(allProblems)) {
525 auto r = problem->finalLocation();
526 if (r.onSingleLine() && r.start().line() == position.line())
527 closestProblems += problem;
528 else
529 break;
530 }
531
532 if (!closestProblems.isEmpty()) {
533 auto it = closestProblems.constBegin();
534 handleRange = (*it)->finalLocation();
535 ++it;
536 for (auto end = closestProblems.constEnd(); it != end; ++it) {
537 handleRange.confineToRange((*it)->finalLocation());
538 }

Callers 1

Calls 15

sortFunction · 0.85
modelsMethod · 0.80
problemModelSetMethod · 0.80
languageControllerMethod · 0.80
constBeginMethod · 0.80
constEndMethod · 0.80
invalidFunction · 0.50
problemsMethod · 0.45
urlMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected