2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2010-03-30 12:11:32 +02:00
|
|
|
|
|
|
|
|
#include "cmakeeditor.h"
|
2023-09-20 14:17:18 +02:00
|
|
|
#include "cmaketoolmanager.h"
|
2010-03-30 12:11:32 +02:00
|
|
|
|
2022-07-08 17:07:33 +02:00
|
|
|
#include "cmakeautocompleter.h"
|
2023-09-14 16:22:25 +02:00
|
|
|
#include "cmakebuildsystem.h"
|
2013-08-30 12:55:06 +02:00
|
|
|
#include "cmakefilecompletionassist.h"
|
2015-08-24 08:43:18 +02:00
|
|
|
#include "cmakeindenter.h"
|
2022-07-08 17:07:33 +02:00
|
|
|
#include "cmakeprojectconstants.h"
|
2010-03-30 12:11:32 +02:00
|
|
|
|
2023-09-22 12:29:25 +02:00
|
|
|
#include "3rdparty/cmake/cmListFileCache.h"
|
|
|
|
|
|
2012-02-19 18:58:39 +04:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2023-02-17 23:21:31 +01:00
|
|
|
#include <coreplugin/coreplugintr.h>
|
2023-08-22 18:44:59 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/buildsystem.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
2023-09-18 22:08:23 +02:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
2023-08-22 18:44:59 +02:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2023-09-20 14:17:18 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2023-09-18 22:08:23 +02:00
|
|
|
#include <texteditor/basehoverhandler.h>
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
2010-03-30 12:11:32 +02:00
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
2023-07-04 10:05:33 +02:00
|
|
|
#include <utils/textutils.h>
|
2023-09-18 22:08:23 +02:00
|
|
|
#include <utils/tooltip/tooltip.h>
|
2014-08-20 00:07:43 +02:00
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <QTextDocument>
|
2010-03-30 12:11:32 +02:00
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <functional>
|
2010-03-30 12:11:32 +02:00
|
|
|
|
2014-08-20 00:07:43 +02:00
|
|
|
using namespace Core;
|
2023-08-22 18:44:59 +02:00
|
|
|
using namespace ProjectExplorer;
|
2023-09-18 22:08:23 +02:00
|
|
|
using namespace Utils;
|
2014-08-20 00:07:43 +02:00
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
namespace CMakeProjectManager::Internal {
|
2010-03-30 12:11:32 +02:00
|
|
|
|
|
|
|
|
//
|
2014-08-20 00:07:43 +02:00
|
|
|
// CMakeEditor
|
2010-03-30 12:11:32 +02:00
|
|
|
//
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
class CMakeEditor : public TextEditor::BaseTextEditor
|
|
|
|
|
{
|
2023-09-20 14:17:18 +02:00
|
|
|
CMakeKeywords m_keywords;
|
2022-09-29 15:26:31 +02:00
|
|
|
public:
|
2023-09-20 14:17:18 +02:00
|
|
|
CMakeEditor();
|
2022-09-29 15:26:31 +02:00
|
|
|
void contextHelp(const HelpCallback &callback) const final;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-20 14:17:18 +02:00
|
|
|
CMakeEditor::CMakeEditor()
|
2014-06-17 11:33:58 +02:00
|
|
|
{
|
2023-09-25 23:08:38 +02:00
|
|
|
if (auto tool = CMakeToolManager::defaultProjectOrDefaultCMakeTool())
|
2023-09-20 14:17:18 +02:00
|
|
|
m_keywords = tool->keywords();
|
|
|
|
|
}
|
2014-06-17 11:33:58 +02:00
|
|
|
|
2023-09-20 14:17:18 +02:00
|
|
|
void CMakeEditor::contextHelp(const HelpCallback &callback) const
|
|
|
|
|
{
|
|
|
|
|
auto helpPrefix = [this](const QString &word) {
|
|
|
|
|
if (m_keywords.includeStandardModules.contains(word))
|
|
|
|
|
return "module/";
|
|
|
|
|
if (m_keywords.functions.contains(word))
|
|
|
|
|
return "command/";
|
|
|
|
|
if (m_keywords.variables.contains(word))
|
|
|
|
|
return "variable/";
|
|
|
|
|
if (m_keywords.directoryProperties.contains(word))
|
|
|
|
|
return "prop_dir/";
|
|
|
|
|
if (m_keywords.targetProperties.contains(word))
|
|
|
|
|
return "prop_tgt/";
|
|
|
|
|
if (m_keywords.sourceProperties.contains(word))
|
|
|
|
|
return "prop_sf/";
|
|
|
|
|
if (m_keywords.testProperties.contains(word))
|
|
|
|
|
return "prop_test/";
|
|
|
|
|
if (m_keywords.properties.contains(word))
|
|
|
|
|
return "prop_gbl/";
|
2023-09-20 22:39:50 +02:00
|
|
|
if (m_keywords.policies.contains(word))
|
|
|
|
|
return "policy/";
|
2023-09-20 14:17:18 +02:00
|
|
|
|
|
|
|
|
return "unknown/";
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-21 11:23:03 +02:00
|
|
|
const QString word = Utils::Text::wordUnderCursor(editorWidget()->textCursor());
|
2023-09-20 14:17:18 +02:00
|
|
|
const QString id = helpPrefix(word) + word;
|
|
|
|
|
if (id.startsWith("unknown/")) {
|
2019-08-05 13:40:36 +02:00
|
|
|
BaseTextEditor::contextHelp(callback);
|
2018-01-17 16:06:13 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2014-06-17 11:33:58 +02:00
|
|
|
|
2023-09-21 13:26:54 +02:00
|
|
|
callback({{id, word}, {}, {}, HelpItem::Unknown});
|
2014-06-17 11:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 12:11:32 +02:00
|
|
|
//
|
2014-08-20 00:07:43 +02:00
|
|
|
// CMakeEditorWidget
|
2010-03-30 12:11:32 +02:00
|
|
|
//
|
|
|
|
|
|
2020-01-29 04:15:25 +03:00
|
|
|
class CMakeEditorWidget final : public TextEditorWidget
|
2014-08-22 16:38:38 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2016-08-18 13:20:35 +02:00
|
|
|
~CMakeEditorWidget() final = default;
|
2014-08-22 16:38:38 +02:00
|
|
|
|
|
|
|
|
private:
|
2018-02-21 11:58:16 +01:00
|
|
|
void findLinkAt(const QTextCursor &cursor,
|
2022-06-03 15:17:33 +02:00
|
|
|
const Utils::LinkHandler &processLinkCallback,
|
2018-02-21 11:58:16 +01:00
|
|
|
bool resolveTarget = true,
|
|
|
|
|
bool inNextSplit = false) override;
|
2015-06-01 17:55:31 +02:00
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
2014-08-22 16:38:38 +02:00
|
|
|
};
|
|
|
|
|
|
2012-02-19 18:58:39 +04:00
|
|
|
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|
|
|
|
{
|
2012-07-24 23:30:32 +04:00
|
|
|
showDefaultContextMenu(e, Constants::M_CONTEXT);
|
2012-02-19 18:58:39 +04:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 15:29:08 +02:00
|
|
|
static bool mustBeQuotedInFileName(const QChar &c)
|
2012-02-19 18:58:39 +04:00
|
|
|
{
|
2021-04-12 15:29:08 +02:00
|
|
|
return c.isSpace() || c == '"' || c == '(' || c == ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool isValidFileNameChar(const QString &block, int pos)
|
|
|
|
|
{
|
|
|
|
|
const QChar c = block.at(pos);
|
|
|
|
|
return !mustBeQuotedInFileName(c) || (pos > 0 && block.at(pos - 1) == '\\');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString unescape(const QString &s)
|
|
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
int i = 0;
|
2023-09-21 11:29:23 +02:00
|
|
|
const qsizetype size = s.size();
|
2021-04-12 15:29:08 +02:00
|
|
|
while (i < size) {
|
|
|
|
|
const QChar c = s.at(i);
|
|
|
|
|
if (c == '\\' && i < size - 1) {
|
|
|
|
|
const QChar nc = s.at(i + 1);
|
|
|
|
|
if (mustBeQuotedInFileName(nc)) {
|
|
|
|
|
result += nc;
|
|
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result += c;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2012-02-19 18:58:39 +04:00
|
|
|
}
|
|
|
|
|
|
2023-09-29 18:07:51 +02:00
|
|
|
static bool isValidUrlChar(const QChar &c)
|
|
|
|
|
{
|
|
|
|
|
static QSet<QChar> urlChars{'-', '.', '_', '~', ':', '/', '?', '#', '[', ']', '@', '!',
|
|
|
|
|
'$', '&', '\'', '(', ')', '*', '+', ',', ';', '%', '='};
|
|
|
|
|
|
|
|
|
|
return (c.isLetterOrNumber() || urlChars.contains(c)) && !c.isSpace();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 12:29:25 +02:00
|
|
|
QHash<QString, Utils::Link> getLocalSymbolsHash(const QByteArray &content, const Utils::FilePath &filePath)
|
|
|
|
|
{
|
|
|
|
|
cmListFile cmakeListFile;
|
|
|
|
|
if (!content.isEmpty()) {
|
|
|
|
|
std::string errorString;
|
|
|
|
|
const std::string fileName = "buffer";
|
|
|
|
|
if (!cmakeListFile.ParseString(content.toStdString(), fileName, errorString))
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QHash<QString, Utils::Link> hash;
|
|
|
|
|
for (const auto &func : cmakeListFile.Functions) {
|
|
|
|
|
if (func.LowerCaseName() != "function" && func.LowerCaseName() != "macro"
|
|
|
|
|
&& func.LowerCaseName() != "set" && func.LowerCaseName() != "option")
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (func.Arguments().size() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
auto arg = func.Arguments()[0];
|
|
|
|
|
|
|
|
|
|
Utils::Link link;
|
|
|
|
|
link.targetFilePath = filePath;
|
|
|
|
|
link.targetLine = arg.Line;
|
|
|
|
|
link.targetColumn = arg.Column - 1;
|
|
|
|
|
hash.insert(QString::fromUtf8(arg.Value), link);
|
|
|
|
|
}
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 11:58:16 +01:00
|
|
|
void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
2022-06-03 15:17:33 +02:00
|
|
|
const Utils::LinkHandler &processLinkCallback,
|
2018-02-21 11:58:16 +01:00
|
|
|
bool/* resolveTarget*/,
|
|
|
|
|
bool /*inNextSplit*/)
|
2012-02-19 18:58:39 +04:00
|
|
|
{
|
2017-10-05 09:45:33 +02:00
|
|
|
Utils::Link link;
|
2012-02-19 18:58:39 +04:00
|
|
|
|
2018-11-02 14:17:12 +01:00
|
|
|
int line = 0;
|
|
|
|
|
int column = 0;
|
|
|
|
|
convertPosition(cursor.position(), &line, &column);
|
2012-02-19 18:58:39 +04:00
|
|
|
|
|
|
|
|
const QString block = cursor.block().text();
|
|
|
|
|
|
2023-09-29 18:07:51 +02:00
|
|
|
int beginPos = 0;
|
|
|
|
|
int endPos = 0;
|
|
|
|
|
auto addTextStartEndToLink = [&](Utils::Link &link) {
|
|
|
|
|
link.linkTextStart = cursor.position() - column + beginPos + 1;
|
|
|
|
|
link.linkTextEnd = cursor.position() - column + endPos;
|
|
|
|
|
return link;
|
|
|
|
|
};
|
|
|
|
|
|
2012-02-19 18:58:39 +04:00
|
|
|
// check if the current position is commented out
|
2023-09-21 11:29:23 +02:00
|
|
|
const qsizetype hashPos = block.indexOf(QLatin1Char('#'));
|
2023-09-29 18:07:51 +02:00
|
|
|
if (hashPos >= 0 && hashPos < column) {
|
|
|
|
|
// Check to see if we have a https:// link
|
|
|
|
|
QString buffer;
|
|
|
|
|
beginPos = column - 1;
|
|
|
|
|
while (beginPos > hashPos) {
|
|
|
|
|
if (isValidUrlChar(block[beginPos])) {
|
|
|
|
|
buffer.prepend(block.at(beginPos));
|
|
|
|
|
beginPos--;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// find the end of the url
|
|
|
|
|
endPos = column;
|
|
|
|
|
while (endPos < block.size()) {
|
|
|
|
|
if (isValidUrlChar(block[endPos])) {
|
|
|
|
|
buffer.append(block.at(endPos));
|
|
|
|
|
endPos++;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (buffer.startsWith("http")) {
|
|
|
|
|
link.targetFilePath = FilePath::fromPathPart(buffer);
|
|
|
|
|
addTextStartEndToLink(link);
|
|
|
|
|
return processLinkCallback(link);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 11:58:16 +01:00
|
|
|
return processLinkCallback(link);
|
2023-09-29 18:07:51 +02:00
|
|
|
}
|
2012-02-19 18:58:39 +04:00
|
|
|
|
|
|
|
|
// find the beginning of a filename
|
|
|
|
|
QString buffer;
|
2023-09-29 18:07:51 +02:00
|
|
|
beginPos = column - 1;
|
2012-02-19 18:58:39 +04:00
|
|
|
while (beginPos >= 0) {
|
2021-04-12 15:29:08 +02:00
|
|
|
if (isValidFileNameChar(block, beginPos)) {
|
|
|
|
|
buffer.prepend(block.at(beginPos));
|
2012-02-19 18:58:39 +04:00
|
|
|
beginPos--;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// find the end of a filename
|
2023-09-29 18:07:51 +02:00
|
|
|
endPos = column;
|
2023-06-06 16:58:05 +02:00
|
|
|
while (endPos < block.size()) {
|
2021-04-12 15:29:08 +02:00
|
|
|
if (isValidFileNameChar(block, endPos)) {
|
|
|
|
|
buffer.append(block.at(endPos));
|
2012-02-19 18:58:39 +04:00
|
|
|
endPos++;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buffer.isEmpty())
|
2018-02-21 11:58:16 +01:00
|
|
|
return processLinkCallback(link);
|
2012-02-19 18:58:39 +04:00
|
|
|
|
2023-08-24 18:11:01 +02:00
|
|
|
const Utils::FilePath dir = textDocument()->filePath().absolutePath();
|
2019-07-26 15:09:12 +02:00
|
|
|
buffer.replace("${CMAKE_CURRENT_SOURCE_DIR}", dir.path());
|
|
|
|
|
buffer.replace("${CMAKE_CURRENT_LIST_DIR}", dir.path());
|
2023-08-22 18:44:59 +02:00
|
|
|
|
|
|
|
|
if (auto project = ProjectTree::currentProject()) {
|
|
|
|
|
buffer.replace("${CMAKE_SOURCE_DIR}", project->projectDirectory().path());
|
|
|
|
|
if (auto bs = ProjectTree::currentBuildSystem()) {
|
|
|
|
|
buffer.replace("${CMAKE_BINARY_DIR}", bs->buildConfiguration()->buildDirectory().path());
|
|
|
|
|
|
|
|
|
|
// Get the path suffix from current source dir to project source dir and apply it
|
|
|
|
|
// for the binary dir
|
|
|
|
|
const QString relativePathSuffix = textDocument()
|
|
|
|
|
->filePath()
|
|
|
|
|
.parentDir()
|
|
|
|
|
.relativePathFrom(project->projectDirectory())
|
|
|
|
|
.path();
|
|
|
|
|
buffer.replace("${CMAKE_CURRENT_BINARY_DIR}",
|
|
|
|
|
bs->buildConfiguration()
|
|
|
|
|
->buildDirectory()
|
|
|
|
|
.pathAppended(relativePathSuffix)
|
|
|
|
|
.path());
|
2023-09-14 16:22:25 +02:00
|
|
|
|
|
|
|
|
// Check if the symbols is a user defined function or macro
|
|
|
|
|
const CMakeBuildSystem *cbs = static_cast<const CMakeBuildSystem *>(bs);
|
2023-09-27 20:20:46 +02:00
|
|
|
// Strip variable coating
|
|
|
|
|
if (buffer.startsWith("${") && buffer.endsWith("}"))
|
|
|
|
|
buffer = buffer.mid(2, buffer.size() - 3);
|
|
|
|
|
|
2023-09-15 20:56:29 +02:00
|
|
|
if (cbs->cmakeSymbolsHash().contains(buffer)) {
|
|
|
|
|
link = cbs->cmakeSymbolsHash().value(buffer);
|
2023-09-22 12:29:25 +02:00
|
|
|
addTextStartEndToLink(link);
|
2023-09-15 20:56:29 +02:00
|
|
|
return processLinkCallback(link);
|
|
|
|
|
}
|
2023-08-22 18:44:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-07-26 15:09:12 +02:00
|
|
|
// TODO: Resolve more variables
|
|
|
|
|
|
2023-09-22 12:29:25 +02:00
|
|
|
// Resolve local variables and functions
|
|
|
|
|
auto findFunctionEnd = [cursor, this]() -> int {
|
|
|
|
|
int pos = cursor.position();
|
|
|
|
|
QChar chr;
|
|
|
|
|
do {
|
|
|
|
|
chr = textDocument()->characterAt(--pos);
|
|
|
|
|
} while (pos > 0 && chr != ')');
|
|
|
|
|
return pos;
|
|
|
|
|
};
|
|
|
|
|
auto hash = getLocalSymbolsHash(textDocument()->textAt(0, findFunctionEnd() + 1).toUtf8(),
|
|
|
|
|
textDocument()->filePath());
|
|
|
|
|
|
|
|
|
|
// Strip variable coating
|
|
|
|
|
if (buffer.startsWith("${") && buffer.endsWith("}"))
|
|
|
|
|
buffer = buffer.mid(2, buffer.size() - 3);
|
|
|
|
|
|
|
|
|
|
if (hash.contains(buffer)) {
|
|
|
|
|
link = hash.value(buffer);
|
|
|
|
|
addTextStartEndToLink(link);
|
|
|
|
|
return processLinkCallback(link);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 18:11:01 +02:00
|
|
|
Utils::FilePath fileName = dir.withNewPath(unescape(buffer));
|
|
|
|
|
if (fileName.isRelativePath())
|
|
|
|
|
fileName = dir.pathAppended(fileName.path());
|
|
|
|
|
if (fileName.exists()) {
|
|
|
|
|
if (fileName.isDir()) {
|
|
|
|
|
Utils::FilePath subProject = fileName.pathAppended("CMakeLists.txt");
|
|
|
|
|
if (subProject.exists())
|
2012-02-19 18:58:39 +04:00
|
|
|
fileName = subProject;
|
|
|
|
|
else
|
2018-02-21 11:58:16 +01:00
|
|
|
return processLinkCallback(link);
|
2012-02-19 18:58:39 +04:00
|
|
|
}
|
2023-08-24 18:11:01 +02:00
|
|
|
link.targetFilePath = fileName;
|
2023-09-22 12:29:25 +02:00
|
|
|
addTextStartEndToLink(link);
|
2012-02-19 18:58:39 +04:00
|
|
|
}
|
2023-09-22 12:29:25 +02:00
|
|
|
|
2018-02-21 11:58:16 +01:00
|
|
|
processLinkCallback(link);
|
2012-02-19 18:58:39 +04:00
|
|
|
}
|
|
|
|
|
|
2016-05-30 15:23:52 +02:00
|
|
|
static TextDocument *createCMakeDocument()
|
2010-03-30 12:11:32 +02:00
|
|
|
{
|
2016-05-30 15:23:52 +02:00
|
|
|
auto doc = new TextDocument;
|
|
|
|
|
doc->setId(Constants::CMAKE_EDITOR_ID);
|
2020-04-07 14:44:22 +02:00
|
|
|
doc->setMimeType(QLatin1String(Constants::CMAKE_MIMETYPE));
|
2016-05-30 15:23:52 +02:00
|
|
|
return doc;
|
2010-03-30 12:11:32 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-18 22:08:23 +02:00
|
|
|
//
|
|
|
|
|
// CMakeHoverHandler
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
class CMakeHoverHandler : public TextEditor::BaseHoverHandler
|
|
|
|
|
{
|
|
|
|
|
mutable CMakeKeywords m_keywords;
|
|
|
|
|
QString m_helpToolTip;
|
2023-09-25 23:08:38 +02:00
|
|
|
QString m_contextHelp;
|
2023-09-18 22:08:23 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
const CMakeKeywords &keywords() const;
|
|
|
|
|
|
|
|
|
|
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
|
|
|
|
int pos,
|
|
|
|
|
ReportPriority report) final;
|
|
|
|
|
void operateTooltip(TextEditorWidget *editorWidget, const QPoint &point) final;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const CMakeKeywords &CMakeHoverHandler::keywords() const
|
|
|
|
|
{
|
2023-09-25 23:08:38 +02:00
|
|
|
if (m_keywords.functions.isEmpty())
|
|
|
|
|
if (auto tool = CMakeToolManager::defaultProjectOrDefaultCMakeTool())
|
2023-09-18 22:08:23 +02:00
|
|
|
m_keywords = tool->keywords();
|
|
|
|
|
|
|
|
|
|
return m_keywords;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
|
|
|
|
int pos,
|
|
|
|
|
ReportPriority report)
|
|
|
|
|
{
|
|
|
|
|
const QScopeGuard cleanup([this, report] { report(priority()); });
|
|
|
|
|
|
|
|
|
|
QTextCursor cursor = editorWidget->textCursor();
|
|
|
|
|
cursor.setPosition(pos);
|
|
|
|
|
const QString word = Utils::Text::wordUnderCursor(cursor);
|
|
|
|
|
|
|
|
|
|
FilePath helpFile;
|
2023-09-25 23:08:38 +02:00
|
|
|
QString helpCategory;
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
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"}};
|
|
|
|
|
|
|
|
|
|
for (const auto &pair : keywordsListMaps) {
|
|
|
|
|
if (pair.map.contains(word)) {
|
|
|
|
|
helpFile = pair.map.value(word);
|
|
|
|
|
helpCategory = pair.helpCategory;
|
2023-09-18 22:08:23 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_helpToolTip.clear();
|
|
|
|
|
if (!helpFile.isEmpty())
|
2023-09-25 23:08:38 +02:00
|
|
|
m_helpToolTip = CMakeToolManager::toolTipForRstHelpFile(helpFile);
|
|
|
|
|
|
|
|
|
|
if (auto tool = CMakeToolManager::defaultProjectOrDefaultCMakeTool())
|
|
|
|
|
m_contextHelp = QString("%1/%2/%3")
|
|
|
|
|
.arg(tool->documentationUrl(tool->version(),
|
|
|
|
|
tool->qchFilePath().isEmpty()),
|
|
|
|
|
helpCategory,
|
|
|
|
|
word);
|
2023-09-18 22:08:23 +02:00
|
|
|
|
|
|
|
|
setPriority(m_helpToolTip.isEmpty() ? Priority_Tooltip : Priority_None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeHoverHandler::operateTooltip(TextEditorWidget *editorWidget, const QPoint &point)
|
|
|
|
|
{
|
|
|
|
|
if (!m_helpToolTip.isEmpty())
|
2023-09-25 23:08:38 +02:00
|
|
|
Utils::ToolTip::show(point, m_helpToolTip, Qt::MarkdownText, editorWidget, m_contextHelp);
|
2023-09-18 22:08:23 +02:00
|
|
|
else
|
|
|
|
|
Utils::ToolTip::hide();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 00:07:43 +02:00
|
|
|
//
|
|
|
|
|
// CMakeEditorFactory
|
|
|
|
|
//
|
|
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
CMakeEditorFactory::CMakeEditorFactory()
|
2014-08-20 00:07:43 +02:00
|
|
|
{
|
|
|
|
|
setId(Constants::CMAKE_EDITOR_ID);
|
2023-02-17 23:21:31 +01:00
|
|
|
setDisplayName(::Core::Tr::tr("CMake Editor"));
|
2020-04-07 14:44:22 +02:00
|
|
|
addMimeType(Constants::CMAKE_MIMETYPE);
|
|
|
|
|
addMimeType(Constants::CMAKE_PROJECT_MIMETYPE);
|
2014-08-20 00:07:43 +02:00
|
|
|
|
2022-12-07 15:37:42 +01:00
|
|
|
setEditorCreator([] { return new CMakeEditor; });
|
|
|
|
|
setEditorWidgetCreator([] { return new CMakeEditorWidget; });
|
2016-05-30 15:23:52 +02:00
|
|
|
setDocumentCreator(createCMakeDocument);
|
2019-01-16 09:37:54 +01:00
|
|
|
setIndenterCreator([](QTextDocument *doc) { return new CMakeIndenter(doc); });
|
2015-02-03 09:18:57 +01:00
|
|
|
setUseGenericHighlighter(true);
|
2017-04-24 16:01:14 +02:00
|
|
|
setCommentDefinition(Utils::CommentDefinition::HashStyle);
|
2014-10-15 00:36:39 +02:00
|
|
|
setCodeFoldingSupported(true);
|
2014-08-22 16:38:38 +02:00
|
|
|
|
2015-02-04 17:54:46 +01:00
|
|
|
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider);
|
2022-12-07 15:37:42 +01:00
|
|
|
setAutoCompleterCreator([] { return new CMakeAutoCompleter; });
|
2014-10-01 22:39:47 +02:00
|
|
|
|
2014-09-02 12:25:20 +02:00
|
|
|
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
2023-09-14 16:22:25 +02:00
|
|
|
| TextEditorActionHandler::FollowSymbolUnderCursor
|
|
|
|
|
| TextEditorActionHandler::Format);
|
2014-08-20 00:07:43 +02:00
|
|
|
|
2023-09-18 22:08:23 +02:00
|
|
|
addHoverHandler(new CMakeHoverHandler);
|
|
|
|
|
|
2014-08-20 00:07:43 +02:00
|
|
|
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
2023-09-14 16:22:25 +02:00
|
|
|
contextMenu->addAction(ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR));
|
2014-09-02 12:25:20 +02:00
|
|
|
contextMenu->addSeparator(Context(Constants::CMAKE_EDITOR_ID));
|
2014-08-20 00:07:43 +02:00
|
|
|
contextMenu->addAction(ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION));
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
} // CMakeProjectManager::Internal
|