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

Method applyHighlighting

kdevplatform/language/highlighting/codehighlighting.cpp:510–604  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

508}
509
510void CodeHighlighting::applyHighlighting(void* _highlighting)
511{
512 auto* highlighting =
513 static_cast<CodeHighlighting::DocumentHighlighting*>(_highlighting);
514
515 VERIFY_FOREGROUND_LOCKED
516 QMutexLocker lock(&m_dataMutex);
517 DocumentChangeTracker* tracker = ICore::self()->languageController()->backgroundParser()->trackerForUrl(
518 highlighting->m_document);
519
520 if (!tracker) {
521 qCDebug(LANGUAGE) << "no document found for the planned highlighting of" << highlighting->m_document.str();
522 delete highlighting;
523 return;
524 }
525
526 if (!tracker->holdingRevision(highlighting->m_waitingRevision)) {
527 qCDebug(LANGUAGE) << "not holding revision" << highlighting->m_waitingRevision << "not applying highlighting;"
528 << "probably a new parse job has already updated the context";
529 delete highlighting;
530 return;
531 }
532
533 QVector<MovingRange*> oldHighlightedRanges;
534
535 const auto highlightingIt = m_highlights.find(tracker);
536 if (highlightingIt != m_highlights.end()) {
537 oldHighlightedRanges = (*highlightingIt)->m_highlightedRanges;
538 delete *highlightingIt;
539 *highlightingIt = highlighting;
540 } else {
541 // we newly add this tracker, so add the connection
542 connect(tracker->document(), &Document::aboutToInvalidateMovingInterfaceContent, this,
543 &CodeHighlighting::aboutToInvalidateMovingInterfaceContent);
544 // This can't use new style connect syntax since aboutToRemoveText is only part of KTextEditor::DocumentPrivate
545 connect(tracker->document(), SIGNAL(aboutToRemoveText(KTextEditor::Range)),
546 this, SLOT(aboutToRemoveText(KTextEditor::Range)));
547 connect(tracker, &DocumentChangeTracker::destroyed, this, [this, tracker]() {
548 // Called when a document is destroyed
549 VERIFY_FOREGROUND_LOCKED
550 QMutexLocker lock(&m_dataMutex);
551 Q_ASSERT(m_highlights.contains(tracker));
552 delete m_highlights[tracker]; // No need to care about the individual ranges, as the document is being
553 // destroyed
554 m_highlights.remove(tracker);
555 });
556 m_highlights.insert(tracker, highlighting);
557 }
558
559 // Now create MovingRanges (match old ones with the incoming ranges)
560
561 KTextEditor::Range tempRange;
562
563 QVector<MovingRange*>::iterator movingIt = oldHighlightedRanges.begin();
564 QVector<HighlightedRange>::iterator rangeIt = highlighting->m_waiting.begin();
565
566 while (rangeIt != highlighting->m_waiting.end()) {
567 // Translate the range into the current revision

Callers

nothing calls this directly

Calls 15

trackerForUrlMethod · 0.80
backgroundParserMethod · 0.80
languageControllerMethod · 0.80
strMethod · 0.80
holdingRevisionMethod · 0.80
setAttributeMethod · 0.80
setZDepthMethod · 0.80
setRangeMethod · 0.80
findMethod · 0.45
endMethod · 0.45
documentMethod · 0.45

Tested by

no test coverage detected