aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clangtools/clangtool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/clangtools/clangtool.cpp')
-rw-r--r--src/plugins/clangtools/clangtool.cpp74
1 files changed, 42 insertions, 32 deletions
diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp
index 0928e40e6b..49f389b4f2 100644
--- a/src/plugins/clangtools/clangtool.cpp
+++ b/src/plugins/clangtools/clangtool.cpp
@@ -332,7 +332,7 @@ static FileInfos sortedFileInfos(const QVector<CppTools::ProjectPart::Ptr> &proj
{
FileInfos fileInfos;
- for (CppTools::ProjectPart::Ptr projectPart : projectParts) {
+ for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) {
QTC_ASSERT(projectPart, continue);
if (!projectPart->selectedForBuilding)
continue;
@@ -351,7 +351,16 @@ static FileInfos sortedFileInfos(const QVector<CppTools::ProjectPart::Ptr> &proj
}
}
- Utils::sort(fileInfos, &FileInfo::file);
+ Utils::sort(fileInfos, [](const FileInfo &fi1, const FileInfo &fi2) {
+ if (fi1.file == fi2.file) {
+ // If the same file appears more than once, prefer contexts where the file is
+ // built as part of an application or library to those where it may not be,
+ // e.g. because it is just listed as some sort of resource.
+ return fi1.projectPart->buildTargetType != BuildTargetType::Unknown
+ && fi2.projectPart->buildTargetType == BuildTargetType::Unknown;
+ }
+ return fi1.file < fi2.file;
+ });
fileInfos.erase(std::unique(fileInfos.begin(), fileInfos.end()), fileInfos.end());
return fileInfos;
@@ -367,7 +376,7 @@ static RunSettings runSettings()
return ClangToolsSettings::instance()->runSettings();
}
-static ClangDiagnosticConfig diagnosticConfig(const Core::Id &diagConfigId)
+static ClangDiagnosticConfig diagnosticConfig(const Utils::Id &diagConfigId)
{
const ClangDiagnosticConfigsModel configs = diagnosticConfigsModel();
QTC_ASSERT(configs.hasConfigWithId(diagConfigId), return ClangDiagnosticConfig());
@@ -463,7 +472,7 @@ ClangTool::ClangTool()
// Load diagnostics from file
action = new QAction(this);
action->setIcon(Utils::Icons::OPENFILE_TOOLBAR.icon());
- action->setToolTip(tr("Load Diagnostics from YAML Files exported with \"-export-fixes\"."));
+ action->setToolTip(tr("Load diagnostics from YAML files exported with \"-export-fixes\"."));
connect(action, &QAction::triggered, this, &ClangTool::loadDiagnosticsFromFiles);
m_loadExported = action;
@@ -573,7 +582,7 @@ ClangTool::ClangTool()
menu->addAction(ActionManager::registerAction(action, "ClangTidyClazy.Action"),
Debugger::Constants::G_ANALYZER_TOOLS);
QObject::connect(action, &QAction::triggered, this, [this]() {
- startTool(FileSelection::AskUser);
+ startTool(FileSelectionType::AskUser);
});
QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered);
QObject::connect(m_startAction, &QAction::changed, action, [action, this] {
@@ -581,7 +590,7 @@ ClangTool::ClangTool()
});
QObject::connect(m_startOnCurrentFileAction, &QAction::triggered, this, [this] {
- startTool(FileSelection::CurrentFile);
+ startTool(FileSelectionType::CurrentFile);
});
m_perspective.addToolBarAction(m_startAction);
@@ -639,7 +648,7 @@ static bool continueDespiteReleaseBuild(const QString &toolName)
"<p>%2</p>"
"</body></html>")
.arg(problem, question);
- return CheckableMessageBox::doNotAskAgainQuestion(ICore::mainWindow(),
+ return CheckableMessageBox::doNotAskAgainQuestion(ICore::dialogParent(),
title,
message,
ICore::settings(),
@@ -647,7 +656,6 @@ static bool continueDespiteReleaseBuild(const QString &toolName)
== QDialogButtonBox::Yes;
}
-
void ClangTool::startTool(ClangTool::FileSelection fileSelection,
const RunSettings &runSettings,
const CppTools::ClangDiagnosticConfig &diagnosticConfig)
@@ -686,7 +694,9 @@ void ClangTool::startTool(ClangTool::FileSelection fileSelection,
connect(m_runControl, &RunControl::stopped, this, &ClangTool::onRunControlStopped);
// Run worker
- const bool preventBuild = fileSelection == FileSelection::CurrentFile;
+ const bool preventBuild = holds_alternative<FilePath>(fileSelection)
+ || get<FileSelectionType>(fileSelection)
+ == FileSelectionType::CurrentFile;
const bool buildBeforeAnalysis = !preventBuild && runSettings.buildBeforeAnalysis();
m_runWorker = new ClangToolRunWorker(m_runControl,
runSettings,
@@ -716,7 +726,6 @@ void ClangTool::startTool(ClangTool::FileSelection fileSelection,
Diagnostics ClangTool::read(OutputFileFormat outputFileFormat,
const QString &logFilePath,
- const QString &mainFilePath,
const QSet<FilePath> &projectFiles,
QString *errorMessage) const
{
@@ -729,23 +738,27 @@ Diagnostics ClangTool::read(OutputFileFormat outputFileFormat,
acceptFromFilePath,
errorMessage);
}
- return readSerializedDiagnostics(Utils::FilePath::fromString(logFilePath),
- Utils::FilePath::fromString(mainFilePath),
- acceptFromFilePath,
- errorMessage);
+
+ return {};
}
FileInfos ClangTool::collectFileInfos(Project *project, FileSelection fileSelection)
{
+ FileSelectionType *selectionType = get_if<FileSelectionType>(&fileSelection);
+ // early bailout
+ if (selectionType && *selectionType == FileSelectionType::CurrentFile
+ && !EditorManager::currentDocument())
+ return {};
+
auto projectInfo = CppTools::CppModelManager::instance()->projectInfo(project);
QTC_ASSERT(projectInfo.isValid(), return FileInfos());
const FileInfos allFileInfos = sortedFileInfos(projectInfo.projectParts());
- if (fileSelection == FileSelection::AllFiles)
+ if (selectionType && *selectionType == FileSelectionType::AllFiles)
return allFileInfos;
- if (fileSelection == FileSelection::AskUser) {
+ if (selectionType && *selectionType == FileSelectionType::AskUser) {
static int initialProviderIndex = 0;
SelectableFilesDialog dialog(projectInfo,
fileInfoProviders(project, allFileInfos),
@@ -756,18 +769,15 @@ FileInfos ClangTool::collectFileInfos(Project *project, FileSelection fileSelect
return dialog.fileInfos();
}
- if (fileSelection == FileSelection::CurrentFile) {
- if (const IDocument *document = EditorManager::currentDocument()) {
- const Utils::FilePath filePath = document->filePath();
- if (!filePath.isEmpty()) {
- const FileInfo fileInfo = Utils::findOrDefault(allFileInfos,
- [&](const FileInfo &fi) {
- return fi.file == filePath;
- });
- if (!fileInfo.file.isEmpty())
- return {fileInfo};
- }
- }
+ const FilePath filePath = holds_alternative<FilePath>(fileSelection)
+ ? get<FilePath>(fileSelection)
+ : EditorManager::currentDocument()->filePath(); // see early bailout
+ if (!filePath.isEmpty()) {
+ const FileInfo fileInfo = Utils::findOrDefault(allFileInfos, [&](const FileInfo &fi) {
+ return fi.file == filePath;
+ });
+ if (!fileInfo.file.isEmpty())
+ return {fileInfo};
}
return {};
@@ -790,7 +800,7 @@ void ClangTool::loadDiagnosticsFromFiles()
{
// Ask user for files
const QStringList filePaths
- = QFileDialog::getOpenFileNames(Core::ICore::mainWindow(),
+ = QFileDialog::getOpenFileNames(Core::ICore::dialogParent(),
tr("Select YAML Files with Diagnostics"),
QDir::homePath(),
tr("YAML Files (*.yml *.yaml);;All Files (*)"));
@@ -869,13 +879,13 @@ void ClangTool::reset()
static bool canAnalyzeProject(Project *project)
{
if (const Target *target = project->activeTarget()) {
- const Core::Id c = ProjectExplorer::Constants::C_LANGUAGE_ID;
- const Core::Id cxx = ProjectExplorer::Constants::CXX_LANGUAGE_ID;
+ const Utils::Id c = ProjectExplorer::Constants::C_LANGUAGE_ID;
+ const Utils::Id cxx = ProjectExplorer::Constants::CXX_LANGUAGE_ID;
const bool projectSupportsLanguage = project->projectLanguages().contains(c)
|| project->projectLanguages().contains(cxx);
return projectSupportsLanguage
&& CppModelManager::instance()->projectInfo(project).isValid()
- && ToolChainKitAspect::toolChain(target->kit(), cxx);
+ && ToolChainKitAspect::cxxToolChain(target->kit());
}
return false;
}