CMakePM: Allow navigation to project targets

They were available via Ctrl-K and "cmo <target_name>". But they should
be working also in the text editor.

Change-Id: Iaad72b784485364776b67d6dfdef7ba73dd2df70
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2023-09-27 18:47:16 +02:00
parent d915e22adb
commit d08f1c6e94

View File

@@ -1309,10 +1309,39 @@ void CMakeBuildSystem::setupCMakeSymbolsHash()
}
};
// Handle project targets, unfortunately the CMake file-api doesn't deliver the
// column of the target, just the line. Make sure to find it out
QHash<FilePath, int> projectTargetsSourceAndLine;
for (const auto &target : std::as_const(buildTargets())) {
if (target.targetType == TargetType::UtilityType)
continue;
if (target.backtrace.isEmpty())
continue;
projectTargetsSourceAndLine.insert(target.backtrace.last().path,
target.backtrace.last().line);
}
auto handleProjectTargets = [&](const CMakeFileInfo &cmakeFile, const cmListFileFunction &func) {
if (!projectTargetsSourceAndLine.contains(cmakeFile.path)
|| projectTargetsSourceAndLine.value(cmakeFile.path) != func.Line())
return;
if (func.Arguments().size() == 0)
return;
auto arg = func.Arguments()[0];
Utils::Link link;
link.targetFilePath = cmakeFile.path;
link.targetLine = arg.Line;
link.targetColumn = arg.Column - 1;
m_cmakeSymbolsHash.insert(QString::fromUtf8(arg.Value), link);
};
for (const auto &cmakeFile : std::as_const(m_cmakeFiles)) {
for (const auto &func : cmakeFile.cmakeListFile.Functions) {
handleFunctionMacroOption(cmakeFile, func);
handleImportedTargets(cmakeFile, func);
handleProjectTargets(cmakeFile, func);
}
}
}