Clang: Don't analyze same file multiple times

Diagnostics do not depend much on project parts. But
having the same file twice can result in duplicated
diagnostics which later can cause the same fix-it
being applied twice and getting corrupted code.

Change-Id: Ie2809af7a54034b05df9383875f7c3123aea58e8
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-06-28 10:16:48 +02:00
parent 66a271a150
commit be3e848c0f
4 changed files with 19 additions and 7 deletions

View File

@@ -36,12 +36,24 @@ namespace Internal {
class FileInfo
{
public:
FileInfo() = default;
FileInfo(Utils::FileName file,
CppTools::ProjectFile::Kind kind,
CppTools::ProjectPart::Ptr projectPart)
: file(std::move(file))
, kind(kind)
, projectPart(projectPart)
{}
Utils::FileName file;
CppTools::ProjectFile::Kind kind;
CppTools::ProjectPart::Ptr projectPart;
};
using FileInfos = QVector<FileInfo>;
inline bool operator==(const FileInfo &lhs, const FileInfo &rhs) {
return lhs.file == rhs.file;
}
using FileInfos = std::vector<FileInfo>;
} // namespace Internal
} // namespace ClangTools

View File

@@ -155,7 +155,7 @@ public:
return false;
if (!node->isDir)
result += static_cast<TreeWithFileInfo *>(node)->info;
result.push_back(static_cast<TreeWithFileInfo *>(node)->info);
return true;
});
@@ -194,7 +194,7 @@ private:
Tree *projectDirTree = buildProjectDirTree(project->projectDirectory(),
fileInfos,
outOfBaseDirFiles);
if (outOfBaseDirFiles.isEmpty()) {
if (outOfBaseDirFiles.empty()) {
// Showing the project file and beneath the project dir is pointless in this case,
// so get rid of the root node and modify the project dir node as the new root node.
projectDirTree->name = m_root->name;
@@ -229,7 +229,7 @@ private:
for (const FileInfo &fileInfo : fileInfos) {
if (!fileInfo.file.isChildOf(projectDirNode->fullPath)) {
outOfBaseDirFiles += fileInfo;
outOfBaseDirFiles.push_back(fileInfo);
continue; // Handle these separately.
}

View File

@@ -333,7 +333,7 @@ void ClangTidyClazyTool::startTool(bool askUserForFileSelection)
QTC_ASSERT(project, return);
const FileInfos fileInfos = collectFileInfos(project, askUserForFileSelection);
if (fileInfos.isEmpty())
if (fileInfos.empty())
return;
auto clangTool = new ClangTidyClazyRunControl(runControl,

View File

@@ -78,13 +78,13 @@ static FileInfos sortedFileInfos(const QVector<CppTools::ProjectPart::Ptr> &proj
continue;
if (CppTools::ProjectFile::isSource(file.kind)) {
const FileInfo info{Utils::FileName::fromString(file.path), file.kind, projectPart};
fileInfos.append(info);
fileInfos.emplace_back(Utils::FileName::fromString(file.path), file.kind, projectPart);
}
}
}
Utils::sort(fileInfos, &FileInfo::file);
fileInfos.erase(std::unique(fileInfos.begin(), fileInfos.end()), fileInfos.end());
return fileInfos;
}