forked from qt-creator/qt-creator
CMakePM: Add support for "$ENV{" code completion and help
CMake has a few environment variables that are documented and this commit adds support for them. Change-Id: Iaa31bdc97b343581fcf519d19e66bc6ce8ace150 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -77,6 +77,8 @@ void CMakeEditor::contextHelp(const HelpCallback &callback) const
|
||||
return "prop_gbl/";
|
||||
if (m_keywords.policies.contains(word))
|
||||
return "policy/";
|
||||
if (m_keywords.environmentVariables.contains(word))
|
||||
return "envvar/";
|
||||
|
||||
return "unknown/";
|
||||
};
|
||||
@@ -449,15 +451,16 @@ void CMakeHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget
|
||||
const QMap<QString, Utils::FilePath> ↦
|
||||
QString helpCategory;
|
||||
} keywordsListMaps[] = {{keywords().functions, "command"},
|
||||
{keywords().variables, "variable"},
|
||||
{keywords().directoryProperties, "prop_dir"},
|
||||
{keywords().sourceProperties, "prop_sf"},
|
||||
{keywords().targetProperties, "prop_tgt"},
|
||||
{keywords().testProperties, "prop_test"},
|
||||
{keywords().properties, "prop_gbl"},
|
||||
{keywords().includeStandardModules, "module"},
|
||||
{keywords().findModules, "module"},
|
||||
{keywords().policies, "policy"}};
|
||||
{keywords().variables, "variable"},
|
||||
{keywords().directoryProperties, "prop_dir"},
|
||||
{keywords().sourceProperties, "prop_sf"},
|
||||
{keywords().targetProperties, "prop_tgt"},
|
||||
{keywords().testProperties, "prop_test"},
|
||||
{keywords().properties, "prop_gbl"},
|
||||
{keywords().includeStandardModules, "module"},
|
||||
{keywords().findModules, "module"},
|
||||
{keywords().policies, "policy"},
|
||||
{keywords().environmentVariables, "envvar"}};
|
||||
|
||||
for (const auto &pair : keywordsListMaps) {
|
||||
if (pair.map.contains(word)) {
|
||||
|
||||
@@ -469,7 +469,8 @@ IAssistProposal *CMakeFileCompletionAssist::doPerform(const PerformInputDataPtr
|
||||
QList<AssistProposalItemInterface *> items;
|
||||
|
||||
const QString varGenexToken = interface()->textAt(startPos - 2, 2);
|
||||
if (varGenexToken == "${" || varGenexToken == "$<") {
|
||||
const QString varEnvironmentToken = interface()->textAt(startPos - 5, 5);
|
||||
if (varGenexToken == "${" || varGenexToken == "$<" || varEnvironmentToken == "$ENV{") {
|
||||
if (varGenexToken == "${") {
|
||||
items.append(generateList(data->keywords.variables, m_variableIcon));
|
||||
items.append(generateList(data->projectVariables, m_projectVariableIcon));
|
||||
@@ -478,9 +479,16 @@ IAssistProposal *CMakeFileCompletionAssist::doPerform(const PerformInputDataPtr
|
||||
if (varGenexToken == "$<")
|
||||
items.append(generateList(data->keywords.generatorExpressions, m_genexIcon));
|
||||
|
||||
if (varEnvironmentToken == "$ENV{")
|
||||
items.append(generateList(data->keywords.environmentVariables, m_variableIcon));
|
||||
|
||||
return new GenericProposal(startPos, items);
|
||||
}
|
||||
|
||||
const QString ifEnvironmentToken = interface()->textAt(startPos - 4, 4);
|
||||
if ((functionName == "if" || functionName == "elseif") && ifEnvironmentToken == "ENV{")
|
||||
items.append(generateList(data->keywords.environmentVariables, m_variableIcon));
|
||||
|
||||
int fileStartPos = startPos;
|
||||
const auto onlyFileItems = [&] { return fileStartPos != startPos; };
|
||||
|
||||
@@ -569,13 +577,13 @@ IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor(const Assis
|
||||
|
||||
int CMakeFileCompletionAssistProvider::activationCharSequenceLength() const
|
||||
{
|
||||
return 2;
|
||||
return 4;
|
||||
}
|
||||
|
||||
bool CMakeFileCompletionAssistProvider::isActivationCharSequence(const QString &sequence) const
|
||||
{
|
||||
return sequence.endsWith("${") || sequence.endsWith("$<") || sequence.endsWith("/")
|
||||
|| sequence.endsWith("(");
|
||||
|| sequence.endsWith("(") || sequence.endsWith("ENV{");
|
||||
}
|
||||
|
||||
} // namespace CMakeProjectManager::Internal
|
||||
|
||||
@@ -288,6 +288,8 @@ CMakeKeywords CMakeTool::keywords()
|
||||
{"Help/variable", m_introspection->m_keywords.variables},
|
||||
// Policies
|
||||
{"Help/policy", m_introspection->m_keywords.policies},
|
||||
// Environment Variables
|
||||
{"Help/envvar", m_introspection->m_keywords.environmentVariables},
|
||||
};
|
||||
for (auto &i : introspections) {
|
||||
const FilePaths files = cmakeRoot.pathAppended(i.helpPath)
|
||||
|
||||
@@ -25,6 +25,7 @@ struct CMAKE_EXPORT CMakeKeywords
|
||||
QMap<QString, Utils::FilePath> functions;
|
||||
QMap<QString, Utils::FilePath> properties;
|
||||
QSet<QString> generatorExpressions;
|
||||
QMap<QString, Utils::FilePath> environmentVariables;
|
||||
QMap<QString, Utils::FilePath> directoryProperties;
|
||||
QMap<QString, Utils::FilePath> sourceProperties;
|
||||
QMap<QString, Utils::FilePath> targetProperties;
|
||||
|
||||
Reference in New Issue
Block a user