Commit f5dae8bc authored by Roberto Raggi's avatar Roberto Raggi

Refactored the quickfix engine.

parent c3caf282
...@@ -1036,6 +1036,11 @@ CppQuickFixCollector::~CppQuickFixCollector() ...@@ -1036,6 +1036,11 @@ CppQuickFixCollector::~CppQuickFixCollector()
{ {
} }
bool CppQuickFixCollector::supportsEditor(TextEditor::ITextEditable *editor)
{
return CppTools::CppModelManagerInterface::instance()->isCppEditor(editor);
}
TextEditor::QuickFixState *CppQuickFixCollector::initializeCompletion(TextEditor::ITextEditable *editable) TextEditor::QuickFixState *CppQuickFixCollector::initializeCompletion(TextEditor::ITextEditable *editable)
{ {
if (CPPEditor *editor = qobject_cast<CPPEditor *>(editable->widget())) { if (CPPEditor *editor = qobject_cast<CPPEditor *>(editable->widget())) {
......
...@@ -116,6 +116,7 @@ public: ...@@ -116,6 +116,7 @@ public:
CppQuickFixCollector(); CppQuickFixCollector();
virtual ~CppQuickFixCollector(); virtual ~CppQuickFixCollector();
virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable); virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable);
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const; virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const;
}; };
......
...@@ -103,7 +103,7 @@ public: ...@@ -103,7 +103,7 @@ public:
inline Core::ICore *core() const { return m_core; } inline Core::ICore *core() const { return m_core; }
bool isCppEditor(Core::IEditor *editor) const; // ### private virtual bool isCppEditor(Core::IEditor *editor) const;
CppEditorSupport *editorSupport(TextEditor::ITextEditor *editor) const CppEditorSupport *editorSupport(TextEditor::ITextEditor *editor) const
{ return m_editorSupport.value(editor); } { return m_editorSupport.value(editor); }
......
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QFuture> #include <QtCore/QFuture>
namespace Core {
class IEditor;
}
namespace CPlusPlus { namespace CPlusPlus {
class LookupContext; class LookupContext;
} }
...@@ -110,6 +114,8 @@ public: ...@@ -110,6 +114,8 @@ public:
static CppModelManagerInterface *instance(); static CppModelManagerInterface *instance();
virtual bool isCppEditor(Core::IEditor *editor) const = 0;
virtual WorkingCopy workingCopy() const = 0; virtual WorkingCopy workingCopy() const = 0;
virtual CPlusPlus::Snapshot snapshot() const = 0; virtual CPlusPlus::Snapshot snapshot() const = 0;
......
...@@ -253,8 +253,9 @@ void QmlJSEditorPlugin::quickFixNow() ...@@ -253,8 +253,9 @@ void QmlJSEditorPlugin::quickFixNow()
// qDebug() << "TODO: outdated document" << editor->documentRevision() << editor->semanticInfo().revision(); // qDebug() << "TODO: outdated document" << editor->documentRevision() << editor->semanticInfo().revision();
// ### FIXME: m_quickFixTimer->start(QUICKFIX_INTERVAL); // ### FIXME: m_quickFixTimer->start(QUICKFIX_INTERVAL);
m_quickFixTimer->stop(); m_quickFixTimer->stop();
}else } else {
TextEditor::Internal::CompletionSupport::instance()->quickFix(m_currentTextEditable); TextEditor::Internal::CompletionSupport::instance()->quickFix(m_currentTextEditable);
}
} }
} }
} }
......
...@@ -29,10 +29,20 @@ ...@@ -29,10 +29,20 @@
#include "qmljsquickfix.h" #include "qmljsquickfix.h"
#include "qmljseditor.h" #include "qmljseditor.h"
#include "qmljs/parser/qmljsast_p.h"
#include <QtGui/QApplication>
#include <QtCore/QDebug> #include <QtCore/QDebug>
using namespace QmlJSEditor::Internal; using namespace QmlJSEditor::Internal;
class QmlJSQuickFixState: public TextEditor::QuickFixState
{
public:
SemanticInfo semanticInfo;
};
QmlJSQuickFixOperation::QmlJSQuickFixOperation(TextEditor::BaseTextEditor *editor) QmlJSQuickFixOperation::QmlJSQuickFixOperation(TextEditor::BaseTextEditor *editor)
: TextEditor::QuickFixOperation(editor) : TextEditor::QuickFixOperation(editor)
{ {
...@@ -42,6 +52,33 @@ QmlJSQuickFixOperation::~QmlJSQuickFixOperation() ...@@ -42,6 +52,33 @@ QmlJSQuickFixOperation::~QmlJSQuickFixOperation()
{ {
} }
QmlJS::Document::Ptr QmlJSQuickFixOperation::document() const
{
return _semanticInfo.document;
}
const QmlJS::Snapshot &QmlJSQuickFixOperation::snapshot() const
{
return _semanticInfo.snapshot;
}
const SemanticInfo &QmlJSQuickFixOperation::semanticInfo() const
{
return _semanticInfo;
}
int QmlJSQuickFixOperation::match(TextEditor::QuickFixState *state)
{
QmlJSQuickFixState *s = static_cast<QmlJSQuickFixState *>(state);
_semanticInfo = s->semanticInfo;
return check();
}
unsigned QmlJSQuickFixOperation::position(const QmlJS::AST::SourceLocation &loc) const
{
return position(loc.startLine, loc.startColumn);
}
void QmlJSQuickFixOperation::move(const QmlJS::AST::SourceLocation &loc, int to) void QmlJSQuickFixOperation::move(const QmlJS::AST::SourceLocation &loc, int to)
{ {
move(position(loc.startColumn, loc.startColumn), to); move(position(loc.startColumn, loc.startColumn), to);
...@@ -70,6 +107,14 @@ QmlJSQuickFixCollector::~QmlJSQuickFixCollector() ...@@ -70,6 +107,14 @@ QmlJSQuickFixCollector::~QmlJSQuickFixCollector()
{ {
} }
bool QmlJSQuickFixCollector::supportsEditor(TextEditor::ITextEditable *editable)
{
if (qobject_cast<QmlJSTextEditor *>(editable->widget()) != 0)
return true;
return false;
}
TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEditor::ITextEditable *editable) TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEditor::ITextEditable *editable)
{ {
if (QmlJSTextEditor *editor = qobject_cast<QmlJSTextEditor *>(editable->widget())) { if (QmlJSTextEditor *editor = qobject_cast<QmlJSTextEditor *>(editable->widget())) {
...@@ -81,16 +126,16 @@ TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEdit ...@@ -81,16 +126,16 @@ TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEdit
return 0; return 0;
} }
// ### TODO create the quickfix state QmlJSQuickFixState *state = new QmlJSQuickFixState;
return 0; state->semanticInfo = info;
return state;
} }
return 0; return 0;
} }
QList<TextEditor::QuickFixOperation::Ptr> QmlJSQuickFixCollector::quickFixOperations(TextEditor::BaseTextEditor *) const QList<TextEditor::QuickFixOperation::Ptr> QmlJSQuickFixCollector::quickFixOperations(TextEditor::BaseTextEditor *editor) const
{ {
QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations; QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations;
return quickFixOperations; return quickFixOperations;
} }
...@@ -30,8 +30,10 @@ ...@@ -30,8 +30,10 @@
#ifndef QMLJSQUICKFIX_H #ifndef QMLJSQUICKFIX_H
#define QMLJSQUICKFIX_H #define QMLJSQUICKFIX_H
#include "qmljseditor.h"
#include <texteditor/quickfix.h> #include <texteditor/quickfix.h>
#include <qmljs/parser/qmljsastfwd_p.h> #include <qmljs/parser/qmljsastfwd_p.h>
#include <qmljs/qmljsdocument.h>
namespace QmlJSEditor { namespace QmlJSEditor {
...@@ -47,6 +49,13 @@ public: ...@@ -47,6 +49,13 @@ public:
QmlJSQuickFixOperation(TextEditor::BaseTextEditor *editor); QmlJSQuickFixOperation(TextEditor::BaseTextEditor *editor);
virtual ~QmlJSQuickFixOperation(); virtual ~QmlJSQuickFixOperation();
QmlJS::Document::Ptr document() const;
const QmlJS::Snapshot &snapshot() const;
const SemanticInfo &semanticInfo() const;
virtual int check() = 0;
virtual int match(TextEditor::QuickFixState *state);
protected: protected:
using TextEditor::QuickFixOperation::move; using TextEditor::QuickFixOperation::move;
using TextEditor::QuickFixOperation::replace; using TextEditor::QuickFixOperation::replace;
...@@ -56,12 +65,18 @@ protected: ...@@ -56,12 +65,18 @@ protected:
using TextEditor::QuickFixOperation::copy; using TextEditor::QuickFixOperation::copy;
using TextEditor::QuickFixOperation::textOf; using TextEditor::QuickFixOperation::textOf;
using TextEditor::QuickFixOperation::charAt; using TextEditor::QuickFixOperation::charAt;
using TextEditor::QuickFixOperation::position;
unsigned position(const QmlJS::AST::SourceLocation &loc) const;
// token based operations // token based operations
void move(const QmlJS::AST::SourceLocation &loc, int to); void move(const QmlJS::AST::SourceLocation &loc, int to);
void replace(const QmlJS::AST::SourceLocation &loc, const QString &replacement); void replace(const QmlJS::AST::SourceLocation &loc, const QString &replacement);
void remove(const QmlJS::AST::SourceLocation &loc); void remove(const QmlJS::AST::SourceLocation &loc);
void copy(const QmlJS::AST::SourceLocation &loc, int to); void copy(const QmlJS::AST::SourceLocation &loc, int to);
private:
SemanticInfo _semanticInfo;
}; };
class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector
...@@ -72,6 +87,7 @@ public: ...@@ -72,6 +87,7 @@ public:
QmlJSQuickFixCollector(); QmlJSQuickFixCollector();
virtual ~QmlJSQuickFixCollector(); virtual ~QmlJSQuickFixCollector();
virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable); virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable);
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const; virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const;
}; };
......
...@@ -181,9 +181,6 @@ TextEditor::ITextEditable *QuickFixCollector::editor() const ...@@ -181,9 +181,6 @@ TextEditor::ITextEditable *QuickFixCollector::editor() const
int QuickFixCollector::startPosition() const int QuickFixCollector::startPosition() const
{ return _editable->position(); } { return _editable->position(); }
bool QuickFixCollector::supportsEditor(TextEditor::ITextEditable *)
{ return true; }
bool QuickFixCollector::triggersCompletion(TextEditor::ITextEditable *) bool QuickFixCollector::triggersCompletion(TextEditor::ITextEditable *)
{ return false; } { return false; }
......
...@@ -125,7 +125,6 @@ public: ...@@ -125,7 +125,6 @@ public:
virtual TextEditor::ITextEditable *editor() const; virtual TextEditor::ITextEditable *editor() const;
virtual int startPosition() const; virtual int startPosition() const;
virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual bool triggersCompletion(TextEditor::ITextEditable *editor); virtual bool triggersCompletion(TextEditor::ITextEditable *editor);
virtual int startCompletion(TextEditor::ITextEditable *editor); virtual int startCompletion(TextEditor::ITextEditable *editor);
virtual void completions(QList<TextEditor::CompletionItem> *completions); virtual void completions(QList<TextEditor::CompletionItem> *completions);
......
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