diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-01-07 08:49:01 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-01-08 14:50:42 +0000 |
commit | 05c7abf00ea35a7c4085945a06313e2f1d1b15a2 (patch) | |
tree | 2fa634eadd209a715a5c0e67104b3d74789bd7fc /src | |
parent | 5719e7961e5f719f7a8faa15e59f823931c6dfca (diff) |
Clang: Stop going to F2 location if invocation context changed
If follow symbol takes longer than expected and the user switched to
another file or mode, abort processing the result in order to avoid
confusion.
Change-Id: I0106d49006d2cfd8c8dad0af66d97cee5e5c36de
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/clangcodemodel/clangfollowsymbol.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/plugins/clangcodemodel/clangfollowsymbol.cpp b/src/plugins/clangcodemodel/clangfollowsymbol.cpp index c430c810c3..e5c66f6c6b 100644 --- a/src/plugins/clangcodemodel/clangfollowsymbol.cpp +++ b/src/plugins/clangcodemodel/clangfollowsymbol.cpp @@ -26,6 +26,7 @@ #include "clangeditordocumentprocessor.h" #include "clangfollowsymbol.h" +#include <coreplugin/editormanager/editormanager.h> #include <cpptools/cppmodelmanager.h> #include <texteditor/texteditor.h> @@ -155,6 +156,12 @@ static ::Utils::ProcessLinkCallback extendedCallback(::Utils::ProcessLinkCallbac }; } +static bool isSameInvocationContext(const Utils::FileName &filePath) +{ + return TextEditor::BaseTextEditor::currentTextEditor()->editorWidget()->isVisible() + && Core::EditorManager::currentDocument()->filePath() == filePath; +} + void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data, ::Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget, @@ -194,9 +201,9 @@ void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data, m_watcher.reset(new FutureSymbolWatcher()); - QObject::connect(m_watcher.get(), &FutureSymbolWatcher::finished, - [=, callback=std::move(processLinkCallback)]() mutable { - if (m_watcher->isCanceled()) + QObject::connect(m_watcher.get(), &FutureSymbolWatcher::finished, [=, filePath=data.filePath(), + callback=std::move(processLinkCallback)]() mutable { + if (m_watcher->isCanceled() || !isSameInvocationContext(filePath)) return callback(Utils::Link()); CppTools::SymbolInfo result = m_watcher->result(); // We did not fail but the result is empty |