diff options
Diffstat (limited to 'src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp')
-rw-r--r-- | src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 5ca055b0a14..f8a4191513b 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -44,10 +44,6 @@ #include <utils/qtcassert.h> #include <utils/QtConcurrentTools> -#include <QLoggingCategory> - -static Q_LOGGING_CATEGORY(log, "qtc.clangcodemodel.clangeditordocumentprocessor") - namespace { typedef CPlusPlus::Document::DiagnosticMessage CppToolsDiagnostic; @@ -59,8 +55,6 @@ QList<CppToolsDiagnostic> toCppToolsDiagnostics( QList<CppToolsDiagnostic> converted; foreach (const ClangCodeModel::Diagnostic &d, diagnostics) { - qCDebug(log) << "diagnostic" << d.severityAsString() << d.location() << d.spelling(); - if (d.location().fileName() != filePath) continue; @@ -112,6 +106,9 @@ ClangEditorDocumentProcessor::ClangEditorDocumentProcessor( connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::semanticInfoUpdated, this, &ClangEditorDocumentProcessor::semanticInfoUpdated); + connect(CppTools::CppModelManager::instance(), &CppTools::CppModelManager::projectPartsRemoved, + this, &ClangEditorDocumentProcessor::onProjectPartsRemoved); + m_semanticHighlighter.setHighlightingRunner( [this]() -> QFuture<TextEditor::HighlightingResult> { const int firstLine = 1; @@ -129,16 +126,11 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor() m_parserWatcher.cancel(); m_parserWatcher.waitForFinished(); - const CppTools::ProjectPart::Ptr projectPart = m_parser.projectPart(); - QTC_ASSERT(projectPart, return); - - QString projectFilePath; - if (Utils::isProjectPartValid(projectPart)) - projectFilePath = projectPart->projectFile; // OK, Project Part is still loaded - - QTC_ASSERT(m_modelManagerSupport, return); - m_modelManagerSupport->ipcCommunicator().unregisterFilesForCodeCompletion( - {ClangBackEnd::FileContainer(filePath(), projectFilePath)}); + if (m_projectPart) { + QTC_ASSERT(m_modelManagerSupport, return); + m_modelManagerSupport->ipcCommunicator().unregisterFilesForCodeCompletion( + {ClangBackEnd::FileContainer(filePath(), m_projectPart->id())}); + } } void ClangEditorDocumentProcessor::run() @@ -192,6 +184,25 @@ bool ClangEditorDocumentProcessor::isParserRunning() const return m_parserWatcher.isRunning(); } +CppTools::ProjectPart::Ptr ClangEditorDocumentProcessor::projectPart() const +{ + return m_projectPart; +} + +ClangEditorDocumentProcessor *ClangEditorDocumentProcessor::get(const QString &filePath) +{ + return qobject_cast<ClangEditorDocumentProcessor *>(BaseEditorDocumentProcessor::get(filePath)); +} + +void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForCompletion() +{ + const CppTools::ProjectPart::Ptr projectPart = m_parser.projectPart(); + QTC_ASSERT(projectPart, return); + + updateTranslationUnitForCompletion(*projectPart.data()); + m_projectPart = projectPart; +} + void ClangEditorDocumentProcessor::onParserFinished() { if (revision() != m_parserRevision) @@ -208,6 +219,34 @@ void ClangEditorDocumentProcessor::onParserFinished() // Run semantic highlighter m_semanticHighlighter.run(); + + updateProjectPartAndTranslationUnitForCompletion(); +} + +void ClangEditorDocumentProcessor::onProjectPartsRemoved(const QStringList &projectPartIds) +{ + if (m_projectPart && projectPartIds.contains(m_projectPart->id())) + m_projectPart.clear(); +} + +void ClangEditorDocumentProcessor::updateTranslationUnitForCompletion( + CppTools::ProjectPart &projectPart) +{ + QTC_ASSERT(m_modelManagerSupport, return); + IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator(); + + if (m_projectPart) { + if (projectPart.id() != m_projectPart->id()) { + auto container1 = {ClangBackEnd::FileContainer(filePath(), m_projectPart->id())}; + ipcCommunicator.unregisterFilesForCodeCompletion(container1); + + auto container2 = {ClangBackEnd::FileContainer(filePath(), projectPart.id())}; + ipcCommunicator.registerFilesForCodeCompletion(container2); + } + } else { + auto container = {ClangBackEnd::FileContainer(filePath(), projectPart.id())}; + ipcCommunicator.registerFilesForCodeCompletion(container); + } } } // namespace Internal |