TextEditor::IAssistProposal *createAssistProposal(const DCodeModel::CompletionList &list, int pos)
{
    using namespace TextEditor;
    switch (list.type) {
    case DCodeModel::COMPLETION_IDENTIFIER:
    {
        QList<TextEditor::AssistProposalItem *> items;
        foreach (const auto& comp, list.list) {
            AssistProposalItem *item = new AssistProposalItem;
            item->setText(comp.name);
            item->setIcon(DlangIconCache::instance().fromType(comp.type));
            items.append(item);
        }
        return new GenericProposal(pos, items);
    }
        break;
    case DCodeModel::COMPLETION_CALLTIP:
    {
        QStringList functionSymbols;
        foreach (const auto& comp, list.list) {
            functionSymbols.append(comp.parameters);
        }
        IFunctionHintProposalModel *model =
                new KeywordsFunctionHintModel(functionSymbols);
        return new FunctionHintProposal(pos, model);
    }
        break;
    case DCodeModel::COMPLETION_BAD_TYPE:
        return 0;
    default:
        return 0;
    }
}
Esempio n. 2
0
static AssistProposalItem *createCompletionItem(const QString &text, const QIcon &icon, int order = 0)
{
    AssistProposalItem *item = new AssistProposalItem;
    item->setText(text);
    item->setIcon(icon);
    item->setOrder(order);
    return item;
}
    IAssistProposal *immediateProposal(const AssistInterface *) override
    {
        QTC_ASSERT(m_params.function, return 0);

        AssistProposalItem *hintItem
                = new VirtualFunctionProposalItem(TextEditorWidget::Link());
        hintItem->setText(QCoreApplication::translate("VirtualFunctionsAssistProcessor",
                                                      "...searching overrides"));
        hintItem->setOrder(-1000);

        QList<AssistProposalItem *> items;
        items << itemFromFunction(m_params.function);
        items << hintItem;
        return new VirtualFunctionProposal(m_params.cursorPosition, items, m_params.openInNextSplit);
    }
static void appendSnippets(QList<AssistProposalItem *> *items,
                    const QString &groupId,
                    const QIcon &icon,
                    int order)
{
    SnippetsCollection *collection = SnippetsCollection::instance();
    const int size = collection->totalActiveSnippets(groupId);
    for (int i = 0; i < size; ++i) {
        const Snippet &snippet = collection->snippet(i, groupId);
        AssistProposalItem *item = new AssistProposalItem;
        item->setText(snippet.trigger() + QLatin1Char(' ') + snippet.complement());
        item->setData(snippet.content());
        item->setDetail(snippet.generateTip());
        item->setIcon(icon);
        item->setOrder(order);
        items->append(item);
    }
}