diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 134fb4d51c8..6a414d8b0fd 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -762,6 +762,11 @@ QByteArray Preprocessor::run(const QString &fileName, return preprocessed; } +void Preprocessor::setCancelChecker(const Preprocessor::CancelChecker &cancelChecker) +{ + m_cancelChecker = cancelChecker; +} + bool Preprocessor::expandFunctionlikeMacros() const { return m_expandFunctionlikeMacros; @@ -1636,6 +1641,9 @@ void Preprocessor::handlePreprocessorDirective(PPToken *tk) void Preprocessor::handleIncludeDirective(PPToken *tk, bool includeNext) { + if (m_cancelChecker && m_cancelChecker()) + return; + m_state.m_lexer->setScanAngleStringLiteralTokens(true); lex(tk); // consume "include" token m_state.m_lexer->setScanAngleStringLiteralTokens(false); diff --git a/src/libs/cplusplus/pp-engine.h b/src/libs/cplusplus/pp-engine.h index b265de6d46a..19935b2c7d9 100644 --- a/src/libs/cplusplus/pp-engine.h +++ b/src/libs/cplusplus/pp-engine.h @@ -56,6 +56,8 @@ #include #include +#include + namespace CPlusPlus { class Environment; @@ -81,6 +83,9 @@ public: QByteArray run(const QString &filename, const QByteArray &source, bool noLines = false, bool markGeneratedTokens = true); + using CancelChecker = std::function; + void setCancelChecker(const CancelChecker &cancelChecker); + bool expandFunctionlikeMacros() const; void setExpandFunctionlikeMacros(bool expandFunctionlikeMacros); @@ -253,6 +258,7 @@ private: Client *m_client; Environment *m_env; QByteArray m_scratchBuffer; + CancelChecker m_cancelChecker; bool m_expandFunctionlikeMacros; bool m_keepComments; diff --git a/src/plugins/clangcodemodel/clangeditordocumentparser.cpp b/src/plugins/clangcodemodel/clangeditordocumentparser.cpp index 97939dd92c4..129c0669a61 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentparser.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentparser.cpp @@ -35,7 +35,8 @@ ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath) setConfiguration(config); } -void ClangEditorDocumentParser::updateHelper(const CppTools::WorkingCopy &) +void ClangEditorDocumentParser::updateHelper(const QFutureInterface &, + const CppTools::WorkingCopy &) { State state_ = state(); state_.projectPart = determineProjectPart(filePath(), configuration(), state_); diff --git a/src/plugins/clangcodemodel/clangeditordocumentparser.h b/src/plugins/clangcodemodel/clangeditordocumentparser.h index 65da483e2f2..848e31f1259 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentparser.h +++ b/src/plugins/clangcodemodel/clangeditordocumentparser.h @@ -37,7 +37,8 @@ public: ClangEditorDocumentParser(const QString &filePath); private: - void updateHelper(const CppTools::WorkingCopy &) override; + void updateHelper(const QFutureInterface &future, + const CppTools::WorkingCopy &) override; }; } // namespace ClangCodeModel diff --git a/src/plugins/cpptools/baseeditordocumentparser.cpp b/src/plugins/cpptools/baseeditordocumentparser.cpp index 4a216e17ae9..ee3b8bec5c4 100644 --- a/src/plugins/cpptools/baseeditordocumentparser.cpp +++ b/src/plugins/cpptools/baseeditordocumentparser.cpp @@ -77,9 +77,16 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati } void BaseEditorDocumentParser::update(const WorkingCopy &workingCopy) +{ + QFutureInterface dummy; + update(dummy, workingCopy); +} + +void BaseEditorDocumentParser::update(const QFutureInterface &future, + const WorkingCopy &workingCopy) { QMutexLocker locker(&m_updateIsRunning); - updateHelper(workingCopy); + updateHelper(future, workingCopy); } BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const diff --git a/src/plugins/cpptools/baseeditordocumentparser.h b/src/plugins/cpptools/baseeditordocumentparser.h index 3822394c61b..328fe421fdb 100644 --- a/src/plugins/cpptools/baseeditordocumentparser.h +++ b/src/plugins/cpptools/baseeditordocumentparser.h @@ -29,6 +29,7 @@ #include "cppworkingcopy.h" #include "projectpart.h" +#include #include #include @@ -39,7 +40,7 @@ class CPPTOOLS_EXPORT BaseEditorDocumentParser : public QObject Q_OBJECT public: - using Ptr = QSharedPointer;; + using Ptr = QSharedPointer; static Ptr get(const QString &filePath); struct Configuration { @@ -58,6 +59,7 @@ public: void setConfiguration(const Configuration &configuration); void update(const WorkingCopy &workingCopy); + void update(const QFutureInterface &future, const WorkingCopy &workingCopy); ProjectPart::Ptr projectPart() const; @@ -76,7 +78,8 @@ protected: mutable QMutex m_stateAndConfigurationMutex; private: - virtual void updateHelper(const WorkingCopy &workingCopy) = 0; + virtual void updateHelper(const QFutureInterface &future, + const WorkingCopy &workingCopy) = 0; const QString m_filePath; Configuration m_configuration; diff --git a/src/plugins/cpptools/baseeditordocumentprocessor.cpp b/src/plugins/cpptools/baseeditordocumentprocessor.cpp index f32d79ed771..82aa058b90d 100644 --- a/src/plugins/cpptools/baseeditordocumentprocessor.cpp +++ b/src/plugins/cpptools/baseeditordocumentprocessor.cpp @@ -77,7 +77,7 @@ void BaseEditorDocumentProcessor::runParser(QFutureInterface &future, return; } - parser->update(workingCopy); + parser->update(future, workingCopy); CppToolsBridge::finishedRefreshingSourceFiles({parser->filePath()}); future.setProgressValue(1); diff --git a/src/plugins/cpptools/builtineditordocumentparser.cpp b/src/plugins/cpptools/builtineditordocumentparser.cpp index 014252b13d8..8ab6a891014 100644 --- a/src/plugins/cpptools/builtineditordocumentparser.cpp +++ b/src/plugins/cpptools/builtineditordocumentparser.cpp @@ -55,7 +55,8 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath qRegisterMetaType("CPlusPlus::Snapshot"); } -void BuiltinEditorDocumentParser::updateHelper(const WorkingCopy &theWorkingCopy) +void BuiltinEditorDocumentParser::updateHelper(const QFutureInterface &future, + const WorkingCopy &theWorkingCopy) { if (filePath().isEmpty()) return; @@ -181,6 +182,10 @@ void BuiltinEditorDocumentParser::updateHelper(const WorkingCopy &theWorkingCopy if (releaseSourceAndAST_) doc->releaseSourceAndAST(); }); + sourceProcessor.setCancelChecker([future]() { + return future.isCanceled(); + }); + Snapshot globalSnapshot = modelManager->snapshot(); globalSnapshot.remove(filePath()); sourceProcessor.setGlobalSnapshot(globalSnapshot); diff --git a/src/plugins/cpptools/builtineditordocumentparser.h b/src/plugins/cpptools/builtineditordocumentparser.h index c2eb4c86ee4..94ae556574c 100644 --- a/src/plugins/cpptools/builtineditordocumentparser.h +++ b/src/plugins/cpptools/builtineditordocumentparser.h @@ -58,7 +58,8 @@ public: static Ptr get(const QString &filePath); private: - void updateHelper(const WorkingCopy &workingCopy) override; + void updateHelper(const QFutureInterface &future, + const WorkingCopy &workingCopy) override; void addFileAndDependencies(CPlusPlus::Snapshot *snapshot, QSet *toRemove, const Utils::FileName &fileName) const; diff --git a/src/plugins/cpptools/cppsourceprocessor.cpp b/src/plugins/cpptools/cppsourceprocessor.cpp index f238a841f7a..e04d977ebf1 100644 --- a/src/plugins/cpptools/cppsourceprocessor.cpp +++ b/src/plugins/cpptools/cppsourceprocessor.cpp @@ -121,6 +121,11 @@ CppSourceProcessor::CppSourceProcessor(const Snapshot &snapshot, DocumentCallbac CppSourceProcessor::~CppSourceProcessor() { } +void CppSourceProcessor::setCancelChecker(const CppSourceProcessor::CancelChecker &cancelChecker) +{ + m_preprocess.setCancelChecker(cancelChecker); +} + void CppSourceProcessor::setWorkingCopy(const WorkingCopy &workingCopy) { m_workingCopy = workingCopy; } diff --git a/src/plugins/cpptools/cppsourceprocessor.h b/src/plugins/cpptools/cppsourceprocessor.h index fdebc893c6f..84ea0343472 100644 --- a/src/plugins/cpptools/cppsourceprocessor.h +++ b/src/plugins/cpptools/cppsourceprocessor.h @@ -59,6 +59,9 @@ public: CppSourceProcessor(const CPlusPlus::Snapshot &snapshot, DocumentCallback documentFinished); ~CppSourceProcessor(); + using CancelChecker = std::function; + void setCancelChecker(const CancelChecker &cancelChecker); + void setWorkingCopy(const CppTools::WorkingCopy &workingCopy); void setHeaderPaths(const ProjectPartHeaderPaths &headerPaths); void setLanguageFeatures(CPlusPlus::LanguageFeatures languageFeatures);