Commit 7c21f2ec authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

CppTools: Denoise with BuiltinEditorDocumentParser::Ptr

Change-Id: I1d572e8cc3e76ef6bbae720e3c3482292aab9609
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 7d35212f
...@@ -1020,7 +1020,7 @@ void CppEditorWidget::onFilePathChanged() ...@@ -1020,7 +1020,7 @@ void CppEditorWidget::onFilePathChanged()
additionalDirectives = ProjectExplorer::SessionManager::value( additionalDirectives = ProjectExplorer::SessionManager::value(
projectFile + QLatin1Char(',') + filePath).toString().toUtf8(); projectFile + QLatin1Char(',') + filePath).toString().toUtf8();
QSharedPointer<BuiltinEditorDocumentParser> parser BuiltinEditorDocumentParser::Ptr parser
= d->m_modelManager->cppEditorSupport(editor())->documentParser(); = d->m_modelManager->cppEditorSupport(editor())->documentParser();
parser->setProjectPart(d->m_modelManager->projectPartForProjectFile(projectFile)); parser->setProjectPart(d->m_modelManager->projectPartForProjectFile(projectFile));
parser->setEditorDefines(additionalDirectives); parser->setEditorDefines(additionalDirectives);
...@@ -1088,7 +1088,7 @@ void CppEditorWidget::showPreProcessorWidget() ...@@ -1088,7 +1088,7 @@ void CppEditorWidget::showPreProcessorWidget()
CppPreProcessorDialog preProcessorDialog(this, textDocument()->filePath(), projectParts); CppPreProcessorDialog preProcessorDialog(this, textDocument()->filePath(), projectParts);
if (preProcessorDialog.exec() == QDialog::Accepted) { if (preProcessorDialog.exec() == QDialog::Accepted) {
QSharedPointer<BuiltinEditorDocumentParser> parser BuiltinEditorDocumentParser::Ptr parser
= d->m_modelManager->cppEditorSupport(editor())->documentParser(); = d->m_modelManager->cppEditorSupport(editor())->documentParser();
const QString &additionals = preProcessorDialog.additionalPreProcessorDirectives(); const QString &additionals = preProcessorDialog.additionalPreProcessorDirectives();
parser->setProjectPart(preProcessorDialog.projectPart()); parser->setProjectPart(preProcessorDialog.projectPart());
......
...@@ -45,6 +45,9 @@ namespace CppTools { ...@@ -45,6 +45,9 @@ namespace CppTools {
class CPPTOOLS_EXPORT BuiltinEditorDocumentParser : public BaseEditorDocumentParser class CPPTOOLS_EXPORT BuiltinEditorDocumentParser : public BaseEditorDocumentParser
{ {
public:
typedef QSharedPointer<BuiltinEditorDocumentParser> Ptr;
public: public:
BuiltinEditorDocumentParser(const QString &filePath); BuiltinEditorDocumentParser(const QString &filePath);
......
...@@ -1959,7 +1959,7 @@ void CppCompletionAssistInterface::getCppSpecifics() const ...@@ -1959,7 +1959,7 @@ void CppCompletionAssistInterface::getCppSpecifics() const
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance(); CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
if (CppEditorSupport *supp = modelManager->cppEditorSupport(m_editor)) { if (CppEditorSupport *supp = modelManager->cppEditorSupport(m_editor)) {
if (QSharedPointer<BuiltinEditorDocumentParser> parser = supp->documentParser()) { if (BuiltinEditorDocumentParser::Ptr parser = supp->documentParser()) {
parser->update(m_workingCopy); parser->update(m_workingCopy);
m_snapshot = parser->snapshot(); m_snapshot = parser->snapshot();
m_headerPaths = parser->headerPaths(); m_headerPaths = parser->headerPaths();
......
...@@ -144,8 +144,7 @@ void CppToolsPlugin::test_cppsourceprocessor_includes_cyclic() ...@@ -144,8 +144,7 @@ void CppToolsPlugin::test_cppsourceprocessor_includes_cyclic()
CppEditorSupport *cppEditorSupport = CppModelManagerInterface::instance() CppEditorSupport *cppEditorSupport = CppModelManagerInterface::instance()
->cppEditorSupport(editor); ->cppEditorSupport(editor);
QVERIFY(cppEditorSupport); QVERIFY(cppEditorSupport);
QSharedPointer<BuiltinEditorDocumentParser> documentParser BuiltinEditorDocumentParser::Ptr documentParser = cppEditorSupport->documentParser();
= cppEditorSupport->documentParser();
QVERIFY(documentParser); QVERIFY(documentParser);
Snapshot snapshot = documentParser->snapshot(); Snapshot snapshot = documentParser->snapshot();
QCOMPARE(snapshot.size(), 3); // Configuration file included QCOMPARE(snapshot.size(), 3); // Configuration file included
......
...@@ -259,11 +259,11 @@ CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const ...@@ -259,11 +259,11 @@ CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
return m_completionAssistProvider; return m_completionAssistProvider;
} }
QSharedPointer<BuiltinEditorDocumentParser> CppEditorSupport::documentParser() BuiltinEditorDocumentParser::Ptr CppEditorSupport::documentParser()
{ {
QSharedPointer<BuiltinEditorDocumentParser> updater = documentParser_internal(); BuiltinEditorDocumentParser::Ptr updater = documentParser_internal();
if (!updater || updater->filePath() != fileName()) { if (!updater || updater->filePath() != fileName()) {
updater = QSharedPointer<BuiltinEditorDocumentParser>(new BuiltinEditorDocumentParser(fileName())); updater = BuiltinEditorDocumentParser::Ptr(new BuiltinEditorDocumentParser(fileName()));
setDocumentParser_internal(updater); setDocumentParser_internal(updater);
QSharedPointer<CppCodeModelSettings> cms = CppToolsPlugin::instance()->codeModelSettings(); QSharedPointer<CppCodeModelSettings> cms = CppToolsPlugin::instance()->codeModelSettings();
...@@ -282,7 +282,7 @@ void CppEditorSupport::updateDocument() ...@@ -282,7 +282,7 @@ void CppEditorSupport::updateDocument()
m_updateDocumentTimer->start(m_updateDocumentInterval); m_updateDocumentTimer->start(m_updateDocumentInterval);
} }
static void parse(QFutureInterface<void> &future, QSharedPointer<BuiltinEditorDocumentParser> updater, static void parse(QFutureInterface<void> &future, BuiltinEditorDocumentParser::Ptr updater,
WorkingCopy workingCopy) WorkingCopy workingCopy)
{ {
future.setProgressRange(0, 1); future.setProgressRange(0, 1);
...@@ -524,8 +524,7 @@ SemanticInfo CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::So ...@@ -524,8 +524,7 @@ SemanticInfo CppEditorSupport::recalculateSemanticInfoNow(const SemanticInfo::So
// Otherwise reprocess document // Otherwise reprocess document
} else { } else {
const QSharedPointer<BuiltinEditorDocumentParser> documentParser const BuiltinEditorDocumentParser::Ptr documentParser = documentParser_internal();
= documentParser_internal();
QTC_ASSERT(documentParser, return newSemanticInfo); QTC_ASSERT(documentParser, return newSemanticInfo);
newSemanticInfo.snapshot = documentParser->snapshot(); newSemanticInfo.snapshot = documentParser->snapshot();
if (!newSemanticInfo.snapshot.contains(source.fileName)) if (!newSemanticInfo.snapshot.contains(source.fileName))
...@@ -584,14 +583,13 @@ void CppEditorSupport::setSemanticInfo(const SemanticInfo &semanticInfo, bool em ...@@ -584,14 +583,13 @@ void CppEditorSupport::setSemanticInfo(const SemanticInfo &semanticInfo, bool em
emit semanticInfoUpdated(semanticInfo); emit semanticInfoUpdated(semanticInfo);
} }
QSharedPointer<BuiltinEditorDocumentParser> CppEditorSupport::documentParser_internal() const BuiltinEditorDocumentParser::Ptr CppEditorSupport::documentParser_internal() const
{ {
QMutexLocker locker(&m_documentParserLock); QMutexLocker locker(&m_documentParserLock);
return m_documentParser; return m_documentParser;
} }
void CppEditorSupport::setDocumentParser_internal( void CppEditorSupport::setDocumentParser_internal(const BuiltinEditorDocumentParser::Ptr &updater)
const QSharedPointer<BuiltinEditorDocumentParser> &updater)
{ {
QMutexLocker locker(&m_documentParserLock); QMutexLocker locker(&m_documentParserLock);
m_documentParser = updater; m_documentParser = updater;
......
...@@ -133,7 +133,7 @@ public: ...@@ -133,7 +133,7 @@ public:
CppCompletionAssistProvider *completionAssistProvider() const; CppCompletionAssistProvider *completionAssistProvider() const;
QSharedPointer<BuiltinEditorDocumentParser> documentParser(); BuiltinEditorDocumentParser::Ptr documentParser();
/// Checks whether the document is (re)parsed or about to be (re)parsed. /// Checks whether the document is (re)parsed or about to be (re)parsed.
bool isUpdatingDocument(); bool isUpdatingDocument();
...@@ -202,8 +202,8 @@ private: ...@@ -202,8 +202,8 @@ private:
SemanticInfo semanticInfo() const; SemanticInfo semanticInfo() const;
void setSemanticInfo(const SemanticInfo &semanticInfo, bool emitSignal = true); void setSemanticInfo(const SemanticInfo &semanticInfo, bool emitSignal = true);
QSharedPointer<BuiltinEditorDocumentParser> documentParser_internal() const; BuiltinEditorDocumentParser::Ptr documentParser_internal() const;
void setDocumentParser_internal(const QSharedPointer<BuiltinEditorDocumentParser> &updater); void setDocumentParser_internal(const BuiltinEditorDocumentParser::Ptr &updater);
private: private:
Internal::CppModelManager *m_modelManager; Internal::CppModelManager *m_modelManager;
...@@ -234,7 +234,7 @@ private: ...@@ -234,7 +234,7 @@ private:
SemanticInfo m_lastSemanticInfo; SemanticInfo m_lastSemanticInfo;
QFuture<void> m_futureSemanticInfo; QFuture<void> m_futureSemanticInfo;
mutable QMutex m_documentParserLock; mutable QMutex m_documentParserLock;
QSharedPointer<BuiltinEditorDocumentParser> m_documentParser; BuiltinEditorDocumentParser::Ptr m_documentParser;
QFuture<void> m_documentParserFuture; QFuture<void> m_documentParserFuture;
// Highlighting: // Highlighting:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment