forked from qt-creator/qt-creator
ClangCodeModel: Special rendering for deprecated completion items
We add the attribute textually and show a warning icon. Fixes: QTCREATORBUG-2325 Change-Id: Icc0305a703e26c84095167087b30fa3456f97614 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -49,6 +49,16 @@ Utils::optional<CompletionItem::InsertTextFormat> CompletionItem::insertTextForm
|
|||||||
return Utils::nullopt;
|
return Utils::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::optional<QList<CompletionItem::CompletionItemTag>> CompletionItem::tags() const
|
||||||
|
{
|
||||||
|
if (const auto value = optionalValue<QJsonArray>(tagsKey)) {
|
||||||
|
QList<CompletionItemTag> tags;
|
||||||
|
for (auto it = value->cbegin(); it != value->cend(); ++it)
|
||||||
|
tags << static_cast<CompletionItemTag>(it->toInt());
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
CompletionItemResolveRequest::CompletionItemResolveRequest(const CompletionItem ¶ms)
|
CompletionItemResolveRequest::CompletionItemResolveRequest(const CompletionItem ¶ms)
|
||||||
: Request(methodName, params)
|
: Request(methodName, params)
|
||||||
|
@@ -214,6 +214,27 @@ public:
|
|||||||
void setData(const QJsonValue &data) { insert(dataKey, data); }
|
void setData(const QJsonValue &data) { insert(dataKey, data); }
|
||||||
void clearData() { remove(dataKey); }
|
void clearData() { remove(dataKey); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completion item tags are extra annotations that tweak the rendering of a
|
||||||
|
* completion item.
|
||||||
|
* @since 3.15.0
|
||||||
|
*/
|
||||||
|
enum CompletionItemTag {
|
||||||
|
Deprecated = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags for this completion item.
|
||||||
|
* @since 3.15.0
|
||||||
|
*/
|
||||||
|
Utils::optional<QList<CompletionItemTag>> tags() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if this item is deprecated.
|
||||||
|
* @deprecated Use `tags` instead if supported.
|
||||||
|
*/
|
||||||
|
Utils::optional<bool> deprecated() const { return optionalValue<bool>(deprecatedKey); }
|
||||||
|
|
||||||
bool isValid() const override { return contains(labelKey); }
|
bool isValid() const override { return contains(labelKey); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -209,6 +209,7 @@ constexpr char symbolKindKey[] = "symbolKind";
|
|||||||
constexpr char syncKindKey[] = "syncKind";
|
constexpr char syncKindKey[] = "syncKind";
|
||||||
constexpr char synchronizationKey[] = "synchronization";
|
constexpr char synchronizationKey[] = "synchronization";
|
||||||
constexpr char tabSizeKey[] = "tabSize";
|
constexpr char tabSizeKey[] = "tabSize";
|
||||||
|
constexpr char tagsKey[] = "tags";
|
||||||
constexpr char targetKey[] = "target";
|
constexpr char targetKey[] = "target";
|
||||||
constexpr char textDocumentKey[] = "textDocument";
|
constexpr char textDocumentKey[] = "textDocument";
|
||||||
constexpr char textDocumentSyncKey[] = "textDocumentSync";
|
constexpr char textDocumentSyncKey[] = "textDocumentSync";
|
||||||
|
@@ -741,6 +741,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QIcon icon() const override;
|
QIcon icon() const override;
|
||||||
|
QString text() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClangdClient::ClangdCompletionAssistProcessor : public LanguageClientCompletionAssistProcessor
|
class ClangdClient::ClangdCompletionAssistProcessor : public LanguageClientCompletionAssistProcessor
|
||||||
@@ -2551,6 +2552,8 @@ ClangdCompletionItem::SpecialQtType ClangdCompletionItem::getQtType(const Comple
|
|||||||
|
|
||||||
QIcon ClangdCompletionItem::icon() const
|
QIcon ClangdCompletionItem::icon() const
|
||||||
{
|
{
|
||||||
|
if (isDeprecated())
|
||||||
|
return Utils::Icons::WARNING.icon();
|
||||||
const SpecialQtType qtType = getQtType(item());
|
const SpecialQtType qtType = getQtType(item());
|
||||||
switch (qtType) {
|
switch (qtType) {
|
||||||
case SpecialQtType::Signal:
|
case SpecialQtType::Signal:
|
||||||
@@ -2566,6 +2569,14 @@ QIcon ClangdCompletionItem::icon() const
|
|||||||
return LanguageClientCompletionItem::icon();
|
return LanguageClientCompletionItem::icon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ClangdCompletionItem::text() const
|
||||||
|
{
|
||||||
|
const QString clangdValue = LanguageClientCompletionItem::text();
|
||||||
|
if (isDeprecated())
|
||||||
|
return "[[deprecated]]" + clangdValue;
|
||||||
|
return clangdValue;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@@ -227,6 +227,15 @@ bool LanguageClientCompletionItem::isPerfectMatch(int pos, QTextDocument *doc) c
|
|||||||
return textToInsert == textAt(QTextCursor(doc), pos - length, length);
|
return textToInsert == textAt(QTextCursor(doc), pos - length, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LanguageClientCompletionItem::isDeprecated() const
|
||||||
|
{
|
||||||
|
if (const auto tags = m_item.tags(); tags && tags->contains(CompletionItem::Deprecated))
|
||||||
|
return true;
|
||||||
|
if (const auto deprecated = m_item.deprecated())
|
||||||
|
return *deprecated;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
class LanguageClientCompletionModel : public GenericProposalModel
|
class LanguageClientCompletionModel : public GenericProposalModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -135,6 +135,7 @@ public:
|
|||||||
bool operator <(const LanguageClientCompletionItem &other) const;
|
bool operator <(const LanguageClientCompletionItem &other) const;
|
||||||
|
|
||||||
bool isPerfectMatch(int pos, QTextDocument *doc) const;
|
bool isPerfectMatch(int pos, QTextDocument *doc) const;
|
||||||
|
bool isDeprecated() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LanguageServerProtocol::CompletionItem m_item;
|
LanguageServerProtocol::CompletionItem m_item;
|
||||||
|
Reference in New Issue
Block a user