Skip to content

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

Closed

Description

@osaxma

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"

Activity

  1. DanTup commented on Aug 21, 2023

    @DanTup
    Member

    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
    		}
    	},
  2. added this to the v3.72.0 milestone on Aug 21, 2023
  3. added
    in debuggingRelates to the debug adapter or process of running debug sessions
    in testingRelates to test execution of Dart/Flutter tests for end users
    on Aug 21, 2023
  4. 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[/+] on Aug 21, 2023
  5. modified the milestones: v3.72.0, v3.74.0 on Aug 31, 2023
  6. DanTup commented on Sep 6, 2023

    @DanTup
    Member
  7. DanTup commented on Sep 23, 2023

    @DanTup
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in debuggingRelates to the debug adapter or process of running debug sessionsin testingRelates to test execution of Dart/Flutter tests for end usersis bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions