Commit 20902cf1 authored by Lasse Holmstedt's avatar Lasse Holmstedt

Moved debug id -> AST mapping code to livepreview class

parent f8fc9084
......@@ -143,7 +143,6 @@ Inspector::Inspector(QObject *parent)
connect(m_clientProxy, SIGNAL(aboutToReloadEngines()), SLOT(aboutToReloadEngines()));
connect(m_clientProxy, SIGNAL(enginesChanged()), SLOT(updateEngineList()));
connect(m_clientProxy, SIGNAL(aboutToDisconnect()), SLOT(disconnectWidgets()));
connect(m_clientProxy, SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)), SLOT(objectTreeUpdated(QDeclarativeDebugObjectReference)));
connect(Debugger::DebuggerPlugin::instance(),
SIGNAL(stateChanged(int)), this, SLOT(debuggerStateChanged(int)));
......@@ -569,66 +568,3 @@ bool Inspector::addQuotesForData(const QVariant &value) const
return false;
}
/*!
Associates the UiObjectMember* to their QDeclarativeDebugObjectReference.
*/
class MapObjectWithDebugReference : public Visitor
{
public:
virtual void endVisit(UiObjectDefinition *ast) ;
virtual void endVisit(UiObjectBinding *ast) ;
QDeclarativeDebugObjectReference root;
QString filename;
QHash<UiObjectMember *, QList<QDeclarativeDebugObjectReference> > result;
private:
void processRecursive(const QDeclarativeDebugObjectReference &object, UiObjectMember *ast);
};
void MapObjectWithDebugReference::endVisit(UiObjectDefinition* ast)
{
if (ast->qualifiedTypeNameId->name->asString().at(0).isUpper())
processRecursive(root, ast);
}
void MapObjectWithDebugReference::endVisit(UiObjectBinding* ast)
{
if (ast->qualifiedId->name->asString().at(0).isUpper())
processRecursive(root, ast);
}
void MapObjectWithDebugReference::processRecursive(const QDeclarativeDebugObjectReference& object, UiObjectMember* ast)
{
// If this is too slow, it can be speed up by indexing
// the QDeclarativeDebugObjectReference by filename/loc in a fist pass
SourceLocation loc = ast->firstSourceLocation();
if (object.source().lineNumber() == int(loc.startLine) && object.source().columnNumber() == int(loc.startColumn) && object.source().url().toLocalFile() == filename) {
result[ast] += object;
}
foreach (const QDeclarativeDebugObjectReference &it, object.children()) {
processRecursive(it, ast);
}
}
void QmlJSInspector::Internal::Inspector::objectTreeUpdated(const QDeclarativeDebugObjectReference &ref)
{
QmlJS::ModelManagerInterface *m = QmlJS::ModelManagerInterface::instance();
Snapshot snapshot = m->snapshot();
QHash<QString, QHash<UiObjectMember *, QList< QDeclarativeDebugObjectReference> > > allDebugIds;
foreach(const Document::Ptr &doc, snapshot) {
if (!doc->qmlProgram())
continue;
MapObjectWithDebugReference visitor;
visitor.root = ref;
QString filename = doc->fileName();
visitor.filename = filename;
doc->qmlProgram()->accept(&visitor);
allDebugIds[filename] = visitor.result;
}
//FIXME
m_textPreview->m_initialTable = allDebugIds;
m_textPreview->m_debugIds.clear();
}
......@@ -117,8 +117,6 @@ private slots:
void disconnectWidgets();
void disconnected();
void objectTreeUpdated(const QDeclarativeDebugObjectReference &ref);
private:
Debugger::DebuggerRunControl *createDebuggerRunControl(ProjectExplorer::RunConfiguration *runConfig,
const QString &executableFile = QString(),
......
......@@ -23,12 +23,59 @@ using namespace QmlJS::AST;
namespace QmlJSInspector {
namespace Internal {
/*!
Associates the UiObjectMember* to their QDeclarativeDebugObjectReference.
*/
class MapObjectWithDebugReference : public Visitor
{
public:
virtual void endVisit(UiObjectDefinition *ast) ;
virtual void endVisit(UiObjectBinding *ast) ;
QDeclarativeDebugObjectReference root;
QString filename;
QHash<UiObjectMember *, QList<QDeclarativeDebugObjectReference> > result;
private:
void processRecursive(const QDeclarativeDebugObjectReference &object, UiObjectMember *ast);
};
void MapObjectWithDebugReference::endVisit(UiObjectDefinition* ast)
{
if (ast->qualifiedTypeNameId->name->asString().at(0).isUpper())
processRecursive(root, ast);
}
void MapObjectWithDebugReference::endVisit(UiObjectBinding* ast)
{
if (ast->qualifiedId->name->asString().at(0).isUpper())
processRecursive(root, ast);
}
void MapObjectWithDebugReference::processRecursive(const QDeclarativeDebugObjectReference& object, UiObjectMember* ast)
{
// If this is too slow, it can be speed up by indexing
// the QDeclarativeDebugObjectReference by filename/loc in a fist pass
SourceLocation loc = ast->firstSourceLocation();
if (object.source().lineNumber() == int(loc.startLine) && object.source().columnNumber() == int(loc.startColumn) && object.source().url().toLocalFile() == filename) {
result[ast] += object;
}
foreach (const QDeclarativeDebugObjectReference &it, object.children()) {
processRecursive(it, ast);
}
}
QmlJSLiveTextPreview::QmlJSLiveTextPreview(QObject *parent) :
QObject(parent)
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
connect(editorManager->instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
ClientProxy *clientProxy = ClientProxy::instance();
connect(editorManager->instance(),
SIGNAL(currentEditorChanged(Core::IEditor*)),
SLOT(setEditor(Core::IEditor*)));
connect(clientProxy,
SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)),
SLOT(updateDebugIds(QDeclarativeDebugObjectReference)));
}
QmlJS::ModelManagerInterface *QmlJSLiveTextPreview::modelManager()
......@@ -132,6 +179,26 @@ void QmlJSLiveTextPreview::setEditor(Core::IEditor *editor)
}
}
void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference &rootReference)
{
QmlJS::ModelManagerInterface *m = QmlJS::ModelManagerInterface::instance();
Snapshot snapshot = m->snapshot();
QHash<QString, QHash<UiObjectMember *, QList< QDeclarativeDebugObjectReference> > > allDebugIds;
foreach(const Document::Ptr &doc, snapshot) {
if (!doc->qmlProgram())
continue;
MapObjectWithDebugReference visitor;
visitor.root = rootReference;
QString filename = doc->fileName();
visitor.filename = filename;
doc->qmlProgram()->accept(&visitor);
allDebugIds[filename] = visitor.result;
}
m_initialTable = allDebugIds;
m_debugIds.clear();
}
void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
{
Core::ICore *core = Core::ICore::instance();
......@@ -140,7 +207,9 @@ void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
if (!core->hasContext(dbgcontext))
return;
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName() && doc->qmlProgram() && m_previousDoc->qmlProgram()) {
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName()
&& doc->qmlProgram() && m_previousDoc->qmlProgram())
{
if (m_debugIds.isEmpty())
m_debugIds = m_initialTable.value(doc->fileName());
......
......@@ -50,6 +50,7 @@ private slots:
void changeSelectedElements(QList<int> offsets, const QString &wordAtCursor);
void documentChanged(QmlJS::Document::Ptr doc);
void setEditor(Core::IEditor *editor);
void updateDebugIds(const QDeclarativeDebugObjectReference &rootReference);
private:
QList<QDeclarativeDebugObjectReference > objectReferencesForOffset(quint32 offset) const;
......
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