forked from qt-creator/qt-creator
Clang: Use follow symbol result from clang when global fails
When built-in code model fails to follow symbol under cursor fall back to the clang result even if it only follows to the decalration. Change-Id: I22d8c5fee6ab7594b1d1b7ce8104414db28383c7 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -140,6 +140,19 @@ static Utils::Link linkAtCursor(const QTextCursor &cursor,
|
||||
return Link();
|
||||
}
|
||||
|
||||
static ::Utils::ProcessLinkCallback extendedCallback(::Utils::ProcessLinkCallback &&callback,
|
||||
const CppTools::SymbolInfo &result)
|
||||
{
|
||||
// If globalFollowSymbol finds nothing follow to the declaration.
|
||||
return [original_callback = std::move(callback), result](const ::Utils::Link &link) {
|
||||
if (!link.hasValidTarget() && result.isPureDeclarationForUsage) {
|
||||
return original_callback(::Utils::Link(result.fileName, result.startLine,
|
||||
result.startColumn - 1));
|
||||
}
|
||||
return original_callback(link);
|
||||
};
|
||||
}
|
||||
|
||||
void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
||||
::Utils::ProcessLinkCallback &&processLinkCallback,
|
||||
bool resolveTarget,
|
||||
@@ -185,11 +198,11 @@ void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
||||
return callback(Utils::Link());
|
||||
CppTools::SymbolInfo result = m_watcher->result();
|
||||
// We did not fail but the result is empty
|
||||
if (result.fileName.isEmpty()) {
|
||||
if (result.fileName.isEmpty() || result.isPureDeclarationForUsage) {
|
||||
const CppTools::RefactoringEngineInterface &refactoringEngine
|
||||
= *CppTools::CppModelManager::instance();
|
||||
refactoringEngine.globalFollowSymbol(data,
|
||||
std::move(callback),
|
||||
extendedCallback(std::move(callback), result),
|
||||
snapshot,
|
||||
documentFromSemanticInfo,
|
||||
symbolFinder,
|
||||
|
||||
Reference in New Issue
Block a user