[dds/dap] Optimise computing line/col for stack frames

See https://github.com/Dart-Code/Dart-Code/issues/4209 / https://github.com/Dart-Code/Dart-Code/issues/4208.

Change-Id: I62f029d50e7b0b1964868c9221ca7b0a387dc23a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263300
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Danny Tuppeny 2022-10-10 18:22:23 +00:00 committed by Commit Queue
parent 38581783e6
commit 946eec8330

View file

@ -397,14 +397,19 @@ class ProtocolConverter {
canShowSource = true;
}
var line = 0, col = 0;
if (scriptRef != null && tokenPos != null) {
try {
final script = await thread.getScript(scriptRef);
line = script.getLineNumberFromTokenPos(tokenPos) ?? 0;
col = script.getColumnNumberFromTokenPos(tokenPos) ?? 0;
} catch (e) {
_adapter.logger?.call('Failed to map frame location to line/col: $e');
// First try to use line/col from location to avoid fetching scripts.
// LSP doesn't support nullable lines so we use 0 as where we can't map.
var line = location.line ?? 0;
var col = location.column ?? 0;
if (line == 0 || col == 0) {
if (scriptRef != null && tokenPos != null) {
try {
final script = await thread.getScript(scriptRef);
line = script.getLineNumberFromTokenPos(tokenPos) ?? 0;
col = script.getColumnNumberFromTokenPos(tokenPos) ?? 0;
} catch (e) {
_adapter.logger?.call('Failed to map frame location to line/col: $e');
}
}
}