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>
This commit is contained in:
Nikolai Kosjar
2019-01-07 08:49:01 +01:00
parent 5719e7961e
commit 05c7abf00e

View File

@@ -26,6 +26,7 @@
#include "clangeditordocumentprocessor.h" #include "clangeditordocumentprocessor.h"
#include "clangfollowsymbol.h" #include "clangfollowsymbol.h"
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <texteditor/texteditor.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, void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
::Utils::ProcessLinkCallback &&processLinkCallback, ::Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget, bool resolveTarget,
@@ -194,9 +201,9 @@ void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
m_watcher.reset(new FutureSymbolWatcher()); m_watcher.reset(new FutureSymbolWatcher());
QObject::connect(m_watcher.get(), &FutureSymbolWatcher::finished, QObject::connect(m_watcher.get(), &FutureSymbolWatcher::finished, [=, filePath=data.filePath(),
[=, callback=std::move(processLinkCallback)]() mutable { callback=std::move(processLinkCallback)]() mutable {
if (m_watcher->isCanceled()) if (m_watcher->isCanceled() || !isSameInvocationContext(filePath))
return callback(Utils::Link()); return callback(Utils::Link());
CppTools::SymbolInfo result = m_watcher->result(); CppTools::SymbolInfo result = m_watcher->result();
// We did not fail but the result is empty // We did not fail but the result is empty