Commit bb3b7307 authored by Marco Bubke's avatar Marco Bubke
Browse files

Clang: ClangAssistProposalItem is now inheriting AssistProposalItemInterface



Change-Id: I781ba27659e852782292596fe590666b09d7253e
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent c903f497
......@@ -27,6 +27,7 @@
#include "clangcompletionchunkstotextconverter.h"
#include <cplusplus/Icons.h>
#include <cplusplus/MatchingText.h>
#include <cplusplus/Token.h>
......@@ -60,6 +61,11 @@ bool ClangAssistProposalItem::prematurelyApplies(const QChar &typedChar) const
return applies;
}
bool ClangAssistProposalItem::implicitlyApplies() const
{
return false;
}
static bool hasOnlyBlanksBeforeCursorInLine(QTextCursor textCursor)
{
textCursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
......@@ -75,8 +81,8 @@ static bool hasOnlyBlanksBeforeCursorInLine(QTextCursor textCursor)
return nonSpace == textBeforeCursor.cend();
}
void ClangAssistProposalItem::applyContextualContent(TextEditor::TextEditorWidget *editorWidget,
int basePosition) const
void ClangAssistProposalItem::apply(TextEditor::TextEditorWidget *editorWidget,
int basePosition) const
{
const CodeCompletion ccr = codeCompletion();
......@@ -234,6 +240,103 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::TextEditorWidge
}
}
void ClangAssistProposalItem::setText(const QString &text)
{
m_text = text;
}
QString ClangAssistProposalItem::text() const
{
return m_text;
}
QIcon ClangAssistProposalItem::icon() const
{
using CPlusPlus::Icons;
static const CPlusPlus::Icons m_icons;
static const char SNIPPET_ICON_PATH[] = ":/texteditor/images/snippet.png";
static const QIcon snippetIcon = QIcon(QLatin1String(SNIPPET_ICON_PATH));
switch (m_codeCompletion.completionKind()) {
case CodeCompletion::ClassCompletionKind:
case CodeCompletion::TemplateClassCompletionKind:
case CodeCompletion::TypeAliasCompletionKind:
return m_icons.iconForType(Icons::ClassIconType);
case CodeCompletion::EnumerationCompletionKind:
return m_icons.iconForType(Icons::EnumIconType);
case CodeCompletion::EnumeratorCompletionKind:
return m_icons.iconForType(Icons::EnumeratorIconType);
case CodeCompletion::ConstructorCompletionKind:
case CodeCompletion::DestructorCompletionKind:
case CodeCompletion::FunctionCompletionKind:
case CodeCompletion::TemplateFunctionCompletionKind:
case CodeCompletion::ObjCMessageCompletionKind:
switch (m_codeCompletion.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
return m_icons.iconForType(Icons::FuncPublicIconType);
default:
return m_icons.iconForType(Icons::FuncPrivateIconType);
}
case CodeCompletion::SignalCompletionKind:
return m_icons.iconForType(Icons::SignalIconType);
case CodeCompletion::SlotCompletionKind:
switch (m_codeCompletion.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
return m_icons.iconForType(Icons::SlotPublicIconType);
case CodeCompletion::NotAccessible:
case CodeCompletion::NotAvailable:
return m_icons.iconForType(Icons::SlotPrivateIconType);
}
case CodeCompletion::NamespaceCompletionKind:
return m_icons.iconForType(Icons::NamespaceIconType);
case CodeCompletion::PreProcessorCompletionKind:
return m_icons.iconForType(Icons::MacroIconType);
case CodeCompletion::VariableCompletionKind:
switch (m_codeCompletion.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
return m_icons.iconForType(Icons::VarPublicIconType);
default:
return m_icons.iconForType(Icons::VarPrivateIconType);
}
case CodeCompletion::KeywordCompletionKind:
return m_icons.iconForType(Icons::KeywordIconType);
case CodeCompletion::ClangSnippetKind:
return snippetIcon;
case CodeCompletion::Other:
return m_icons.iconForType(Icons::UnknownIconType);
}
return QIcon();
}
QString ClangAssistProposalItem::detail() const
{
QString detail = CompletionChunksToTextConverter::convertToToolTipWithHtml(m_codeCompletion.chunks());
if (!m_codeCompletion.briefComment().isEmpty())
detail += QStringLiteral("\n\n") + m_codeCompletion.briefComment().toString();
return detail;
}
bool ClangAssistProposalItem::isSnippet() const
{
return false;
}
bool ClangAssistProposalItem::isValid() const
{
return true;
}
quint64 ClangAssistProposalItem::hash() const
{
return 0;
}
void ClangAssistProposalItem::keepCompletionOperator(unsigned compOp)
{
m_completionOperator = compOp;
......
......@@ -28,19 +28,30 @@
#include <codecompletion.h>
#include <texteditor/codeassist/assistproposalitem.h>
#include <texteditor/codeassist/assistproposaliteminterface.h>
#include <QString>
namespace ClangCodeModel {
namespace Internal {
class ClangAssistProposalItem final : public TextEditor::AssistProposalItem
class ClangAssistProposalItem final : public TextEditor::AssistProposalItemInterface
{
friend bool operator<(const ClangAssistProposalItem &first, const ClangAssistProposalItem &second);
public:
ClangAssistProposalItem() {}
bool prematurelyApplies(const QChar &c) const override;
void applyContextualContent(TextEditor::TextEditorWidget *editorWidget, int basePosition) const override;
bool prematurelyApplies(const QChar &c) const final;
bool implicitlyApplies() const final;
void apply(TextEditor::TextEditorWidget *editorWidget, int basePosition) const final;
void setText(const QString &text);
QString text() const final;
QIcon icon() const final;
QString detail() const final;
bool isSnippet() const final;
bool isValid() const final;
quint64 hash() const final;
void keepCompletionOperator(unsigned compOp);
......@@ -53,6 +64,7 @@ public:
private:
ClangBackEnd::CodeCompletion m_codeCompletion;
QList<ClangBackEnd::CodeCompletion> m_overloads;
QString m_text;
unsigned m_completionOperator;
mutable QChar m_typedChar;
};
......
......@@ -62,119 +62,39 @@ using TextEditor::AssistProposalItemInterface;
namespace {
const char SNIPPET_ICON_PATH[] = ":/texteditor/images/snippet.png";
QList<AssistProposalItemInterface *> toAssistProposalItems(const CodeCompletions &completions)
{
static CPlusPlus::Icons m_icons; // de-deduplicate
bool signalCompletion = false; // TODO
bool slotCompletion = false; // TODO
const QIcon snippetIcon = QIcon(QLatin1String(SNIPPET_ICON_PATH));
QHash<QString, ClangAssistProposalItem *> items;
foreach (const CodeCompletion &ccr, completions) {
if (ccr.text().isEmpty()) // TODO: Make isValid()?
foreach (const CodeCompletion &codeCompletion, completions) {
if (codeCompletion.text().isEmpty()) // TODO: Make isValid()?
continue;
if (signalCompletion && ccr.completionKind() != CodeCompletion::SignalCompletionKind)
if (signalCompletion && codeCompletion.completionKind() != CodeCompletion::SignalCompletionKind)
continue;
if (slotCompletion && ccr.completionKind() != CodeCompletion::SlotCompletionKind)
if (slotCompletion && codeCompletion.completionKind() != CodeCompletion::SlotCompletionKind)
continue;
QString name;
if (ccr.completionKind() == CodeCompletion::KeywordCompletionKind)
name = CompletionChunksToTextConverter::convertToName(ccr.chunks());
if (codeCompletion.completionKind() == CodeCompletion::KeywordCompletionKind)
name = CompletionChunksToTextConverter::convertToName(codeCompletion.chunks());
else
name = ccr.text().toString();
name = codeCompletion.text().toString();
ClangAssistProposalItem *item = items.value(name, 0);
if (item) {
item->addOverload(ccr);
item->addOverload(codeCompletion);
} else {
item = new ClangAssistProposalItem;
items.insert(name, item);
item->setText(name);
item->setOrder(ccr.priority());
QString detail
= CompletionChunksToTextConverter::convertToToolTipWithHtml(ccr.chunks());
if (!ccr.briefComment().isEmpty())
detail += QStringLiteral("\n\n") + ccr.briefComment().toString();
item->setDetail(detail);
item->setCodeCompletion(ccr);
}
// FIXME: show the effective accessebility instead of availability
using CPlusPlus::Icons;
switch (ccr.completionKind()) {
case CodeCompletion::ClassCompletionKind:
case CodeCompletion::TemplateClassCompletionKind:
case CodeCompletion::TypeAliasCompletionKind:
item->setIcon(m_icons.iconForType(Icons::ClassIconType)); break;
case CodeCompletion::EnumerationCompletionKind: item->setIcon(m_icons.iconForType(Icons::EnumIconType)); break;
case CodeCompletion::EnumeratorCompletionKind: item->setIcon(m_icons.iconForType(Icons::EnumeratorIconType)); break;
case CodeCompletion::ConstructorCompletionKind: // fall through
case CodeCompletion::DestructorCompletionKind: // fall through
case CodeCompletion::FunctionCompletionKind:
case CodeCompletion::TemplateFunctionCompletionKind:
case CodeCompletion::ObjCMessageCompletionKind:
switch (ccr.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
item->setIcon(m_icons.iconForType(Icons::FuncPublicIconType));
break;
default:
item->setIcon(m_icons.iconForType(Icons::FuncPrivateIconType));
break;
}
break;
case CodeCompletion::SignalCompletionKind:
item->setIcon(m_icons.iconForType(Icons::SignalIconType));
break;
QString detail = CompletionChunksToTextConverter::convertToToolTipWithHtml(codeCompletion.chunks());
case CodeCompletion::SlotCompletionKind:
switch (ccr.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
item->setIcon(m_icons.iconForType(Icons::SlotPublicIconType));
break;
case CodeCompletion::NotAccessible:
case CodeCompletion::NotAvailable:
item->setIcon(m_icons.iconForType(Icons::SlotPrivateIconType));
break;
}
break;
case CodeCompletion::NamespaceCompletionKind: item->setIcon(m_icons.iconForType(Icons::NamespaceIconType)); break;
case CodeCompletion::PreProcessorCompletionKind: item->setIcon(m_icons.iconForType(Icons::MacroIconType)); break;
case CodeCompletion::VariableCompletionKind:
switch (ccr.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
item->setIcon(m_icons.iconForType(Icons::VarPublicIconType));
break;
default:
item->setIcon(m_icons.iconForType(Icons::VarPrivateIconType));
break;
}
break;
case CodeCompletion::KeywordCompletionKind:
item->setIcon(m_icons.iconForType(Icons::KeywordIconType));
break;
case CodeCompletion::ClangSnippetKind:
item->setIcon(snippetIcon);
break;
items.insert(name, item);
case CodeCompletion::Other:
item->setIcon(m_icons.iconForType(Icons::UnknownIconType));
break;
item->setText(name);
item->setOrder(int(codeCompletion.priority()));
item->setCodeCompletion(codeCompletion);
}
}
......@@ -613,10 +533,10 @@ void ClangCompletionAssistProcessor::completeIncludePath(const QString &realPath
if (fileInfo.isDir())
text += QLatin1Char('/');
ClangAssistProposalItem *item = new ClangAssistProposalItem;
auto *item = new ClangAssistProposalItem; // TODO: Add IncludeAssistProposalItem
item->setText(text);
item->setDetail(hint);
item->setIcon(m_icons.keywordIcon());
//item->setDetail(hint);
//item->setIcon(m_icons.keywordIcon());
item->keepCompletionOperator(m_completionOperator);
m_completions.append(item);
}
......@@ -645,14 +565,12 @@ bool ClangCompletionAssistProcessor::completeDoxygenKeywords()
void ClangCompletionAssistProcessor::addCompletionItem(const QString &text,
const QIcon &icon,
int order,
const QVariant &data)
int order)
{
ClangAssistProposalItem *item = new ClangAssistProposalItem;
item->setText(text);
item->setIcon(icon);
//item->setIcon(icon); TODO: Add item for macros and includes
item->setOrder(order);
item->setData(data);
item->keepCompletionOperator(m_completionOperator);
m_completions.append(item);
}
......
......@@ -71,8 +71,7 @@ private:
bool completeDoxygenKeywords();
void addCompletionItem(const QString &text,
const QIcon &icon = QIcon(),
int order = 0,
const QVariant &data = QVariant());
int order = 0);
struct UnsavedFileContentInfo {
QByteArray unsavedContent;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment