Commit f5dae8bc authored by Roberto Raggi's avatar Roberto Raggi

Refactored the quickfix engine.

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