CMakeToolManager: Add static readFirstParagraphs()

Reuse it in CMakeEditor and CMakeFileCompletionAssistProvider.

Amends d04585b519

Change-Id: I8dbd59c815e017404ff215ca1ff68740d6653e91
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Jarek Kobus
2023-09-27 13:01:18 +02:00
committed by Cristian Adam
parent cbc6809b28
commit 4e90ca1b59
4 changed files with 19 additions and 19 deletions

View File

@@ -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);
}

View File

@@ -153,20 +153,6 @@ static QList<AssistProposalItemInterface *> generateList(const T &words, const Q
});
}
static QString readFirstParagraphs(const FilePath &helpFile)
{
static QMap<FilePath, QString> 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<AssistProposalItemInterface *> generateList(const QMap<QString, FilePath> &words,
const QIcon &icon)
{
@@ -180,7 +166,7 @@ static QList<AssistProposalItemInterface *> generateList(const QMap<QString, Fil
MarkDownAssitProposalItem *item = new MarkDownAssitProposalItem();
item->setText(it.key());
if (!it.value().isEmpty())
item->setDetail(readFirstParagraphs(it.value()));
item->setDetail(CMakeToolManager::readFirstParagraphs(it.value()));
item->setIcon(icon);
list << item;
};

View File

@@ -167,6 +167,21 @@ void CMakeToolManager::updateDocumentation()
Core::HelpManager::registerDocumentation(docs);
}
QString CMakeToolManager::readFirstParagraphs(const FilePath &helpFile)
{
static QMap<FilePath, QString> 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<Id> CMakeToolManager::autoDetectCMakeForDevice(const FilePaths &searchPaths,
const QString &detectionSource,
QString *logMessage)

View File

@@ -40,6 +40,8 @@ public:
static void updateDocumentation();
static QString readFirstParagraphs(const Utils::FilePath &helpFile);
public slots:
QList<Utils::Id> autoDetectCMakeForDevice(const Utils::FilePaths &searchPaths,
const QString &detectionSource,