forked from qt-creator/qt-creator
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: Christiaan Janssen <christiaan.janssen@nokia.com>
This commit is contained in:
@@ -140,8 +140,19 @@ private:
|
|||||||
class ObjectReference
|
class ObjectReference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ObjectReference() : m_debugId(-1), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {}
|
ObjectReference()
|
||||||
explicit ObjectReference(int id) : m_debugId(id), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {}
|
: 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 debugId() const { return m_debugId; }
|
||||||
int parentId() const { return m_parentId; }
|
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=\"Core\" version=\"$$QTCREATOR_VERSION\"/>
|
||||||
<dependency name=\"Find\" version=\"$$QTCREATOR_VERSION\"/>
|
<dependency name=\"Find\" version=\"$$QTCREATOR_VERSION\"/>
|
||||||
<dependency name=\"CppTools\" 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 -->
|
<!-- Debugger plugin adds items to the editor\'s context menu -->
|
||||||
<dependency name=\"CppEditor\" version=\"$$QTCREATOR_VERSION\" type=\"optional\"/>
|
<dependency name=\"CppEditor\" version=\"$$QTCREATOR_VERSION\" type=\"optional\"/>
|
||||||
</dependencyList>
|
</dependencyList>
|
||||||
|
@@ -3,7 +3,6 @@ include(../../plugins/cpptools/cpptools.pri)
|
|||||||
include(../../plugins/find/find.pri)
|
include(../../plugins/find/find.pri)
|
||||||
include(../../plugins/projectexplorer/projectexplorer.pri)
|
include(../../plugins/projectexplorer/projectexplorer.pri)
|
||||||
include(../../plugins/texteditor/texteditor.pri)
|
include(../../plugins/texteditor/texteditor.pri)
|
||||||
include(../../plugins/qmljstools/qmljstools.pri)
|
|
||||||
include(../../libs/cplusplus/cplusplus.pri)
|
include(../../libs/cplusplus/cplusplus.pri)
|
||||||
include(../../libs/utils/utils.pri)
|
include(../../libs/utils/utils.pri)
|
||||||
include(../../libs/symbianutils/symbianutils.pri)
|
include(../../libs/symbianutils/symbianutils.pri)
|
||||||
|
@@ -49,7 +49,6 @@
|
|||||||
#include <qmldebug/qmltoolsclient.h>
|
#include <qmldebug/qmltoolsclient.h>
|
||||||
#include <qmljseditor/qmljseditorconstants.h>
|
#include <qmljseditor/qmljseditorconstants.h>
|
||||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||||
#include <qmljstools/qmljssemanticinfo.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/savedaction.h>
|
#include <utils/savedaction.h>
|
||||||
|
|
||||||
@@ -57,24 +56,6 @@ using namespace QmlDebug;
|
|||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
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
|
* QmlInspectorAdapter manages the clients for the inspector, and the
|
||||||
* integration with the text editor.
|
* integration with the text editor.
|
||||||
@@ -281,7 +262,7 @@ void QmlInspectorAdapter::selectObjectsFromEditor(const QList<int> &debugIds)
|
|||||||
m_cursorPositionChangedExternally = true;
|
m_cursorPositionChangedExternally = true;
|
||||||
m_targetToSync = ToolTarget;
|
m_targetToSync = ToolTarget;
|
||||||
m_debugIdToSelect = debugIds.first();
|
m_debugIdToSelect = debugIds.first();
|
||||||
selectObject(ObjectReference(m_debugIdToSelect), ToolTarget);
|
selectObject(agent()->objectForId(m_debugIdToSelect), ToolTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugIds)
|
void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugIds)
|
||||||
@@ -291,7 +272,7 @@ void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugId
|
|||||||
|
|
||||||
m_targetToSync = EditorTarget;
|
m_targetToSync = EditorTarget;
|
||||||
m_debugIdToSelect = debugIds.first();
|
m_debugIdToSelect = debugIds.first();
|
||||||
selectObject(ObjectReference(m_debugIdToSelect), EditorTarget);
|
selectObject(agent()->objectForId(m_debugIdToSelect), EditorTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref)
|
void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref)
|
||||||
@@ -477,16 +458,14 @@ void QmlInspectorAdapter::showConnectionStatusMessage(const QString &message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAdapter::gotoObjectReferenceDefinition(
|
void QmlInspectorAdapter::gotoObjectReferenceDefinition(
|
||||||
const ObjectReference &obj)
|
const FileReference &objSource)
|
||||||
{
|
{
|
||||||
if (m_cursorPositionChangedExternally) {
|
if (m_cursorPositionChangedExternally) {
|
||||||
m_cursorPositionChangedExternally = false;
|
m_cursorPositionChangedExternally = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReference source = obj.source();
|
const QString fileName = m_engine->toFileInProject(objSource.url());
|
||||||
|
|
||||||
const QString fileName = m_engine->toFileInProject(source.url());
|
|
||||||
|
|
||||||
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||||
Core::IEditor *currentEditor = editorManager->currentEditor();
|
Core::IEditor *currentEditor = editorManager->currentEditor();
|
||||||
@@ -498,46 +477,13 @@ void QmlInspectorAdapter::gotoObjectReferenceDefinition(
|
|||||||
m_selectionCallbackExpected = true;
|
m_selectionCallbackExpected = true;
|
||||||
|
|
||||||
if (textEditor) {
|
if (textEditor) {
|
||||||
if (objectIdForLocation(fileName) != obj.debugId()) {
|
m_selectionCallbackExpected = true;
|
||||||
m_selectionCallbackExpected = true;
|
editorManager->addCurrentPositionToNavigationHistory();
|
||||||
editorManager->addCurrentPositionToNavigationHistory();
|
textEditor->gotoLine(objSource.lineNumber());
|
||||||
textEditor->gotoLine(source.lineNumber());
|
textEditor->widget()->setFocus();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
|
void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
|
||||||
SelectionTarget target)
|
SelectionTarget target)
|
||||||
{
|
{
|
||||||
@@ -546,9 +492,10 @@ void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
|
|||||||
QList<ObjectReference>() << obj);
|
QList<ObjectReference>() << obj);
|
||||||
|
|
||||||
if (target == EditorTarget)
|
if (target == EditorTarget)
|
||||||
gotoObjectReferenceDefinition(obj);
|
gotoObjectReferenceDefinition(obj.source());
|
||||||
|
|
||||||
agent()->selectObjectInTree(obj.debugId());
|
if (!agent()->selectObjectInTree(obj.debugId()))
|
||||||
|
return;
|
||||||
|
|
||||||
m_currentSelectedDebugId = obj.debugId();
|
m_currentSelectedDebugId = obj.debugId();
|
||||||
m_currentSelectedDebugName = agent()->displayName(obj.debugId());
|
m_currentSelectedDebugName = agent()->displayName(obj.debugId());
|
||||||
|
@@ -48,6 +48,7 @@ namespace QmlDebug {
|
|||||||
class BaseEngineDebugClient;
|
class BaseEngineDebugClient;
|
||||||
class BaseToolsClient;
|
class BaseToolsClient;
|
||||||
class ObjectReference;
|
class ObjectReference;
|
||||||
|
class FileReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
@@ -106,9 +107,7 @@ private:
|
|||||||
void initializePreviews();
|
void initializePreviews();
|
||||||
void showConnectionStatusMessage(const QString &message);
|
void showConnectionStatusMessage(const QString &message);
|
||||||
|
|
||||||
void gotoObjectReferenceDefinition(const QmlDebug::ObjectReference &obj);
|
void gotoObjectReferenceDefinition(const QmlDebug::FileReference &objSource);
|
||||||
int objectIdForLocation(
|
|
||||||
const QString &fileName, int cursorPosition = -1) const;
|
|
||||||
|
|
||||||
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
|
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
|
||||||
void selectObject(
|
void selectObject(
|
||||||
|
@@ -110,7 +110,7 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlInspectorAgent::selectObjectInTree(int debugId)
|
bool QmlInspectorAgent::selectObjectInTree(int debugId)
|
||||||
{
|
{
|
||||||
if (debug) {
|
if (debug) {
|
||||||
qDebug() << __FUNCTION__ << "(" << debugId << ")";
|
qDebug() << __FUNCTION__ << "(" << debugId << ")";
|
||||||
@@ -125,10 +125,12 @@ void QmlInspectorAgent::selectObjectInTree(int debugId)
|
|||||||
qDebug() << " selecting" << iname << "in tree";
|
qDebug() << " selecting" << iname << "in tree";
|
||||||
m_debuggerEngine->watchHandler()->setCurrentItem(iname);
|
m_debuggerEngine->watchHandler()->setCurrentItem(iname);
|
||||||
m_objectToSelect = 0;
|
m_objectToSelect = 0;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// we've to fetch it
|
// we've to fetch it
|
||||||
m_objectToSelect = debugId;
|
m_objectToSelect = debugId;
|
||||||
fetchObject(debugId);
|
fetchObject(debugId);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +222,7 @@ quint32 QmlInspectorAgent::resetBindingForObject(int objectDebugId,
|
|||||||
return queryId;
|
return queryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectReference QmlInspectorAgent::objectForId(
|
ObjectReference QmlInspectorAgent::objectForName(
|
||||||
const QString &objectId) const
|
const QString &objectId) const
|
||||||
{
|
{
|
||||||
if (!objectId.isEmpty() && objectId[0].isLower()) {
|
if (!objectId.isEmpty() && objectId[0].isLower()) {
|
||||||
@@ -234,6 +236,36 @@ ObjectReference QmlInspectorAgent::objectForId(
|
|||||||
return ObjectReference();
|
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 QmlInspectorAgent::objectIdForLocation(
|
||||||
int line, int column) const
|
int line, int column) const
|
||||||
{
|
{
|
||||||
|
@@ -64,7 +64,7 @@ public:
|
|||||||
|
|
||||||
void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV);
|
void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV);
|
||||||
void updateWatchData(const WatchData &data);
|
void updateWatchData(const WatchData &data);
|
||||||
void selectObjectInTree(int debugId);
|
bool selectObjectInTree(int debugId);
|
||||||
|
|
||||||
quint32 setBindingForObject(int objectDebugId,
|
quint32 setBindingForObject(int objectDebugId,
|
||||||
const QString &propertyName,
|
const QString &propertyName,
|
||||||
@@ -77,7 +77,8 @@ public:
|
|||||||
quint32 resetBindingForObject(int objectDebugId,
|
quint32 resetBindingForObject(int objectDebugId,
|
||||||
const QString &propertyName);
|
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;
|
int objectIdForLocation(int line, int column) const;
|
||||||
QHash<int, QString> rootObjectIds() const;
|
QHash<int, QString> rootObjectIds() const;
|
||||||
DebugIdHash debugIdHash() const { return m_debugIdHash; }
|
DebugIdHash debugIdHash() const { return m_debugIdHash; }
|
||||||
|
@@ -540,7 +540,7 @@ bool QmlLiveTextPreview::changeSelectedElements(const QList<int> offsets,
|
|||||||
m_lastOffsets = offsets;
|
m_lastOffsets = offsets;
|
||||||
ObjectReference objectRefUnderCursor;
|
ObjectReference objectRefUnderCursor;
|
||||||
objectRefUnderCursor
|
objectRefUnderCursor
|
||||||
= m_inspectorAdapter->agent()->objectForId(wordAtCursor);
|
= m_inspectorAdapter->agent()->objectForName(wordAtCursor);
|
||||||
|
|
||||||
QList<int> selectedReferences;
|
QList<int> selectedReferences;
|
||||||
bool containsReferenceUnderCursor = false;
|
bool containsReferenceUnderCursor = false;
|
||||||
|
Reference in New Issue
Block a user