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

Method documentLoadedPrepare

kdevplatform/language/duchain/duchain.cpp:1627–1690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1625}
1626
1627void DUChain::documentLoadedPrepare(KDevelop::IDocument* doc)
1628{
1629 if (sdDUChainPrivate->m_destroyed)
1630 return;
1631
1632 const IndexedString url(doc->url());
1633 DUChainWriteLocker lock(DUChain::lock());
1634 QMutexLocker l(&sdDUChainPrivate->m_chainsMutex);
1635
1636 TopDUContext* standardContext = DUChainUtils::standardContextForUrl(doc->url());
1637 QList<TopDUContext*> chains = chainsForDocument(url);
1638
1639 const auto languages = ICore::self()->languageController()->languagesForUrl(doc->url());
1640
1641 if (standardContext) {
1642 Q_ASSERT(chains.contains(standardContext)); //We have just loaded it
1643 Q_ASSERT((standardContext->url() == url));
1644
1645 sdDUChainPrivate->m_openDocumentContexts.insert(standardContext);
1646
1647 bool needsUpdate = standardContext->parsingEnvironmentFile() &&
1648 standardContext->parsingEnvironmentFile()->needsUpdate();
1649 if (!needsUpdate) {
1650 //Only apply the highlighting if we don't need to update, else we might highlight total crap
1651 //Do instant highlighting only if all imports are loaded, to make sure that we don't block the user-interface too long
1652 //Else the highlighting will be done in the background-thread
1653 //This is not exactly right, as the direct imports don't necessarily equal the real imports used by uses
1654 //but it approximates the correct behavior.
1655 bool allImportsLoaded = true;
1656 const auto importedParentContexts = standardContext->importedParentContexts();
1657 for (const DUContext::Import& import : importedParentContexts) {
1658 if (!import.indexedContext().indexedTopContext().isLoaded())
1659 allImportsLoaded = false;
1660 }
1661
1662 if (allImportsLoaded) {
1663 l.unlock();
1664 lock.unlock();
1665 for (const auto language : languages) {
1666 if (language->codeHighlighting()) {
1667 language->codeHighlighting()->highlightDUChain(standardContext);
1668 }
1669 }
1670
1671 qCDebug(LANGUAGE) << "highlighted" << doc->url() << "in foreground";
1672 return;
1673 }
1674 } else {
1675 qCDebug(LANGUAGE) << "not highlighting the duchain because the documents needs an update";
1676 }
1677
1678 if (needsUpdate || !(standardContext->features() & TopDUContext::AllDeclarationsContextsAndUses)) {
1679 ICore::self()->languageController()->backgroundParser()->addDocument(IndexedString(doc->url()),
1680 TopDUContext::AllDeclarationsContextsAndUses
1681 | TopDUContext::ForceUpdate);
1682 return;
1683 }
1684 }

Callers

nothing calls this directly

Calls 15

languagesForUrlMethod · 0.80
languageControllerMethod · 0.80
backgroundParserMethod · 0.80
IndexedStringClass · 0.70
urlMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45
needsUpdateMethod · 0.45
isLoadedMethod · 0.45
indexedTopContextMethod · 0.45

Tested by

no test coverage detected