Qml Debugger: Do not focus the current frame when adding a watch

The other debuggers do not cause the view to jump to the current frame
when adding a watch. Make the Qml debugger also not do this.

This is done in a slightly hacky way by preventing the gotoLocation of
the next handleFrame call to be executed. Ideally, the logic to
retrieve the value of locals should be separated from the logic to jump
to a specific frame. Right now the jump is implicit when updating the
locals.

Fixes: QTCREATORBUG-29329
Change-Id: I4b8f5c99ae41c92c3394f86da481303d4765f897
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Olivier De Cannière
2023-11-09 10:37:34 +01:00
parent 2f7bfd3ef8
commit 08546615f2
3 changed files with 12 additions and 6 deletions

View File

@@ -2411,6 +2411,7 @@ void DebuggerEngine::updateWatchData(const QString &iname)
// e.g. when changing the expression in a watcher. // e.g. when changing the expression in a watcher.
UpdateParameters params; UpdateParameters params;
params.partialVariable = iname; params.partialVariable = iname;
params.qmlFocusOnFrame = false;
doUpdateLocals(params); doUpdateLocals(params);
} }

View File

@@ -214,6 +214,7 @@ public:
} }
QString partialVariable; QString partialVariable;
bool qmlFocusOnFrame = true; // QTCREATORBUG-29874
}; };
class Location class Location

View File

@@ -141,7 +141,7 @@ public:
void evaluate(const QString expr, qint64 context, const QmlCallback &cb); void evaluate(const QString expr, qint64 context, const QmlCallback &cb);
void lookup(const LookupItems &items); void lookup(const LookupItems &items);
void backtrace(); void backtrace();
void updateLocals(); void updateLocals(bool focusOnFrame = true);
void scope(int number, int frameNumber = -1); void scope(int number, int frameNumber = -1);
void scripts(int types = 4, const QList<int> ids = QList<int>(), void scripts(int types = 4, const QList<int> ids = QList<int>(),
bool includeSource = false, const QVariant filter = QVariant()); bool includeSource = false, const QVariant filter = QVariant());
@@ -216,6 +216,8 @@ public:
FileInProjectFinder fileFinder; FileInProjectFinder fileFinder;
bool skipFocusOnNextHandleFrame = false;
private: private:
ConsoleItem *constructLogItemTree(const QmlV8ObjectData &objectData, QList<int> &seenHandles); ConsoleItem *constructLogItemTree(const QmlV8ObjectData &objectData, QList<int> &seenHandles);
void constructChildLogItems(ConsoleItem *item, const QmlV8ObjectData &objectData, void constructChildLogItems(ConsoleItem *item, const QmlV8ObjectData &objectData,
@@ -791,7 +793,7 @@ void QmlEngine::assignValueInDebugger(WatchItem *item,
StackHandler *handler = stackHandler(); StackHandler *handler = stackHandler();
QString exp = QString("%1 = %2;").arg(expression).arg(value.toString()); QString exp = QString("%1 = %2;").arg(expression).arg(value.toString());
if (handler->isContentsValid() && handler->currentFrame().isUsable()) { if (handler->isContentsValid() && handler->currentFrame().isUsable()) {
d->evaluate(exp, -1, [this](const QVariantMap &) { d->updateLocals(); }); d->evaluate(exp, -1, [this](const QVariantMap &) { d->updateLocals(false); });
} else { } else {
showMessage(Tr::tr("Cannot evaluate %1 in current stack frame.") showMessage(Tr::tr("Cannot evaluate %1 in current stack frame.")
.arg(expression), ConsoleOutput); .arg(expression), ConsoleOutput);
@@ -941,8 +943,7 @@ void QmlEngine::quitDebugger()
void QmlEngine::doUpdateLocals(const UpdateParameters &params) void QmlEngine::doUpdateLocals(const UpdateParameters &params)
{ {
Q_UNUSED(params) d->updateLocals(params.qmlFocusOnFrame);
d->updateLocals();
} }
Context QmlEngine::languageContext() const Context QmlEngine::languageContext() const
@@ -1292,13 +1293,14 @@ void QmlEnginePrivate::backtrace()
runCommand(cmd, CB(handleBacktrace)); runCommand(cmd, CB(handleBacktrace));
} }
void QmlEnginePrivate::updateLocals() void QmlEnginePrivate::updateLocals(bool focusOnFrame)
{ {
// { "seq" : <number>, // { "seq" : <number>,
// "type" : "request", // "type" : "request",
// "command" : "frame", // "command" : "frame",
// "arguments" : { "number" : <frame number> } // "arguments" : { "number" : <frame number> }
// } // }
skipFocusOnNextHandleFrame = focusOnFrame;
DebuggerCommand cmd(FRAME); DebuggerCommand cmd(FRAME);
cmd.arg(NUMBER, stackIndexLookup.value(engine->stackHandler()->currentIndex())); cmd.arg(NUMBER, stackIndexLookup.value(engine->stackHandler()->currentIndex()));
@@ -2136,7 +2138,9 @@ void QmlEnginePrivate::handleFrame(const QVariantMap &response)
currentFrameScopes.append(scopeIndex); currentFrameScopes.append(scopeIndex);
this->scope(scopeIndex); this->scope(scopeIndex);
} }
engine->gotoLocation(stackHandler->currentFrame());
if (skipFocusOnNextHandleFrame)
engine->gotoLocation(stackHandler->currentFrame());
// Send watchers list // Send watchers list
if (stackHandler->isContentsValid() && stackHandler->currentFrame().isUsable()) { if (stackHandler->isContentsValid() && stackHandler->currentFrame().isUsable()) {