forked from qt-creator/qt-creator
LanguageClient: Prevent duplicate references due to file aliasing
This problem has been observed with clangd, but it's probably a good idea to apply the check generally. Note that in the case of renaming, omitting the filtering can lead to file corruption. Task-number: QTCREATORBUG-30546 Change-Id: I007edbae2cba5f59e427ab07e183162df9e99367 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
committed by
David Schulz
parent
e3302afd09
commit
5afdc47760
@@ -291,12 +291,17 @@ void ClangdFindReferences::Private::handleFindUsagesResult(const QList<Location>
|
||||
|
||||
for (const Location &loc : locations)
|
||||
fileData[loc.uri()].rangesAndLineText.push_back({loc.range(), {}});
|
||||
QSet<FilePath> canonicalFilePaths;
|
||||
for (auto it = fileData.begin(); it != fileData.end();) {
|
||||
const Utils::FilePath filePath = client()->serverUriToHostPath(it.key());
|
||||
if (!filePath.exists()) { // https://github.com/clangd/clangd/issues/935
|
||||
it = fileData.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (!Utils::insert(canonicalFilePaths, filePath.canonicalPath())) { // QTCREATORBUG-30546
|
||||
it = fileData.erase(it);
|
||||
continue;
|
||||
}
|
||||
const QStringList lines = SymbolSupport::getFileContents(filePath);
|
||||
it->fileContent = lines.join('\n');
|
||||
for (auto &rangeWithText : it.value().rangesAndLineText) {
|
||||
|
||||
Reference in New Issue
Block a user