CMakePM: Allow code completion for CMake files without a project

By taking the default CMake tool in Qt Creator. Similar to the editor.

Change-Id: Id1effa3c4f71dc59dcf940f0fc246aa87c9ba0f7
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Cristian Adam
2023-09-21 13:36:17 +02:00
parent 18a3a55d95
commit d88c270aaf

View File

@@ -9,6 +9,7 @@
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include "cmaketool.h"
#include "cmaketoolmanager.h"
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>
@@ -197,12 +198,16 @@ IAssistProposal *CMakeFileCompletionAssist::performAsync()
Project *project = nullptr;
const FilePath &filePath = interface()->filePath();
if (!filePath.isEmpty() && filePath.isFile()) {
CMakeTool *cmake = nullptr;
project = static_cast<CMakeProject *>(ProjectManager::projectForFile(filePath));
if (project && project->activeTarget()) {
CMakeTool *cmake = CMakeKitAspect::cmakeTool(project->activeTarget()->kit());
if (cmake && cmake->isValid())
keywords = cmake->keywords();
}
if (project && project->activeTarget())
cmake = CMakeKitAspect::cmakeTool(project->activeTarget()->kit());
if (!cmake)
cmake = CMakeToolManager::defaultCMakeTool();
if (cmake && cmake->isValid())
keywords = cmake->keywords();
}
QStringList buildTargets;