From a51380c2fdff6a7f80b25d13de0a643c36eef5b1 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 20 Sep 2023 22:39:50 +0200 Subject: [PATCH] CMakePM: Add policy support for help and code completion Change-Id: I82d291639fe890602bba61eded9d1dfd7d38ca41 Reviewed-by: Alessandro Portale --- src/plugins/cmakeprojectmanager/cmakeeditor.cpp | 2 ++ .../cmakeprojectmanager/cmakefilecompletionassist.cpp | 3 +++ src/plugins/cmakeprojectmanager/cmaketool.cpp | 7 +++++++ src/plugins/cmakeprojectmanager/cmaketool.h | 1 + 4 files changed, 13 insertions(+) diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 1d6fbf0e2a2..57aaf49f2a1 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -78,6 +78,8 @@ void CMakeEditor::contextHelp(const HelpCallback &callback) const return "prop_test/"; if (m_keywords.properties.contains(word)) return "prop_gbl/"; + if (m_keywords.policies.contains(word)) + return "policy/"; return "unknown/"; }; diff --git a/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp b/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp index 92abd32f510..b32ae13d9ab 100644 --- a/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp +++ b/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp @@ -264,6 +264,9 @@ IAssistProposal *CMakeFileCompletionAssist::performAsync() items.append(generateList(projectKeywords.variables, m_projectVariableIcon)); } + if (functionName == "if" || functionName == "elseif" || functionName == "cmake_policy") + items.append(generateList(keywords.policies, m_variableIcon)); + if (functionName.contains("path") || functionName.contains("file") || functionName.contains("add_executable") || functionName.contains("add_library") || functionName == "include" || functionName == "add_subdirectory" diff --git a/src/plugins/cmakeprojectmanager/cmaketool.cpp b/src/plugins/cmakeprojectmanager/cmaketool.cpp index f992a82bfbb..22e980cd9c0 100644 --- a/src/plugins/cmakeprojectmanager/cmaketool.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketool.cpp @@ -100,6 +100,7 @@ public: QStringList m_testProperties; QStringList m_includeStandardModules; QStringList m_findModules; + QStringList m_policies; CMakeTool::Version m_version; }; @@ -276,6 +277,11 @@ CMakeKeywords CMakeTool::keywords() Utils::sort(m_introspection->m_variables); } + runCMake(proc, {"--help-policy-list"}, 5); + if (proc.result() == ProcessResult::FinishedWithSuccess) + m_introspection->m_policies = Utils::filtered(proc.cleanedStdOut().split('\n'), + std::not_fn(&QString::isEmpty)); + parseSyntaxHighlightingXml(); } @@ -291,6 +297,7 @@ CMakeKeywords CMakeTool::keywords() keywords.testProperties = Utils::toSet(m_introspection->m_testProperties); keywords.includeStandardModules = Utils::toSet(m_introspection->m_includeStandardModules); keywords.findModules = Utils::toSet(m_introspection->m_findModules); + keywords.policies = Utils::toSet(m_introspection->m_policies); return keywords; } diff --git a/src/plugins/cmakeprojectmanager/cmaketool.h b/src/plugins/cmakeprojectmanager/cmaketool.h index 7a1b8fbc828..0ad9780971b 100644 --- a/src/plugins/cmakeprojectmanager/cmaketool.h +++ b/src/plugins/cmakeprojectmanager/cmaketool.h @@ -31,6 +31,7 @@ struct CMAKE_EXPORT CMakeKeywords QSet testProperties; QSet includeStandardModules; QSet findModules; + QSet policies; QMap functionArgs; };