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