forked from qt-creator/qt-creator
New code assist API
This is a re-work of our completion engine. Primary goals are: - Allow the computation to run in a separate thread so the GUI is not locked. - Support a model-based approach. QStrings are still needed (filtering, etc), but internal structures are free to use more efficient representations. - Unifiy all kinds of *assist* into a more reusable and extensible framework. - Remove unnecessary dependencies on the text editor so we have more generic and easily "plugable" components (still things to be resolved).
This commit is contained in:
@@ -30,18 +30,18 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "snippetcollector.h"
|
||||
#include "snippetassistcollector.h"
|
||||
#include "snippetscollection.h"
|
||||
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/codeassist/basicproposalitem.h>
|
||||
|
||||
using namespace TextEditor;
|
||||
using namespace Internal;
|
||||
|
||||
namespace {
|
||||
|
||||
void appendSnippets(ICompletionCollector *collector,
|
||||
QList<CompletionItem> *completionItems,
|
||||
void appendSnippets(QList<BasicProposalItem *> *items,
|
||||
const QString &groupId,
|
||||
const QIcon &icon,
|
||||
int order)
|
||||
@@ -50,30 +50,32 @@ void appendSnippets(ICompletionCollector *collector,
|
||||
const int size = collection->totalActiveSnippets(groupId);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
const Snippet &snippet = collection->snippet(i, groupId);
|
||||
CompletionItem item(collector);
|
||||
item.text = snippet.trigger() + QLatin1Char(' ') + snippet.complement();
|
||||
item.data = snippet.content();
|
||||
item.details = snippet.generateTip();
|
||||
item.icon = icon;
|
||||
item.order = order;
|
||||
item.isSnippet = true;
|
||||
completionItems->append(item);
|
||||
BasicProposalItem *item = new BasicProposalItem;
|
||||
item->setText(snippet.trigger() + QLatin1Char(' ') + snippet.complement());
|
||||
item->setData(snippet.content());
|
||||
item->setDetail(snippet.generateTip());
|
||||
item->setIcon(icon);
|
||||
item->setOrder(order);
|
||||
items->append(item);
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous
|
||||
|
||||
SnippetCollector::SnippetCollector(const QString &groupId, const QIcon &icon, int order) :
|
||||
m_groupId(groupId), m_icon(icon), m_order(order)
|
||||
|
||||
SnippetAssistCollector::SnippetAssistCollector(const QString &groupId, const QIcon &icon, int order)
|
||||
: m_groupId(groupId)
|
||||
, m_icon(icon)
|
||||
, m_order(order)
|
||||
{}
|
||||
|
||||
SnippetCollector::~SnippetCollector()
|
||||
SnippetAssistCollector::~SnippetAssistCollector()
|
||||
{}
|
||||
|
||||
QList<CompletionItem> SnippetCollector::getSnippets(ICompletionCollector *collector) const
|
||||
QList<BasicProposalItem *> SnippetAssistCollector::collect() const
|
||||
{
|
||||
QList<CompletionItem> completionItems;
|
||||
appendSnippets(collector, &completionItems, m_groupId, m_icon, m_order);
|
||||
appendSnippets(collector, &completionItems, Constants::TEXT_SNIPPET_GROUP_ID, m_icon, m_order);
|
||||
return completionItems;
|
||||
QList<BasicProposalItem *> snippets;
|
||||
appendSnippets(&snippets, m_groupId, m_icon, m_order);
|
||||
appendSnippets(&snippets, Constants::TEXT_SNIPPET_GROUP_ID, m_icon, m_order);
|
||||
return snippets;
|
||||
}
|
||||
@@ -30,11 +30,10 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef SNIPPETPROVIDER_H
|
||||
#define SNIPPETPROVIDER_H
|
||||
#ifndef SNIPPETASSISTCOLLECTOR_H
|
||||
#define SNIPPETASSISTCOLLECTOR_H
|
||||
|
||||
#include <texteditor/texteditor_global.h>
|
||||
#include <texteditor/icompletioncollector.h>
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QList>
|
||||
@@ -42,13 +41,15 @@
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
class TEXTEDITOR_EXPORT SnippetCollector
|
||||
class BasicProposalItem;
|
||||
|
||||
class TEXTEDITOR_EXPORT SnippetAssistCollector
|
||||
{
|
||||
public:
|
||||
SnippetCollector(const QString &groupId, const QIcon &icon, int order = 0);
|
||||
~SnippetCollector();
|
||||
SnippetAssistCollector(const QString &groupId, const QIcon &icon, int order = 0);
|
||||
~SnippetAssistCollector();
|
||||
|
||||
QList<CompletionItem> getSnippets(ICompletionCollector *collector) const;
|
||||
QList<BasicProposalItem *> collect() const;
|
||||
|
||||
private:
|
||||
QString m_groupId;
|
||||
@@ -58,4 +59,4 @@ private:
|
||||
|
||||
} // TextEditor
|
||||
|
||||
#endif // SNIPPETPROVIDER_H
|
||||
#endif // SNIPPETASSISTCOLLECTOR_H
|
||||
Reference in New Issue
Block a user