void BaseEditorDocumentParser::updateProjectPart() { if (m_manuallySetProjectPart) { m_projectPart = m_manuallySetProjectPart; return; } CppModelManagerInterface *cmm = CppModelManagerInterface::instance(); QList<ProjectPart::Ptr> projectParts = cmm->projectPart(m_filePath); if (projectParts.isEmpty()) { if (m_projectPart) // File is not directly part of any project, but we got one before. We will re-use it, // because re-calculating this can be expensive when the dependency table is big. return; // Fall-back step 1: Get some parts through the dependency table: projectParts = cmm->projectPartFromDependencies(m_filePath); if (projectParts.isEmpty()) // Fall-back step 2: Use fall-back part from the model manager: m_projectPart = cmm->fallbackProjectPart(); else m_projectPart = projectParts.first(); } else { if (!projectParts.contains(m_projectPart)) // Apparently the project file changed, so update our project part. m_projectPart = projectParts.first(); } }
void CppIncludeHierarchyModel::buildHierarchyIncludes_helper(const QString &filePath, CppIncludeHierarchyItem *parent, QSet<QString> *cyclic, bool recursive) { if (!m_editor) return; CppModelManagerInterface *cppMM = CppModelManagerInterface::instance(); const Snapshot &snapshot = cppMM->cppEditorSupport(m_editor)->snapshotUpdater()->snapshot(); Document::Ptr doc = snapshot.document(filePath); if (!doc) return; parent->setHasChildren(doc->resolvedIncludes().size() > 0); if (!recursive) return; cyclic->insert(filePath); foreach (const Document::Include &includeFile, doc->resolvedIncludes()) { const QString includedFilePath = includeFile.resolvedFileName(); CppIncludeHierarchyItem *item = 0; if (cyclic->contains(includedFilePath)) { item = new CppIncludeHierarchyItem(includedFilePath, parent, true); parent->appendChild(item); continue; } item = new CppIncludeHierarchyItem(includedFilePath, parent); parent->appendChild(item); buildHierarchyIncludes_helper(includedFilePath, item, cyclic, false); } cyclic->remove(filePath); }
BaseEditorDocumentParser *BaseEditorDocumentParser::get(const QString &filePath) { CppModelManagerInterface *cmmi = CppModelManagerInterface::instance(); if (EditorDocumentHandle *editorDocument = cmmi->editorDocument(filePath)) { if (BaseEditorDocumentProcessor *processor = editorDocument->processor()) return processor->parser(); } return 0; }
static ProjectInfo setupProject(const QByteArray &projectFile, const QByteArray &mainFile, ProjectExplorerHelper &pHelper) { CppModelManagerHelper cppHelper; Project *project = pHelper.openProject(projectFilePath(_(projectFile))); if (!project) return ProjectInfo(); // Wait only for a single file: we don't really care if the file is refreshed or not, but at // this point we know that the C++ model manager got notified of all project parts and we can // retrieve them for inspection. cppHelper.waitForSourceFilesRefreshed(projectFilePath(_(mainFile))); CppModelManagerInterface *mm = cppHelper.cppModelManager(); return mm->projectInfo(project); }
TestCase::~TestCase() { // Close editors QList<Core::IEditor *> editorsToClose; foreach (const TestDocumentPtr testFile, m_testFiles) { if (testFile->editor) editorsToClose << testFile->editor; } EditorManager::closeEditors(editorsToClose, false); QCoreApplication::processEvents(); // process any pending events // Remove the test files from the code-model CppModelManagerInterface *mmi = CppTools::CppModelManagerInterface::instance(); mmi->GC(); QCOMPARE(mmi->snapshot().size(), 0); }
void GenericProjectPlugin::test_simple() { CppModelManagerHelper cppHelper; QString projectFile = _("testdata_simpleproject/simpleproject.creator"); ProjectExplorerHelper pHelper; Project *project = pHelper.openProject(projectFilePath(projectFile)); QVERIFY(project); QString mainFile = projectFilePath(_("testdata_simpleproject/main.cpp")); cppHelper.waitForSourceFilesRefreshed(mainFile); CppModelManagerInterface *mm = cppHelper.cppModelManager(); CppModelManagerInterface::ProjectInfo pInfo = mm->projectInfo(project); QCOMPARE(pInfo.projectParts().size(), 1); ProjectPart::Ptr pPart = pInfo.projectParts().first(); QVERIFY(pPart); QCOMPARE(pPart->files.size(), 1); QCOMPARE(pPart->files.first().path, mainFile); QCOMPARE(pPart->files.first().kind, ProjectFile::CXXSource); }
void CreateMarkers::run() { QMutexLocker lock(m_marker->mutex()); if (isCanceled()) return; m_options += QLatin1String("-fspell-checking"); QTime t; if (DebugTiming) { qDebug() << "*** Highlighting from" << m_firstLine << "to" << m_lastLine << "of" << m_fileName; qDebug("***** Options (cmd line equivalent): %s", commandLine(m_options, m_fileName).toUtf8().constData()); t.start(); } m_usages.clear(); m_marker->setFileName(m_fileName); m_marker->setCompilationOptions(m_options); m_marker->reparse(m_unsavedFiles); if (DebugTiming) qDebug() << "*** Reparse for highlighting took" << t.elapsed() << "ms."; m_pchInfo.clear(); typedef CPlusPlus::Document::DiagnosticMessage OtherDiagnostic; QList<OtherDiagnostic> msgs; foreach (const ClangCodeModel::Diagnostic &d, m_marker->diagnostics()) { if (DebugTiming) qDebug() << d.severityAsString() << d.location() << d.spelling(); if (d.location().fileName() != m_marker->fileName()) continue; // TODO: retrieve fix-its for this diagnostic int level; switch (d.severity()) { case Diagnostic::Fatal: level = OtherDiagnostic::Fatal; break; case Diagnostic::Error: level = OtherDiagnostic::Error; break; case Diagnostic::Warning: level = OtherDiagnostic::Warning; break; default: continue; } msgs.append(OtherDiagnostic(level, d.location().fileName(), d.location().line(), d.location().column(), d.spelling(), d.length())); } if (isCanceled()) { reportFinished(); return; } CppModelManagerInterface *mmi = CppModelManagerInterface::instance(); static const QString key = QLatin1String("ClangCodeModel.Diagnostics"); mmi->setExtraDiagnostics(m_marker->fileName(), key, msgs); #if CINDEX_VERSION_MINOR >= 21 mmi->setIfdefedOutBlocks(m_marker->fileName(), m_marker->ifdefedOutBlocks()); #endif if (isCanceled()) { reportFinished(); return; } QList<ClangCodeModel::SourceMarker> markers = m_marker->sourceMarkersInRange(m_firstLine, m_lastLine); foreach (const ClangCodeModel::SourceMarker &m, markers) addUse(SourceMarker(m.location().line(), m.location().column(), m.length(), m.kind())); if (isCanceled()) { reportFinished(); return; } flush(); reportFinished(); if (DebugTiming) { qDebug() << "*** Highlighting took" << t.elapsed() << "ms in total."; t.restart(); } if (m_fastIndexer) m_fastIndexer->indexNow(m_marker->unit()); if (DebugTiming) qDebug() << "*** Fast re-indexing took" << t.elapsed() << "ms in total."; }