forked from qt-creator/qt-creator
CppTools: Remove some duplication
Change-Id: I8c84660b28c3e76b2cedd08ff3b44a38583f38a0 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -36,11 +36,13 @@ ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClangEditorDocumentParser::updateImpl(const QFutureInterface<void> &,
|
void ClangEditorDocumentParser::updateImpl(const QFutureInterface<void> &,
|
||||||
const CppTools::WorkingCopy &,
|
const UpdateParams &updateParams)
|
||||||
const ProjectExplorer::Project *activeProject)
|
|
||||||
{
|
{
|
||||||
State state_ = state();
|
State state_ = state();
|
||||||
state_.projectPart = determineProjectPart(filePath(), configuration(), state_, activeProject);
|
state_.projectPart = determineProjectPart(filePath(),
|
||||||
|
configuration(),
|
||||||
|
state_,
|
||||||
|
updateParams.activeProject);
|
||||||
setState(state_);
|
setState(state_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,8 +38,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateImpl(const QFutureInterface<void> &future,
|
void updateImpl(const QFutureInterface<void> &future,
|
||||||
const CppTools::WorkingCopy &,
|
const UpdateParams &updateParams) override;
|
||||||
const ProjectExplorer::Project *activeProject) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
||||||
|
@@ -46,8 +46,6 @@
|
|||||||
#include <cpptools/cppworkingcopy.h>
|
#include <cpptools/cppworkingcopy.h>
|
||||||
#include <cpptools/editordocumenthandle.h>
|
#include <cpptools/editordocumenthandle.h>
|
||||||
|
|
||||||
#include <projectexplorer/session.h>
|
|
||||||
|
|
||||||
#include <texteditor/convenience.h>
|
#include <texteditor/convenience.h>
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
@@ -103,7 +101,8 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangEditorDocumentProcessor::run()
|
void ClangEditorDocumentProcessor::runImpl(
|
||||||
|
const CppTools::BaseEditorDocumentParser::UpdateParams &updateParams)
|
||||||
{
|
{
|
||||||
m_updateTranslationUnitTimer.start();
|
m_updateTranslationUnitTimer.start();
|
||||||
|
|
||||||
@@ -116,13 +115,7 @@ void ClangEditorDocumentProcessor::run()
|
|||||||
m_parserRevision = revision();
|
m_parserRevision = revision();
|
||||||
connect(&m_parserWatcher, &QFutureWatcher<void>::finished,
|
connect(&m_parserWatcher, &QFutureWatcher<void>::finished,
|
||||||
this, &ClangEditorDocumentProcessor::onParserFinished);
|
this, &ClangEditorDocumentProcessor::onParserFinished);
|
||||||
const CppTools::WorkingCopy workingCopy = CppTools::CppModelManager::instance()->workingCopy();
|
const QFuture<void> future = ::Utils::runAsync(&runParser, parser(), updateParams);
|
||||||
const ProjectExplorer::Project *activeProject
|
|
||||||
= ProjectExplorer::SessionManager::startupProject();
|
|
||||||
const QFuture<void> future = ::Utils::runAsync(&runParser,
|
|
||||||
parser(),
|
|
||||||
workingCopy,
|
|
||||||
activeProject);
|
|
||||||
m_parserWatcher.setFuture(future);
|
m_parserWatcher.setFuture(future);
|
||||||
|
|
||||||
// Run builtin processor
|
// Run builtin processor
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
~ClangEditorDocumentProcessor();
|
~ClangEditorDocumentProcessor();
|
||||||
|
|
||||||
// BaseEditorDocumentProcessor interface
|
// BaseEditorDocumentProcessor interface
|
||||||
void run() override;
|
void runImpl(const CppTools::BaseEditorDocumentParser::UpdateParams &updateParams) override;
|
||||||
void semanticRehighlight() override;
|
void semanticRehighlight() override;
|
||||||
void recalculateSemanticInfoDetached(bool force) override;
|
void recalculateSemanticInfoDetached(bool force) override;
|
||||||
CppTools::SemanticInfo recalculateSemanticInfo() override;
|
CppTools::SemanticInfo recalculateSemanticInfo() override;
|
||||||
|
@@ -77,19 +77,17 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati
|
|||||||
m_configuration = configuration;
|
m_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditorDocumentParser::update(const WorkingCopy &workingCopy,
|
void BaseEditorDocumentParser::update(const UpdateParams &updateParams)
|
||||||
const ProjectExplorer::Project *activeProject)
|
|
||||||
{
|
{
|
||||||
QFutureInterface<void> dummy;
|
QFutureInterface<void> dummy;
|
||||||
update(dummy, workingCopy, activeProject);
|
update(dummy, updateParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditorDocumentParser::update(const QFutureInterface<void> &future,
|
void BaseEditorDocumentParser::update(const QFutureInterface<void> &future,
|
||||||
const WorkingCopy &workingCopy,
|
const UpdateParams &updateParams)
|
||||||
const ProjectExplorer::Project *activeProject)
|
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_updateIsRunning);
|
QMutexLocker locker(&m_updateIsRunning);
|
||||||
updateImpl(future, workingCopy, activeProject);
|
updateImpl(future, updateParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
|
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
|
||||||
|
@@ -52,6 +52,18 @@ public:
|
|||||||
ProjectPart::Ptr manuallySetProjectPart;
|
ProjectPart::Ptr manuallySetProjectPart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct UpdateParams {
|
||||||
|
UpdateParams(const WorkingCopy &workingCopy,
|
||||||
|
const ProjectExplorer::Project *activeProject)
|
||||||
|
: workingCopy(workingCopy)
|
||||||
|
, activeProject(activeProject)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkingCopy workingCopy;
|
||||||
|
const ProjectExplorer::Project *activeProject = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseEditorDocumentParser(const QString &filePath);
|
BaseEditorDocumentParser(const QString &filePath);
|
||||||
virtual ~BaseEditorDocumentParser();
|
virtual ~BaseEditorDocumentParser();
|
||||||
@@ -60,11 +72,8 @@ public:
|
|||||||
Configuration configuration() const;
|
Configuration configuration() const;
|
||||||
void setConfiguration(const Configuration &configuration);
|
void setConfiguration(const Configuration &configuration);
|
||||||
|
|
||||||
void update(const WorkingCopy &workingCopy,
|
void update(const UpdateParams &updateParams);
|
||||||
const ProjectExplorer::Project *activeProject);
|
void update(const QFutureInterface<void> &future, const UpdateParams &updateParams);
|
||||||
void update(const QFutureInterface<void> &future,
|
|
||||||
const WorkingCopy &workingCopy,
|
|
||||||
const ProjectExplorer::Project *activeProject);
|
|
||||||
|
|
||||||
ProjectPart::Ptr projectPart() const;
|
ProjectPart::Ptr projectPart() const;
|
||||||
|
|
||||||
@@ -85,8 +94,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void updateImpl(const QFutureInterface<void> &future,
|
virtual void updateImpl(const QFutureInterface<void> &future,
|
||||||
const WorkingCopy &workingCopy,
|
const UpdateParams &updateParams) = 0;
|
||||||
const ProjectExplorer::Project *activeProject) = 0;
|
|
||||||
|
|
||||||
const QString m_filePath;
|
const QString m_filePath;
|
||||||
Configuration m_configuration;
|
Configuration m_configuration;
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include "cpptoolsbridge.h"
|
#include "cpptoolsbridge.h"
|
||||||
#include "editordocumenthandle.h"
|
#include "editordocumenthandle.h"
|
||||||
|
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
#include <texteditor/quickfix.h>
|
#include <texteditor/quickfix.h>
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
@@ -52,6 +53,12 @@ BaseEditorDocumentProcessor::~BaseEditorDocumentProcessor()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseEditorDocumentProcessor::run()
|
||||||
|
{
|
||||||
|
runImpl({CppModelManager::instance()->workingCopy(),
|
||||||
|
ProjectExplorer::SessionManager::startupProject()});
|
||||||
|
}
|
||||||
|
|
||||||
TextEditor::QuickFixOperations
|
TextEditor::QuickFixOperations
|
||||||
BaseEditorDocumentProcessor::extraRefactoringOperations(const TextEditor::AssistInterface &)
|
BaseEditorDocumentProcessor::extraRefactoringOperations(const TextEditor::AssistInterface &)
|
||||||
{
|
{
|
||||||
@@ -73,8 +80,7 @@ void BaseEditorDocumentProcessor::editorDocumentTimerRestarted()
|
|||||||
|
|
||||||
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
|
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
|
||||||
BaseEditorDocumentParser::Ptr parser,
|
BaseEditorDocumentParser::Ptr parser,
|
||||||
const WorkingCopy workingCopy,
|
BaseEditorDocumentParser::UpdateParams updateParams)
|
||||||
const ProjectExplorer::Project *activeProject)
|
|
||||||
{
|
{
|
||||||
future.setProgressRange(0, 1);
|
future.setProgressRange(0, 1);
|
||||||
if (future.isCanceled()) {
|
if (future.isCanceled()) {
|
||||||
@@ -82,7 +88,7 @@ void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->update(future, workingCopy, activeProject);
|
parser->update(future, updateParams);
|
||||||
CppToolsBridge::finishedRefreshingSourceFiles({parser->filePath()});
|
CppToolsBridge::finishedRefreshingSourceFiles({parser->filePath()});
|
||||||
|
|
||||||
future.setProgressValue(1);
|
future.setProgressValue(1);
|
||||||
|
@@ -54,8 +54,7 @@ public:
|
|||||||
BaseEditorDocumentProcessor(QTextDocument *textDocument, const QString &filePath);
|
BaseEditorDocumentProcessor(QTextDocument *textDocument, const QString &filePath);
|
||||||
virtual ~BaseEditorDocumentProcessor();
|
virtual ~BaseEditorDocumentProcessor();
|
||||||
|
|
||||||
// Function interface to implement
|
void run();
|
||||||
virtual void run() = 0;
|
|
||||||
virtual void semanticRehighlight() = 0;
|
virtual void semanticRehighlight() = 0;
|
||||||
virtual void recalculateSemanticInfoDetached(bool force) = 0;
|
virtual void recalculateSemanticInfoDetached(bool force) = 0;
|
||||||
virtual CppTools::SemanticInfo recalculateSemanticInfo() = 0;
|
virtual CppTools::SemanticInfo recalculateSemanticInfo() = 0;
|
||||||
@@ -91,14 +90,16 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
static void runParser(QFutureInterface<void> &future,
|
static void runParser(QFutureInterface<void> &future,
|
||||||
BaseEditorDocumentParser::Ptr parser,
|
BaseEditorDocumentParser::Ptr parser,
|
||||||
const CppTools::WorkingCopy workingCopy,
|
BaseEditorDocumentParser::UpdateParams updateParams);
|
||||||
const ProjectExplorer::Project *activeProject);
|
|
||||||
|
|
||||||
// Convenience
|
// Convenience
|
||||||
QString filePath() const { return m_filePath; }
|
QString filePath() const { return m_filePath; }
|
||||||
unsigned revision() const { return static_cast<unsigned>(m_textDocument->revision()); }
|
unsigned revision() const { return static_cast<unsigned>(m_textDocument->revision()); }
|
||||||
QTextDocument *textDocument() const { return m_textDocument; }
|
QTextDocument *textDocument() const { return m_textDocument; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_filePath;
|
QString m_filePath;
|
||||||
QTextDocument *m_textDocument;
|
QTextDocument *m_textDocument;
|
||||||
|
@@ -56,8 +56,7 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &future,
|
void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &future,
|
||||||
const WorkingCopy &theWorkingCopy,
|
const UpdateParams &updateParams)
|
||||||
const ProjectExplorer::Project *activeProject)
|
|
||||||
{
|
{
|
||||||
if (filePath().isEmpty())
|
if (filePath().isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -67,7 +66,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
|||||||
|
|
||||||
State baseState = state();
|
State baseState = state();
|
||||||
ExtraState state = extraState();
|
ExtraState state = extraState();
|
||||||
WorkingCopy workingCopy = theWorkingCopy;
|
WorkingCopy workingCopy = updateParams.workingCopy;
|
||||||
|
|
||||||
bool invalidateSnapshot = false, invalidateConfig = false, editorDefinesChanged_ = false;
|
bool invalidateSnapshot = false, invalidateConfig = false, editorDefinesChanged_ = false;
|
||||||
|
|
||||||
@@ -78,7 +77,10 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
|||||||
QString projectConfigFile;
|
QString projectConfigFile;
|
||||||
LanguageFeatures features = LanguageFeatures::defaultFeatures();
|
LanguageFeatures features = LanguageFeatures::defaultFeatures();
|
||||||
|
|
||||||
baseState.projectPart = determineProjectPart(filePath(), baseConfig, baseState, activeProject);
|
baseState.projectPart = determineProjectPart(filePath(),
|
||||||
|
baseConfig,
|
||||||
|
baseState,
|
||||||
|
updateParams.activeProject);
|
||||||
|
|
||||||
if (state.forceSnapshotInvalidation) {
|
if (state.forceSnapshotInvalidation) {
|
||||||
invalidateSnapshot = true;
|
invalidateSnapshot = true;
|
||||||
|
@@ -59,8 +59,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateImpl(const QFutureInterface<void> &future,
|
void updateImpl(const QFutureInterface<void> &future,
|
||||||
const WorkingCopy &workingCopy,
|
const UpdateParams &updateParams) override;
|
||||||
const ProjectExplorer::Project *activeProject) override;
|
|
||||||
void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
|
void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
|
||||||
QSet<Utils::FileName> *toRemove,
|
QSet<Utils::FileName> *toRemove,
|
||||||
const Utils::FileName &fileName) const;
|
const Utils::FileName &fileName) const;
|
||||||
|
@@ -32,8 +32,6 @@
|
|||||||
#include "cpptoolsreuse.h"
|
#include "cpptoolsreuse.h"
|
||||||
#include "cppworkingcopy.h"
|
#include "cppworkingcopy.h"
|
||||||
|
|
||||||
#include <projectexplorer/session.h>
|
|
||||||
|
|
||||||
#include <texteditor/convenience.h>
|
#include <texteditor/convenience.h>
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
#include <texteditor/refactoroverlay.h>
|
#include <texteditor/refactoroverlay.h>
|
||||||
@@ -204,16 +202,13 @@ BuiltinEditorDocumentProcessor::~BuiltinEditorDocumentProcessor()
|
|||||||
m_parserFuture.waitForFinished();
|
m_parserFuture.waitForFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltinEditorDocumentProcessor::run()
|
void BuiltinEditorDocumentProcessor::runImpl(
|
||||||
|
const BaseEditorDocumentParser::UpdateParams &updateParams)
|
||||||
{
|
{
|
||||||
CppModelManager *mgr = CppModelManager::instance();
|
m_parserFuture = Utils::runAsync(CppModelManager::instance()->sharedThreadPool(),
|
||||||
const ProjectExplorer::Project *activeProject
|
|
||||||
= ProjectExplorer::SessionManager::startupProject();
|
|
||||||
m_parserFuture = Utils::runAsync(mgr->sharedThreadPool(),
|
|
||||||
runParser,
|
runParser,
|
||||||
parser(),
|
parser(),
|
||||||
mgr->workingCopy(),
|
updateParams);
|
||||||
activeProject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseEditorDocumentParser::Ptr BuiltinEditorDocumentProcessor::parser()
|
BaseEditorDocumentParser::Ptr BuiltinEditorDocumentProcessor::parser()
|
||||||
|
@@ -43,7 +43,7 @@ public:
|
|||||||
~BuiltinEditorDocumentProcessor();
|
~BuiltinEditorDocumentProcessor();
|
||||||
|
|
||||||
// BaseEditorDocumentProcessor interface
|
// BaseEditorDocumentProcessor interface
|
||||||
void run() override;
|
void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) override;
|
||||||
void recalculateSemanticInfoDetached(bool force) override;
|
void recalculateSemanticInfoDetached(bool force) override;
|
||||||
void semanticRehighlight() override;
|
void semanticRehighlight() override;
|
||||||
CppTools::SemanticInfo recalculateSemanticInfo() override;
|
CppTools::SemanticInfo recalculateSemanticInfo() override;
|
||||||
|
@@ -158,7 +158,7 @@ void indexFindErrors(QFutureInterface<void> &future, const ParseParams params)
|
|||||||
// Parse the file as precisely as possible
|
// Parse the file as precisely as possible
|
||||||
BuiltinEditorDocumentParser parser(file);
|
BuiltinEditorDocumentParser parser(file);
|
||||||
parser.setReleaseSourceAndAST(false);
|
parser.setReleaseSourceAndAST(false);
|
||||||
parser.update(CppModelManager::instance()->workingCopy(), nullptr);
|
parser.update({CppModelManager::instance()->workingCopy(), nullptr});
|
||||||
CPlusPlus::Document::Ptr document = parser.document();
|
CPlusPlus::Document::Ptr document = parser.document();
|
||||||
QTC_ASSERT(document, return);
|
QTC_ASSERT(document, return);
|
||||||
|
|
||||||
|
@@ -2122,7 +2122,7 @@ void CppCompletionAssistInterface::getCppSpecifics() const
|
|||||||
m_gotCppSpecifics = true;
|
m_gotCppSpecifics = true;
|
||||||
|
|
||||||
if (m_parser) {
|
if (m_parser) {
|
||||||
m_parser->update(CppTools::CppModelManager::instance()->workingCopy(), nullptr);
|
m_parser->update({CppTools::CppModelManager::instance()->workingCopy(), nullptr});
|
||||||
m_snapshot = m_parser->snapshot();
|
m_snapshot = m_parser->snapshot();
|
||||||
m_headerPaths = m_parser->headerPaths();
|
m_headerPaths = m_parser->headerPaths();
|
||||||
}
|
}
|
||||||
|
@@ -877,7 +877,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
|
|||||||
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
||||||
config.usePrecompiledHeaders = true;
|
config.usePrecompiledHeaders = true;
|
||||||
parser->setConfiguration(config);
|
parser->setConfiguration(config);
|
||||||
parser->update(CppModelManager::instance()->workingCopy(), nullptr);
|
parser->update({CppModelManager::instance()->workingCopy(), nullptr});
|
||||||
|
|
||||||
// Check if defines from pch are considered
|
// Check if defines from pch are considered
|
||||||
Document::Ptr document = mm->document(fileName);
|
Document::Ptr document = mm->document(fileName);
|
||||||
@@ -955,7 +955,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
|
|||||||
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
BaseEditorDocumentParser::Configuration config = parser->configuration();
|
||||||
config.editorDefines = editorDefines.toUtf8();
|
config.editorDefines = editorDefines.toUtf8();
|
||||||
parser->setConfiguration(config);
|
parser->setConfiguration(config);
|
||||||
parser->update(CppModelManager::instance()->workingCopy(), nullptr);
|
parser->update({CppModelManager::instance()->workingCopy(), nullptr});
|
||||||
|
|
||||||
Document::Ptr doc = mm->document(main1File);
|
Document::Ptr doc = mm->document(main1File);
|
||||||
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
|
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
|
||||||
|
Reference in New Issue
Block a user