From 4e90ca1b59a3ed3e4abbac81d47d752de569cd60 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 27 Sep 2023 13:01:18 +0200 Subject: [PATCH] CMakeToolManager: Add static readFirstParagraphs() Reuse it in CMakeEditor and CMakeFileCompletionAssistProvider. Amends d04585b519f51b47cfc4200a048acc416c187b86 Change-Id: I8dbd59c815e017404ff215ca1ff68740d6653e91 Reviewed-by: Cristian Adam --- src/plugins/cmakeprojectmanager/cmakeeditor.cpp | 5 +---- .../cmakefilecompletionassist.cpp | 16 +--------------- .../cmakeprojectmanager/cmaketoolmanager.cpp | 15 +++++++++++++++ .../cmakeprojectmanager/cmaketoolmanager.h | 2 ++ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 1f1e873be52..9b363faebe3 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -9,7 +9,6 @@ #include "cmakefilecompletionassist.h" #include "cmakeindenter.h" #include "cmakekitaspect.h" -#include "cmakeproject.h" #include "cmakeprojectconstants.h" #include "3rdparty/cmake/cmListFileCache.h" @@ -347,8 +346,6 @@ const CMakeKeywords &CMakeHoverHandler::keywords() const return m_keywords; } -QString readFirstParagraphs(const QString &element, const FilePath &helpFile); - void CMakeHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos, ReportPriority report) @@ -377,7 +374,7 @@ void CMakeHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget } m_helpToolTip.clear(); if (!helpFile.isEmpty()) - m_helpToolTip = readFirstParagraphs(word, helpFile); + m_helpToolTip = CMakeToolManager::readFirstParagraphs(helpFile); setPriority(m_helpToolTip.isEmpty() ? Priority_Tooltip : Priority_None); } diff --git a/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp b/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp index 62cc290aa8d..f8d7bb7a3b1 100644 --- a/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp +++ b/src/plugins/cmakeprojectmanager/cmakefilecompletionassist.cpp @@ -153,20 +153,6 @@ static QList generateList(const T &words, const Q }); } -static QString readFirstParagraphs(const FilePath &helpFile) -{ - static QMap map; - if (map.contains(helpFile)) - return map.value(helpFile); - - auto content = helpFile.fileContents(1024).value_or(QByteArray()); - const QString firstParagraphs - = QString("```\n%1\n```").arg(QString::fromUtf8(content.left(content.lastIndexOf("\n")))); - - map[helpFile] = firstParagraphs; - return firstParagraphs; -} - static QList generateList(const QMap &words, const QIcon &icon) { @@ -180,7 +166,7 @@ static QList generateList(const QMapsetText(it.key()); if (!it.value().isEmpty()) - item->setDetail(readFirstParagraphs(it.value())); + item->setDetail(CMakeToolManager::readFirstParagraphs(it.value())); item->setIcon(icon); list << item; }; diff --git a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp index d8978e3bc61..da2bcff6e05 100644 --- a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp @@ -167,6 +167,21 @@ void CMakeToolManager::updateDocumentation() Core::HelpManager::registerDocumentation(docs); } +QString CMakeToolManager::readFirstParagraphs(const FilePath &helpFile) +{ + static QMap map; + if (map.contains(helpFile)) + return map.value(helpFile); + + auto content = helpFile.fileContents(1024).value_or(QByteArray()); + const QString firstParagraphs + = QString("```\n%1\n```").arg(QString::fromUtf8(content.left(content.lastIndexOf("\n")))); + + map[helpFile] = firstParagraphs; + return firstParagraphs; +} + + QList CMakeToolManager::autoDetectCMakeForDevice(const FilePaths &searchPaths, const QString &detectionSource, QString *logMessage) diff --git a/src/plugins/cmakeprojectmanager/cmaketoolmanager.h b/src/plugins/cmakeprojectmanager/cmaketoolmanager.h index 1b5ee74c8f1..85dbcb53b9e 100644 --- a/src/plugins/cmakeprojectmanager/cmaketoolmanager.h +++ b/src/plugins/cmakeprojectmanager/cmaketoolmanager.h @@ -40,6 +40,8 @@ public: static void updateDocumentation(); + static QString readFirstParagraphs(const Utils::FilePath &helpFile); + public slots: QList autoDetectCMakeForDevice(const Utils::FilePaths &searchPaths, const QString &detectionSource,