forked from qt-creator/qt-creator
CMakePM: Jump to function/macro/option definitions in CMake editor
Fixes: QTCREATORBUG-25523 Change-Id: If9ab6651a858e5fa08e8a1c321cb1f757831e14a Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -1141,6 +1141,7 @@ void CMakeBuildSystem::handleParsingSucceeded(bool restoredFromBackup)
|
|||||||
});
|
});
|
||||||
m_buildTargets += m_reader.takeBuildTargets(errorMessage);
|
m_buildTargets += m_reader.takeBuildTargets(errorMessage);
|
||||||
m_cmakeFiles = m_reader.takeCMakeFileInfos(errorMessage);
|
m_cmakeFiles = m_reader.takeCMakeFileInfos(errorMessage);
|
||||||
|
setupCMakeSymbolsHash();
|
||||||
|
|
||||||
checkAndReportError(errorMessage);
|
checkAndReportError(errorMessage);
|
||||||
}
|
}
|
||||||
@@ -1245,6 +1246,29 @@ void CMakeBuildSystem::wireUpConnections()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMakeBuildSystem::setupCMakeSymbolsHash()
|
||||||
|
{
|
||||||
|
m_cmakeSymbolsHash.clear();
|
||||||
|
|
||||||
|
for (const auto &cmakeFile : std::as_const(m_cmakeFiles)) {
|
||||||
|
for (const auto &func : cmakeFile.cmakeListFile.Functions) {
|
||||||
|
if (func.LowerCaseName() != "function" && func.LowerCaseName() != "macro"
|
||||||
|
&& func.LowerCaseName() != "option")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (func.Arguments().size() == 0)
|
||||||
|
continue;
|
||||||
|
auto arg = func.Arguments()[0];
|
||||||
|
|
||||||
|
Utils::Link link;
|
||||||
|
link.targetFilePath = cmakeFile.path;
|
||||||
|
link.targetLine = arg.Line;
|
||||||
|
link.targetColumn = arg.Column - 1;
|
||||||
|
m_cmakeSymbolsHash.insert(QString::fromUtf8(arg.Value), link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CMakeBuildSystem::ensureBuildDirectory(const BuildDirParameters ¶meters)
|
void CMakeBuildSystem::ensureBuildDirectory(const BuildDirParameters ¶meters)
|
||||||
{
|
{
|
||||||
const FilePath bdir = parameters.buildDirectory;
|
const FilePath bdir = parameters.buildDirectory;
|
||||||
|
@@ -18,7 +18,10 @@ namespace ProjectExplorer {
|
|||||||
class ExtraCompiler;
|
class ExtraCompiler;
|
||||||
class FolderNode;
|
class FolderNode;
|
||||||
}
|
}
|
||||||
namespace Utils { class Process; }
|
namespace Utils {
|
||||||
|
class Process;
|
||||||
|
class Link;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
|
|
||||||
@@ -115,6 +118,8 @@ public:
|
|||||||
QString error() const;
|
QString error() const;
|
||||||
QString warning() const;
|
QString warning() const;
|
||||||
|
|
||||||
|
const QHash<QString, Utils::Link> &cmakeSymbolsHash() const { return m_cmakeSymbolsHash; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void configurationCleared();
|
void configurationCleared();
|
||||||
void configurationChanged(const CMakeConfig &config);
|
void configurationChanged(const CMakeConfig &config);
|
||||||
@@ -190,6 +195,8 @@ private:
|
|||||||
|
|
||||||
void runCTest();
|
void runCTest();
|
||||||
|
|
||||||
|
void setupCMakeSymbolsHash();
|
||||||
|
|
||||||
struct ProjectFileArgumentPosition
|
struct ProjectFileArgumentPosition
|
||||||
{
|
{
|
||||||
cmListFileArgument argumentPosition;
|
cmListFileArgument argumentPosition;
|
||||||
@@ -215,6 +222,7 @@ private:
|
|||||||
QList<ProjectExplorer::ExtraCompiler *> m_extraCompilers;
|
QList<ProjectExplorer::ExtraCompiler *> m_extraCompilers;
|
||||||
QList<CMakeBuildTarget> m_buildTargets;
|
QList<CMakeBuildTarget> m_buildTargets;
|
||||||
QSet<CMakeFileInfo> m_cmakeFiles;
|
QSet<CMakeFileInfo> m_cmakeFiles;
|
||||||
|
QHash<QString, Utils::Link> m_cmakeSymbolsHash;
|
||||||
|
|
||||||
QHash<QString, ProjectFileArgumentPosition> m_filesToBeRenamed;
|
QHash<QString, ProjectFileArgumentPosition> m_filesToBeRenamed;
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "cmakeeditor.h"
|
#include "cmakeeditor.h"
|
||||||
|
|
||||||
#include "cmakeautocompleter.h"
|
#include "cmakeautocompleter.h"
|
||||||
|
#include "cmakebuildsystem.h"
|
||||||
#include "cmakefilecompletionassist.h"
|
#include "cmakefilecompletionassist.h"
|
||||||
#include "cmakeindenter.h"
|
#include "cmakeindenter.h"
|
||||||
#include "cmakeprojectconstants.h"
|
#include "cmakeprojectconstants.h"
|
||||||
@@ -206,6 +207,11 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
->buildDirectory()
|
->buildDirectory()
|
||||||
.pathAppended(relativePathSuffix)
|
.pathAppended(relativePathSuffix)
|
||||||
.path());
|
.path());
|
||||||
|
|
||||||
|
// Check if the symbols is a user defined function or macro
|
||||||
|
const CMakeBuildSystem *cbs = static_cast<const CMakeBuildSystem *>(bs);
|
||||||
|
if (cbs->cmakeSymbolsHash().contains(buffer))
|
||||||
|
return processLinkCallback(cbs->cmakeSymbolsHash().value(buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Resolve more variables
|
// TODO: Resolve more variables
|
||||||
@@ -259,11 +265,11 @@ CMakeEditorFactory::CMakeEditorFactory()
|
|||||||
setAutoCompleterCreator([] { return new CMakeAutoCompleter; });
|
setAutoCompleterCreator([] { return new CMakeAutoCompleter; });
|
||||||
|
|
||||||
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
|
||||||
| TextEditorActionHandler::JumpToFileUnderCursor
|
| TextEditorActionHandler::FollowSymbolUnderCursor
|
||||||
| TextEditorActionHandler::Format);
|
| TextEditorActionHandler::Format);
|
||||||
|
|
||||||
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
||||||
contextMenu->addAction(ActionManager::command(TextEditor::Constants::JUMP_TO_FILE_UNDER_CURSOR));
|
contextMenu->addAction(ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR));
|
||||||
contextMenu->addSeparator(Context(Constants::CMAKE_EDITOR_ID));
|
contextMenu->addSeparator(Context(Constants::CMAKE_EDITOR_ID));
|
||||||
contextMenu->addAction(ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION));
|
contextMenu->addAction(ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user