Skip to content

Cursor moves to beginning of file while stepping if an exception occurs during a test #4692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
osaxma opened this issue Aug 18, 2023 · 3 comments
Labels
in debugger Relates to the debug adapter or process of launching a debug session in testing Relates to test execution of Dart/Flutter tests for end users is bug
Milestone

Comments

@osaxma
Copy link

osaxma commented Aug 18, 2023

Hello there,

It's been a while since I came by .. hope all is well!

Describe the bug

When running a test in debug mode, the cursor in the test file moves to the beginning of the file after each run.

This is inconvenient since after each time I run the test, I have to scroll back to the line wherever the test is to run it again.

To Reproduce
Steps to reproduce the behavior:

  1. create a new dart project (i.e. dart create debug_cursor_issue)

  2. go to the test file and paste the sample code there (given below).

  3. scroll down to the test

  4. place the cursor somewhere within the test

  5. click on the debug button shown above the test within the file.
    image

  6. click the continue button in the debugger controller until the end.

  7. the cursor now should've moved to the top of the file.

>>>> Sample Code <<<<<<
import 'package:dart_code_test_bug/dart_code_test_bug.dart';
import 'package:test/test.dart';

/* 

LONG COMMENT TO SIMULATE THE BUG 


Jump to line 100 

























































































 */

void main() {
  test('calculate', () {
    try {
      expect(true, false);
    } on FormatException catch (e) {
      //
    }
  });
}

Expected behavior

I expect the cursor to stay in its place -- it's inconvenient to keep scrolling back after each run especially in large test files.

Please complete the following information:

  • Operating System and version: 12.6 (21G115)
  • VS Code version: 1.81.1
  • Dart extension version: v3.70.0
  • Dart/Flutter SDK version: Dart SDK version: 3.1.0 (stable) (Tue Aug 15 21:33:36 2023 +0000) on "macos_x64"
@osaxma osaxma added the is bug label Aug 18, 2023
@DanTup
Copy link
Member

DanTup commented Aug 21, 2023

I can reproduce this when debugging and an exception occurs. The exception breaks here:

Screenshot 2023-08-21 105624

And then clicking continue causes it to pause on the next frame up here:

Screenshot 2023-08-21 105627

I think this is because tokenPos in topFrame is -1 (see below). However, there is a function which has a valid location. I wonder whether the -1 is a bug or not - and if it's not, whether it's valid to use the location from function. I'll do some digging.

That said - even with this fixed so it doesn't jump to the top of the file, I don't know that it will solve this entire class of issue. If you hit an exception and click the Continue button, you're going to end up stepping up through a lot of code, so you may still end up in a different place to the test if the test wasn't the top stack frame.

"topFrame": {
	"type": "Frame",
	"kind": "Regular",
	"location": {
		"type": "SourceLocation",
		"script": {
			"type": "@Script",
			"fixedId": true,
			"id": "libraries/@18177300/scripts/file%3A%2F%2F%2FC%3A%2FDev%2FTest%2520Projects%2Fdart_sample%2Ftest%2Fdart_sample_test.dart/18a17861956",
			"uri": "file:///C:/Dev/Test%20Projects/dart_sample/test/dart_sample_test.dart"
		},
		"tokenPos": -1
	},
	"function": {
		"type": "@Function",
		"fixedId": true,
		"id": "libraries/@18177300/closures/47",
		"name": "<anonymous closure>",
		"static": true,
		"const": false,
		"implicit": false,
		"abstract": false,
		"location": {
			"type": "SourceLocation",
			"script": {
				"type": "@Script",
				"fixedId": true,
				"id": "libraries/@18177300/scripts/file%3A%2F%2F%2FC%3A%2FDev%2FTest%2520Projects%2Fdart_sample%2Ftest%2Fdart_sample_test.dart/18a17861956",
				"uri": "file:///C:/Dev/Test%20Projects/dart_sample/test/dart_sample_test.dart"
			},
			"tokenPos": 218,
			"endTokenPos": 315,
			"line": 101,
			"column": 21
		}
	},

@DanTup DanTup added this to the v3.72.0 milestone Aug 21, 2023
@DanTup DanTup added in debugger Relates to the debug adapter or process of launching a debug session in testing Relates to test execution of Dart/Flutter tests for end users labels Aug 21, 2023
@DanTup DanTup changed the title Cursor moves to beginning of file after debug test Cursor moves to beginning of file while stepping if an exception occurs during a test Aug 21, 2023
@DanTup DanTup modified the milestones: v3.72.0, v3.74.0 Aug 31, 2023
@DanTup
Copy link
Member

DanTup commented Sep 6, 2023

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Sep 22, 2023
Some functions when debugging tests have tokenPos=-1 which results in the debugger jumping to the top of the file. If the function has a location, this seems to be more appropriate to use.

Fixes Dart-Code/Dart-Code#4692

Change-Id: I7a800de4f9ce94deb5d35919cab658dee881d439
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324522
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Helin Shiah <helinx@google.com>
@DanTup
Copy link
Member

DanTup commented Sep 23, 2023

Fixed by dart-lang/sdk@a780653. The change ships in the SDK, not the VS Code extension.

@DanTup DanTup closed this as completed Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in debugger Relates to the debug adapter or process of launching a debug session in testing Relates to test execution of Dart/Flutter tests for end users is bug
Projects
None yet
Development

No branches or pull requests

2 participants