summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2014-02-18 12:59:57 -0300
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-02-21 17:46:35 +0100
commitbbdfd0fb8278dd20ec2d7609437032ed633db375 (patch)
tree8fcff77bf293ef8897326bf4c74d26c7b14928f9
parentc0eaed863025543bd36268df7b588576d5696dd1 (diff)
downloadqt-creator-bbdfd0fb8278dd20ec2d7609437032ed633db375.tar.gz
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 <hjk121@nokiamail.com>
-rw-r--r--src/plugins/cpptools/cppcompletionassist.cpp43
-rw-r--r--src/plugins/cpptools/cppcompletionassist.h29
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 <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
@@ -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<SnapshotUpdater> 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 QList<CPl
return false;
}
+
+void CppCompletionAssistInterface::getCppSpecifics() const
+{
+ if (m_gotCppSpecifics)
+ return;
+ m_gotCppSpecifics = true;
+
+ CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
+ if (CppEditorSupport *supp = modelManager->cppEditorSupport(m_editor)) {
+ if (QSharedPointer<SnapshotUpdater> 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 <cplusplus/Symbol.h>
#endif
+#include <texteditor/basetexteditor.h>
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
#include <texteditor/codeassist/defaultassistinterface.h>
#include <texteditor/codeassist/iassistprocessor.h>
@@ -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