ClangCodeModel: Clean file paths resulting from "follow symbol"

Apparently, libclang can give us non-cleaned paths, which we never
noticed until ea215d612d.
We also restore the previous behavior of TextDocument::setFilePath() in
order to prevent similar regressions elsewhere.

Fixes: QTCREATORBUG-26561
Change-Id: I218ed29600e9fb6b299aa2ba0b9d1464f475c06b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2021-11-11 16:11:00 +01:00
parent 95e8afabba
commit 76d3ffa57a
2 changed files with 6 additions and 5 deletions

View File

@@ -155,9 +155,10 @@ static ::Utils::ProcessLinkCallback extendedCallback(::Utils::ProcessLinkCallbac
// If globalFollowSymbol finds nothing follow to the declaration. // If globalFollowSymbol finds nothing follow to the declaration.
return [original_callback = std::move(callback), result](const ::Utils::Link &link) { return [original_callback = std::move(callback), result](const ::Utils::Link &link) {
if (link.linkTextStart < 0 && result.isResultOnlyForFallBack) { if (link.linkTextStart < 0 && result.isResultOnlyForFallBack) {
return original_callback(::Utils::Link(::Utils::FilePath::fromString(result.fileName), return original_callback(Utils::Link(
result.startLine, Utils::FilePath::fromString(result.fileName).cleanPath(),
result.startColumn - 1)); result.startLine,
result.startColumn - 1));
} }
return original_callback(link); return original_callback(link);
}; };
@@ -242,7 +243,7 @@ void ClangFollowSymbol::findLink(const CppEditor::CursorInEditor &data,
symbolFinder, symbolFinder,
inNextSplit); inNextSplit);
} else { } else {
callback(Link(Utils::FilePath::fromString(result.fileName), callback(Link(Utils::FilePath::fromString(result.fileName).cleanPath(),
result.startLine, result.startLine,
result.startColumn - 1)); result.startColumn - 1));
} }

View File

@@ -651,7 +651,7 @@ void TextDocument::setFilePath(const Utils::FilePath &newName)
{ {
if (newName == filePath()) if (newName == filePath())
return; return;
IDocument::setFilePath(newName.absoluteFilePath()); IDocument::setFilePath(newName.absoluteFilePath().cleanPath());
} }
IDocument::ReloadBehavior TextDocument::reloadBehavior(ChangeTrigger state, ChangeType type) const IDocument::ReloadBehavior TextDocument::reloadBehavior(ChangeTrigger state, ChangeType type) const