CMakePM: Display help details for code completion

The first 1024 bytes from the CMake .rst files are displayed raw data.

A .rst to html or markdown would be needed for nicer user experience.

Change-Id: Ie6adbb404d844ae88b868b465d4125c2177e6cfe
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2023-09-22 22:47:31 +02:00
parent a8f6df546c
commit 05614ab740
4 changed files with 95 additions and 81 deletions

View File

@@ -153,6 +153,38 @@ QList<AssistProposalItemInterface *> generateList(const T &words, const QIcon &i
});
}
QString readFirstParagraphs(const QString &element, const FilePath &helpFile)
{
auto content = helpFile.fileContents(1024).value_or(QByteArray());
return QString("```\n%1\n```").arg(QString::fromUtf8(content.left(content.lastIndexOf("\n"))));
}
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; }
};
QList<AssistProposalItemInterface *> list;
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));
}
item->setIcon(icon);
list << item;
};
return list;
}
static int addFilePathItems(const AssistInterface *interface,
QList<AssistProposalItemInterface *> &items,
int symbolStartPos)