forked from qt-creator/qt-creator
ClangCodeModel: Do not report symbol references from non-existing files
... which we get from clangd's textDocument/references. This works around https://github.com/clangd/clangd/issues/935. Fixes: QTCREATORBUG-26574 Change-Id: I3933f30fdaca024a6e240bd0962de3d97acd0dbf Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -1594,14 +1594,20 @@ void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList<Loca
|
|||||||
|
|
||||||
for (const Location &loc : locations)
|
for (const Location &loc : locations)
|
||||||
refData->fileData[loc.uri()].rangesAndLineText << qMakePair(loc.range(), QString());
|
refData->fileData[loc.uri()].rangesAndLineText << qMakePair(loc.range(), QString());
|
||||||
for (auto it = refData->fileData.begin(); it != refData->fileData.end(); ++it) {
|
for (auto it = refData->fileData.begin(); it != refData->fileData.end();) {
|
||||||
const QStringList lines = SymbolSupport::getFileContents(it.key().toFilePath());
|
const Utils::FilePath filePath = it.key().toFilePath();
|
||||||
|
if (!filePath.exists()) { // https://github.com/clangd/clangd/issues/935
|
||||||
|
it = refData->fileData.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const QStringList lines = SymbolSupport::getFileContents(filePath);
|
||||||
it->fileContent = lines.join('\n');
|
it->fileContent = lines.join('\n');
|
||||||
for (auto &rangeWithText : it.value().rangesAndLineText) {
|
for (auto &rangeWithText : it.value().rangesAndLineText) {
|
||||||
const int lineNo = rangeWithText.first.start().line();
|
const int lineNo = rangeWithText.first.start().line();
|
||||||
if (lineNo >= 0 && lineNo < lines.size())
|
if (lineNo >= 0 && lineNo < lines.size())
|
||||||
rangeWithText.second = lines.at(lineNo);
|
rangeWithText.second = lines.at(lineNo);
|
||||||
}
|
}
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(clangdLog) << "document count is" << refData->fileData.size();
|
qCDebug(clangdLog) << "document count is" << refData->fileData.size();
|
||||||
|
Reference in New Issue
Block a user