forked from qt-creator/qt-creator
TextEditor: Introduce AssistProposalItemInterface
For unit test we need to break every dependency to the TextEditor Widget etc.. With an abstract interface we can implement it in clang without relying on unwanted dependencies. It makes it also easier to compute the values deferred. Change-Id: I1b313a1625f4e80bd324ab4bf1a7c4f6b690abe9 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
class ClangAssistProposalItem : public TextEditor::AssistProposalItem
|
||||
class ClangAssistProposalItem final : public TextEditor::AssistProposalItem
|
||||
{
|
||||
friend bool operator<(const ClangAssistProposalItem &first, const ClangAssistProposalItem &second);
|
||||
public:
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "clangassistproposalmodel.h"
|
||||
|
||||
#include <texteditor/codeassist/assistproposalitem.h>
|
||||
#include <texteditor/codeassist/assistproposaliteminterface.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -47,9 +47,10 @@ bool ClangAssistProposalModel::isSortable(const QString &/*prefix*/) const
|
||||
|
||||
void ClangAssistProposalModel::sort(const QString &/*prefix*/)
|
||||
{
|
||||
using TextEditor::AssistProposalItem;
|
||||
using TextEditor::AssistProposalItemInterface;
|
||||
|
||||
auto currentItemsCompare = [](AssistProposalItem *first, AssistProposalItem *second) {
|
||||
auto currentItemsCompare = [](AssistProposalItemInterface *first,
|
||||
AssistProposalItemInterface *second) {
|
||||
return (first->order() > 0
|
||||
&& (first->order() < second->order()
|
||||
|| (first->order() == second->order() && first->text() < second->text())));
|
||||
|
||||
@@ -58,14 +58,14 @@ namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
using ClangBackEnd::CodeCompletion;
|
||||
using TextEditor::AssistProposalItem;
|
||||
using TextEditor::AssistProposalItemInterface;
|
||||
|
||||
namespace {
|
||||
|
||||
const char SNIPPET_ICON_PATH[] = ":/texteditor/images/snippet.png";
|
||||
|
||||
|
||||
QList<AssistProposalItem *> toAssistProposalItems(const CodeCompletions &completions)
|
||||
QList<AssistProposalItemInterface *> toAssistProposalItems(const CodeCompletions &completions)
|
||||
{
|
||||
static CPlusPlus::Icons m_icons; // de-deduplicate
|
||||
|
||||
@@ -178,7 +178,7 @@ QList<AssistProposalItem *> toAssistProposalItems(const CodeCompletions &complet
|
||||
}
|
||||
}
|
||||
|
||||
QList<AssistProposalItem *> results;
|
||||
QList<AssistProposalItemInterface *> results;
|
||||
results.reserve(items.size());
|
||||
std::copy(items.cbegin(), items.cend(), std::back_inserter(results));
|
||||
|
||||
|
||||
@@ -746,10 +746,10 @@ bool hasSnippet(ProposalModel model, const QByteArray &text)
|
||||
|
||||
auto *genericModel = static_cast<TextEditor::GenericProposalModel *>(model.data());
|
||||
for (int i = 0, size = genericModel->size(); i < size; ++i) {
|
||||
TextEditor::AssistProposalItem *item = genericModel->proposalItem(i);
|
||||
TextEditor::AssistProposalItemInterface *item = genericModel->proposalItem(i);
|
||||
QTC_ASSERT(item, continue);
|
||||
if (item->text() == snippetText)
|
||||
return item->data().toString().contains(QLatin1Char('$'));
|
||||
return item->isSnippet();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user