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:
Leandro Melo
2011-04-15 16:19:23 +02:00
parent d835b769c7
commit bec4f02495
119 changed files with 9347 additions and 6595 deletions

View File

@@ -40,6 +40,8 @@
#include <qmljs/qmljsdocument.h>
#include <qmljstools/qmljsrefactoringchanges.h>
#include <QtCore/QSharedPointer>
namespace ExtensionSystem {
class IPlugin;
}
@@ -51,40 +53,12 @@ namespace QmlJS {
namespace QmlJSEditor {
namespace Internal {
class QmlJSQuickFixCollector;
class QmlJSQuickFixAssistInterface;
} // namespace Internal
/*!
Specialized QuickFixState for QML/JavaScript quick-fixes.
This specialized state for QML/JavaScript quick-fixes also holds the
QmlJSEditor::Internal::SemanticInfo for the document in the editor.
*/
class QmlJSQuickFixState: public TextEditor::QuickFixState
{
friend class Internal::QmlJSQuickFixCollector;
public:
/// Creates a new state for the given editor.
QmlJSQuickFixState(TextEditor::BaseTextEditorWidget *editor);
SemanticInfo semanticInfo() const;
/// \returns the snapshot holding the document of the editor.
QmlJS::Snapshot snapshot() const;
/// \returns the document of the editor
QmlJS::Document::Ptr document() const;
const QmlJSTools::QmlJSRefactoringFile currentFile() const;
private:
SemanticInfo _semanticInfo;
};
/*!
A quick-fix operation for the QML/JavaScript editor, which works on a
QmlJSQuickFixState .
A quick-fix operation for the QML/JavaScript editor.
*/
class QmlJSQuickFixOperation: public TextEditor::QuickFixOperation
{
@@ -94,13 +68,12 @@ public:
/*!
Creates a new QmlJSQuickFixOperation.
This operation will copy the complete state, in order to be able to perform
its changes later on.
\param state The state for which this operation was created.
\param interface The interface on which the operation is performed.
\param priority The priority for this operation.
*/
explicit QmlJSQuickFixOperation(const QmlJSQuickFixState &state, int priority = -1);
explicit QmlJSQuickFixOperation(
const QSharedPointer<const Internal::QmlJSQuickFixAssistInterface> &interface,
int priority = -1);
virtual ~QmlJSQuickFixOperation();
virtual void perform();
@@ -111,14 +84,13 @@ protected:
virtual void performChanges(QmlJSTools::QmlJSRefactoringFile *currentFile,
QmlJSTools::QmlJSRefactoringChanges *refactoring) = 0;
/// \returns A const-reference to the state of the operation.
const QmlJSQuickFixState &state() const;
const Internal::QmlJSQuickFixAssistInterface *assistInterface() const;
/// \returns The name of the file for for which this operation is invoked.
QString fileName() const;
private:
QmlJSQuickFixState _state;
QSharedPointer<const Internal::QmlJSQuickFixAssistInterface> m_interface;
};
class QmlJSQuickFixFactory: public TextEditor::QuickFixFactory
@@ -129,39 +101,20 @@ public:
QmlJSQuickFixFactory();
virtual ~QmlJSQuickFixFactory();
virtual QList<TextEditor::QuickFixOperation::Ptr> matchingOperations(TextEditor::QuickFixState *state);
virtual QList<TextEditor::QuickFixOperation::Ptr>
matchingOperations(const QSharedPointer<const TextEditor::IAssistInterface> &interface);
/*!
Implement this method to match and create the appropriate
QmlJSQuickFixOperation objects.
*/
virtual QList<QmlJSQuickFixOperation::Ptr> match(const QmlJSQuickFixState &state) = 0;
virtual QList<QmlJSQuickFixOperation::Ptr> match(
const QSharedPointer<const Internal::QmlJSQuickFixAssistInterface> &interface) = 0;
static QList<QmlJSQuickFixOperation::Ptr> noResult();
static QList<QmlJSQuickFixOperation::Ptr> singleResult(QmlJSQuickFixOperation *operation);
};
namespace Internal {
class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector
{
Q_OBJECT
public:
QmlJSQuickFixCollector();
virtual ~QmlJSQuickFixCollector();
virtual bool supportsEditor(TextEditor::ITextEditor *editor) const;
virtual bool supportsPolicy(TextEditor::CompletionPolicy policy) const;
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::BaseTextEditorWidget *editor);
virtual QList<TextEditor::QuickFixFactory *> quickFixFactories() const;
/// Registers all quick-fixes in this plug-in as auto-released objects.
static void registerQuickFixes(ExtensionSystem::IPlugin *plugIn);
};
} // namespace Internal
} // namespace QmlJSEditor
#endif // QMLJSQUICKFIX_H