From d88c270aaf4f6a00b1d40d5cee28f84709e6539f Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 21 Sep 2023 13:36:17 +0200 Subject: [PATCH] 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 --- .../cmakefilecompletionassist.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp b/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp index b32ae13d9ab..1a1f9d57367 100644 --- a/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp +++ b/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp @@ -9,6 +9,7 @@ #include "cmakeproject.h" #include "cmakeprojectconstants.h" #include "cmaketool.h" +#include "cmaketoolmanager.h" #include #include @@ -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(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;