Commit 799fc18b authored by Aurindam Jana's avatar Aurindam Jana

QmlJSInspector: Remove dependency on QmlJSTools

As Location information is already cached, there is no
need to fetch the information from the QmlJS Semantic info.

Task-number: QTCREATORBUG-7409
Change-Id: I9cc3dce0910632cfe517f7697d74691e6675793b
Reviewed-by: default avatarChristiaan Janssen <christiaan.janssen@nokia.com>
parent 012281cd
......@@ -140,8 +140,19 @@ private:
class ObjectReference
{
public:
ObjectReference() : m_debugId(-1), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {}
explicit ObjectReference(int id) : m_debugId(id), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {}
ObjectReference()
: m_debugId(-1), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false)
{
}
explicit ObjectReference(int id)
: m_debugId(id), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false)
{
}
ObjectReference(int id, int parentId, const FileReference &source)
: m_debugId(id), m_parentId(parentId), m_source(source),
m_contextDebugId(-1), m_needsMoreData(false)
{
}
int debugId() const { return m_debugId; }
int parentId() const { return m_parentId; }
......
......@@ -18,7 +18,6 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
<dependency name=\"Core\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"Find\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"CppTools\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"QmlJSTools\" version=\"$$QTCREATOR_VERSION\"/>
<!-- Debugger plugin adds items to the editor\'s context menu -->
<dependency name=\"CppEditor\" version=\"$$QTCREATOR_VERSION\" type=\"optional\"/>
</dependencyList>
......
......@@ -3,7 +3,6 @@ include(../../plugins/cpptools/cpptools.pri)
include(../../plugins/find/find.pri)
include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/qmljstools/qmljstools.pri)
include(../../libs/cplusplus/cplusplus.pri)
include(../../libs/utils/utils.pri)
include(../../libs/symbianutils/symbianutils.pri)
......
......@@ -49,7 +49,6 @@
#include <qmldebug/qmltoolsclient.h>
#include <qmljseditor/qmljseditorconstants.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljstools/qmljssemanticinfo.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
......@@ -57,24 +56,6 @@ using namespace QmlDebug;
namespace Debugger {
namespace Internal {
// Get semantic info from QmlJSTextEditorWidget
// (we use the meta object system here to avoid having to link
// against qmljseditor)
static QmlJSTools::SemanticInfo getSemanticInfo(QPlainTextEdit *qmlJSTextEdit)
{
QmlJSTools::SemanticInfo info;
QTC_ASSERT(QLatin1String(qmlJSTextEdit->metaObject()->className())
== QLatin1String("QmlJSEditor::QmlJSTextEditorWidget"),
return info);
QTC_ASSERT(qmlJSTextEdit->metaObject()->indexOfProperty("semanticInfo")
!= -1, return info);
info = qmlJSTextEdit->property("semanticInfo")
.value<QmlJSTools::SemanticInfo>();
return info;
}
/*!
* QmlInspectorAdapter manages the clients for the inspector, and the
* integration with the text editor.
......@@ -281,7 +262,7 @@ void QmlInspectorAdapter::selectObjectsFromEditor(const QList<int> &debugIds)
m_cursorPositionChangedExternally = true;
m_targetToSync = ToolTarget;
m_debugIdToSelect = debugIds.first();
selectObject(ObjectReference(m_debugIdToSelect), ToolTarget);
selectObject(agent()->objectForId(m_debugIdToSelect), ToolTarget);
}
void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugIds)
......@@ -291,7 +272,7 @@ void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugId
m_targetToSync = EditorTarget;
m_debugIdToSelect = debugIds.first();
selectObject(ObjectReference(m_debugIdToSelect), EditorTarget);
selectObject(agent()->objectForId(m_debugIdToSelect), EditorTarget);
}
void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref)
......@@ -477,16 +458,14 @@ void QmlInspectorAdapter::showConnectionStatusMessage(const QString &message)
}
void QmlInspectorAdapter::gotoObjectReferenceDefinition(
const ObjectReference &obj)
const FileReference &objSource)
{
if (m_cursorPositionChangedExternally) {
m_cursorPositionChangedExternally = false;
return;
}
FileReference source = obj.source();
const QString fileName = m_engine->toFileInProject(source.url());
const QString fileName = m_engine->toFileInProject(objSource.url());
Core::EditorManager *editorManager = Core::EditorManager::instance();
Core::IEditor *currentEditor = editorManager->currentEditor();
......@@ -498,44 +477,11 @@ void QmlInspectorAdapter::gotoObjectReferenceDefinition(
m_selectionCallbackExpected = true;
if (textEditor) {
if (objectIdForLocation(fileName) != obj.debugId()) {
m_selectionCallbackExpected = true;
editorManager->addCurrentPositionToNavigationHistory();
textEditor->gotoLine(source.lineNumber());
textEditor->widget()->setFocus();
}
}
}
int QmlInspectorAdapter::objectIdForLocation(
const QString &fileName, int cursorPosition) const
{
Core::IEditor *editor = Core::EditorManager::openEditor(fileName);
TextEditor::ITextEditor *textEditor
= qobject_cast<TextEditor::ITextEditor*>(editor);
if (textEditor
&& textEditor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) {
if (cursorPosition == -1)
cursorPosition = textEditor->position();
TextEditor::BaseTextEditor *baseTextEditor =
static_cast<TextEditor::BaseTextEditor*>(editor);
QPlainTextEdit *editWidget
= qobject_cast<QPlainTextEdit*>(baseTextEditor->widget());
QmlJSTools::SemanticInfo semanticInfo = getSemanticInfo(editWidget);
if (QmlJS::AST::Node *node
= semanticInfo.declaringMemberNoProperties(cursorPosition)) {
if (QmlJS::AST::UiObjectMember *objMember
= node->uiObjectMemberCast()) {
return agent()->objectIdForLocation(
objMember->firstSourceLocation().startLine,
objMember->firstSourceLocation().startColumn);
}
}
m_selectionCallbackExpected = true;
editorManager->addCurrentPositionToNavigationHistory();
textEditor->gotoLine(objSource.lineNumber());
textEditor->widget()->setFocus();
}
return -1;
}
void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
......@@ -546,9 +492,10 @@ void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
QList<ObjectReference>() << obj);
if (target == EditorTarget)
gotoObjectReferenceDefinition(obj);
gotoObjectReferenceDefinition(obj.source());
agent()->selectObjectInTree(obj.debugId());
if (!agent()->selectObjectInTree(obj.debugId()))
return;
m_currentSelectedDebugId = obj.debugId();
m_currentSelectedDebugName = agent()->displayName(obj.debugId());
......
......@@ -48,6 +48,7 @@ namespace QmlDebug {
class BaseEngineDebugClient;
class BaseToolsClient;
class ObjectReference;
class FileReference;
}
namespace Debugger {
......@@ -106,9 +107,7 @@ private:
void initializePreviews();
void showConnectionStatusMessage(const QString &message);
void gotoObjectReferenceDefinition(const QmlDebug::ObjectReference &obj);
int objectIdForLocation(
const QString &fileName, int cursorPosition = -1) const;
void gotoObjectReferenceDefinition(const QmlDebug::FileReference &objSource);
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
void selectObject(
......
......@@ -110,7 +110,7 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data)
}
}
void QmlInspectorAgent::selectObjectInTree(int debugId)
bool QmlInspectorAgent::selectObjectInTree(int debugId)
{
if (debug) {
qDebug() << __FUNCTION__ << "(" << debugId << ")";
......@@ -125,10 +125,12 @@ void QmlInspectorAgent::selectObjectInTree(int debugId)
qDebug() << " selecting" << iname << "in tree";
m_debuggerEngine->watchHandler()->setCurrentItem(iname);
m_objectToSelect = 0;
return true;
} else {
// we've to fetch it
m_objectToSelect = debugId;
fetchObject(debugId);
return false;
}
}
......@@ -220,7 +222,7 @@ quint32 QmlInspectorAgent::resetBindingForObject(int objectDebugId,
return queryId;
}
ObjectReference QmlInspectorAgent::objectForId(
ObjectReference QmlInspectorAgent::objectForName(
const QString &objectId) const
{
if (!objectId.isEmpty() && objectId[0].isLower()) {
......@@ -234,6 +236,36 @@ ObjectReference QmlInspectorAgent::objectForId(
return ObjectReference();
}
ObjectReference QmlInspectorAgent::objectForId(int objectDebugId) const
{
if (!m_debugIdToIname.contains(objectDebugId))
return ObjectReference(objectDebugId);
int line = -1;
int column = -1;
QString file;
QHashIterator<QPair<QString, int>, QHash<QPair<int, int>, QList<int> > > iter(m_debugIdHash);
while (iter.hasNext()) {
iter.next();
QHashIterator<QPair<int, int>, QList<int> > i(iter.value());
while (i.hasNext()) {
i.next();
if (i.value().contains(objectDebugId)) {
line = i.key().first;
column = i.key().second;
break;
}
}
if (line != -1) {
file = iter.key().first;
break;
}
}
// TODO: Set correct parentId
return ObjectReference(objectDebugId, -1,
FileReference(QUrl::fromLocalFile(file), line, column));
}
int QmlInspectorAgent::objectIdForLocation(
int line, int column) const
{
......
......@@ -64,7 +64,7 @@ public:
void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV);
void updateWatchData(const WatchData &data);
void selectObjectInTree(int debugId);
bool selectObjectInTree(int debugId);
quint32 setBindingForObject(int objectDebugId,
const QString &propertyName,
......@@ -77,7 +77,8 @@ public:
quint32 resetBindingForObject(int objectDebugId,
const QString &propertyName);
QmlDebug::ObjectReference objectForId(const QString &objectId) const;
QmlDebug::ObjectReference objectForName(const QString &objectId) const;
QmlDebug::ObjectReference objectForId(int objectDebugId) const;
int objectIdForLocation(int line, int column) const;
QHash<int, QString> rootObjectIds() const;
DebugIdHash debugIdHash() const { return m_debugIdHash; }
......
......@@ -540,7 +540,7 @@ bool QmlLiveTextPreview::changeSelectedElements(const QList<int> offsets,
m_lastOffsets = offsets;
ObjectReference objectRefUnderCursor;
objectRefUnderCursor
= m_inspectorAdapter->agent()->objectForId(wordAtCursor);
= m_inspectorAdapter->agent()->objectForName(wordAtCursor);
QList<int> selectedReferences;
bool containsReferenceUnderCursor = false;
......
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