From bbdfd0fb8278dd20ec2d7609437032ed633db375 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Tue, 18 Feb 2014 12:59:57 -0300 Subject: CppTools: Do not block GUI thread for completions The GUI was blocked while waiting for the parsed document. Now the blocking operation is executed in the completion thread. Task-number: QTCREATORBUG-11037 Task-number: QTCREATORBUG-11433 Change-Id: Ia7c1b1b7eea0ba75010ff667ba05273c62c18491 Reviewed-by: hjk --- src/plugins/cpptools/cppcompletionassist.cpp | 43 ++++++++++++++++------------ src/plugins/cpptools/cppcompletionassist.h | 29 +++++++++++++++---- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp index f34c68e07d..c65c0f22ef 100644 --- a/src/plugins/cpptools/cppcompletionassist.cpp +++ b/src/plugins/cpptools/cppcompletionassist.cpp @@ -28,10 +28,13 @@ ****************************************************************************/ #include "cppcompletionassist.h" + +#include "cppdoxygen.h" #include "cppmodelmanager.h" +#include "cppmodelmanagerinterface.h" +#include "cppsnapshotupdater.h" #include "cpptoolsconstants.h" #include "cpptoolseditorsupport.h" -#include "cppdoxygen.h" #include #include @@ -422,24 +425,9 @@ TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInte int position, TextEditor::AssistReason reason) const { Q_UNUSED(project); - - CppModelManagerInterface *modelManager = CppModelManagerInterface::instance(); - - if (CppEditorSupport *supp = modelManager->cppEditorSupport(editor)) { - if (QSharedPointer updater = supp->snapshotUpdater()) { - updater->update(modelManager->workingCopy()); - return new CppTools::Internal::CppCompletionAssistInterface( - document, - position, - editor->document()->filePath(), - reason, - updater->snapshot(), - updater->includePaths(), - updater->frameworkPaths()); - } - } - - return 0; + QTC_ASSERT(editor, return 0); + QTC_ASSERT(document, return 0); + return new CppTools::Internal::CppCompletionAssistInterface(editor, document, position, reason); } // ----------------- @@ -1930,3 +1918,20 @@ bool CppCompletionAssistProcessor::completeConstructorOrFunction(const QListcppEditorSupport(m_editor)) { + if (QSharedPointer updater = supp->snapshotUpdater()) { + updater->update(modelManager->workingCopy()); + m_snapshot = updater->snapshot(); + m_includePaths = updater->includePaths(); + m_frameworkPaths = updater->frameworkPaths(); + } + } +} diff --git a/src/plugins/cpptools/cppcompletionassist.h b/src/plugins/cpptools/cppcompletionassist.h index eb5806ea4f..0e0268b74b 100644 --- a/src/plugins/cpptools/cppcompletionassist.h +++ b/src/plugins/cpptools/cppcompletionassist.h @@ -39,6 +39,7 @@ # include #endif +#include #include #include #include @@ -170,6 +171,16 @@ private: class CppCompletionAssistInterface : public TextEditor::DefaultAssistInterface { public: + CppCompletionAssistInterface(TextEditor::BaseTextEditor *editor, + QTextDocument *textDocument, + int position, + TextEditor::AssistReason reason) + : TextEditor::DefaultAssistInterface(textDocument, position, editor->document()->filePath(), + reason) + , m_editor(editor) + , m_gotCppSpecifics(false) + {} + CppCompletionAssistInterface(QTextDocument *textDocument, int position, const QString &fileName, @@ -178,19 +189,25 @@ public: const QStringList &includePaths, const QStringList &frameworkPaths) : TextEditor::DefaultAssistInterface(textDocument, position, fileName, reason) + , m_editor(0) + , m_gotCppSpecifics(true) , m_snapshot(snapshot) , m_includePaths(includePaths) , m_frameworkPaths(frameworkPaths) {} - const CPlusPlus::Snapshot &snapshot() const { return m_snapshot; } - const QStringList &includePaths() const { return m_includePaths; } - const QStringList &frameworkPaths() const { return m_frameworkPaths; } + const CPlusPlus::Snapshot &snapshot() const { getCppSpecifics(); return m_snapshot; } + const QStringList &includePaths() const { getCppSpecifics(); return m_includePaths; } + const QStringList &frameworkPaths() const { getCppSpecifics(); return m_frameworkPaths; } private: - CPlusPlus::Snapshot m_snapshot; - QStringList m_includePaths; - QStringList m_frameworkPaths; + void getCppSpecifics() const; + + TextEditor::BaseTextEditor *m_editor; + mutable bool m_gotCppSpecifics; + mutable CPlusPlus::Snapshot m_snapshot; + mutable QStringList m_includePaths; + mutable QStringList m_frameworkPaths; }; } // Internal -- cgit v1.2.1