forked from qt-creator/qt-creator
ClangCodeModel: Provide signal/slot icons for clangd completions
Fixes: QTCREATORBUG-26555 Change-Id: I3b647f6fdbeed69bc453d64a69fb57731d92231e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -66,6 +66,7 @@
|
|||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@@ -1110,6 +1111,12 @@ public:
|
|||||||
using LanguageClientCompletionItem::LanguageClientCompletionItem;
|
using LanguageClientCompletionItem::LanguageClientCompletionItem;
|
||||||
void apply(TextDocumentManipulatorInterface &manipulator,
|
void apply(TextDocumentManipulatorInterface &manipulator,
|
||||||
int basePosition) const override;
|
int basePosition) const override;
|
||||||
|
|
||||||
|
enum class SpecialQtType { Signal, Slot, None };
|
||||||
|
static SpecialQtType getQtType(const CompletionItem &item);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QIcon icon() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClangdClient::ClangdCompletionAssistProcessor : public LanguageClientCompletionAssistProcessor
|
class ClangdClient::ClangdCompletionAssistProcessor : public LanguageClientCompletionAssistProcessor
|
||||||
@@ -1155,15 +1162,7 @@ ClangdClient::ClangdCompletionAssistProcessor::generateCompletionItems(
|
|||||||
// whether the cursor was on the second argument of a (dis)connect() call.
|
// whether the cursor was on the second argument of a (dis)connect() call.
|
||||||
// If so, we offer only signals, as nothing else makes sense in that context.
|
// If so, we offer only signals, as nothing else makes sense in that context.
|
||||||
static const auto criterion = [](const CompletionItem &ci) {
|
static const auto criterion = [](const CompletionItem &ci) {
|
||||||
const Utils::optional<MarkupOrString> doc = ci.documentation();
|
return ClangdCompletionItem::getQtType(ci) == ClangdCompletionItem::SpecialQtType::Signal;
|
||||||
if (!doc)
|
|
||||||
return false;
|
|
||||||
QString docText;
|
|
||||||
if (Utils::holds_alternative<QString>(*doc))
|
|
||||||
docText = Utils::get<QString>(*doc);
|
|
||||||
else if (Utils::holds_alternative<MarkupContent>(*doc))
|
|
||||||
docText = Utils::get<MarkupContent>(*doc).content();
|
|
||||||
return docText.contains("Annotation: qt_signal");
|
|
||||||
};
|
};
|
||||||
const QTextDocument *doc = document();
|
const QTextDocument *doc = document();
|
||||||
const int pos = basePos();
|
const int pos = basePos();
|
||||||
@@ -3009,6 +3008,38 @@ void ClangdCompletionItem::apply(TextDocumentManipulatorInterface &manipulator,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClangdCompletionItem::SpecialQtType ClangdCompletionItem::getQtType(const CompletionItem &item)
|
||||||
|
{
|
||||||
|
const Utils::optional<MarkupOrString> doc = item.documentation();
|
||||||
|
if (!doc)
|
||||||
|
return SpecialQtType::None;
|
||||||
|
QString docText;
|
||||||
|
if (Utils::holds_alternative<QString>(*doc))
|
||||||
|
docText = Utils::get<QString>(*doc);
|
||||||
|
else if (Utils::holds_alternative<MarkupContent>(*doc))
|
||||||
|
docText = Utils::get<MarkupContent>(*doc).content();
|
||||||
|
if (docText.contains("Annotation: qt_signal"))
|
||||||
|
return SpecialQtType::Signal;
|
||||||
|
if (docText.contains("Annotation: qt_slot"))
|
||||||
|
return SpecialQtType::Slot;
|
||||||
|
return SpecialQtType::None;
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon ClangdCompletionItem::icon() const
|
||||||
|
{
|
||||||
|
const SpecialQtType qtType = getQtType(item());
|
||||||
|
switch (qtType) {
|
||||||
|
case SpecialQtType::Signal:
|
||||||
|
return Utils::CodeModelIcon::iconForType(Utils::CodeModelIcon::Signal);
|
||||||
|
case SpecialQtType::Slot:
|
||||||
|
// FIXME: Add visibility info to completion item tags in clangd?
|
||||||
|
return Utils::CodeModelIcon::iconForType(Utils::CodeModelIcon::SlotPublic);
|
||||||
|
case SpecialQtType::None:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return LanguageClientCompletionItem::icon();
|
||||||
|
}
|
||||||
|
|
||||||
MessageId ClangdClient::Private::getAndHandleAst(const TextDocOrFile &doc,
|
MessageId ClangdClient::Private::getAndHandleAst(const TextDocOrFile &doc,
|
||||||
const AstHandler &astHandler,
|
const AstHandler &astHandler,
|
||||||
AstCallbackMode callbackMode, const Range &range)
|
AstCallbackMode callbackMode, const Range &range)
|
||||||
|
Reference in New Issue
Block a user