CMakePM: Add hover help for CMakeEditor

Fixes: QTCREATORBUG-25780
Change-Id: I954023f701e6c1c6ca5e25190b37f8b9a8becfb5
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Cristian Adam
2023-09-18 22:08:23 +02:00
parent 05614ab740
commit cd94514dbb
2 changed files with 95 additions and 9 deletions

View File

@@ -155,14 +155,21 @@ QList<AssistProposalItemInterface *> generateList(const T &words, const QIcon &i
QString readFirstParagraphs(const QString &element, const FilePath &helpFile)
{
static QMap<FilePath, QString> map;
if (map.contains(helpFile))
return map.value(helpFile);
auto content = helpFile.fileContents(1024).value_or(QByteArray());
return QString("```\n%1\n```").arg(QString::fromUtf8(content.left(content.lastIndexOf("\n"))));
const QString firstParagraphs
= QString("```\n%1\n```").arg(QString::fromUtf8(content.left(content.lastIndexOf("\n"))));
map[helpFile] = firstParagraphs;
return firstParagraphs;
}
QList<AssistProposalItemInterface *> generateList(const QMap<QString, FilePath> &words,
const QIcon &icon)
{
static QMap<FilePath, QString> map;
struct MarkDownAssitProposalItem : public AssistProposalItem
{
Qt::TextFormat detailFormat() const { return Qt::MarkdownText; }
@@ -172,13 +179,8 @@ QList<AssistProposalItemInterface *> generateList(const QMap<QString, FilePath>
for (const auto &[text, helpFile] : words.asKeyValueRange()) {
MarkDownAssitProposalItem *item = new MarkDownAssitProposalItem();
item->setText(text);
if (!helpFile.isEmpty()) {
if (!map.contains(helpFile))
map[helpFile] = readFirstParagraphs(text, helpFile);
item->setDetail(map.value(helpFile));
}
if (!helpFile.isEmpty())
item->setDetail(readFirstParagraphs(text, helpFile));
item->setIcon(icon);
list << item;
};