From 3fb237d6d62d8f290a3d179a61ca9642bc5fe1f3 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Tue, 14 Nov 2023 10:32:23 +0000 Subject: [PATCH] Accept project root paths in debug sessions for sidebar (#6715) See https://github.com/flutter/devtools/pull/6709 Dart-Code will pass a project root* for debug sessions: ![image](https://github.com/flutter/devtools/assets/1078012/7f01b54c-bbbc-408f-8074-4a3af0f99338) \* if it's able to compute one - which it always should for the cases we care about, but there are some edge cases that mean the field might be missing. --- .../lib/src/standalone_ui/api/impl/vs_code_api.dart | 7 +++++++ .../lib/src/standalone_ui/api/vs_code_api.dart | 11 +++++++++++ .../test_data/dart_tooling_api/mock_api.dart | 1 + 3 files changed, 19 insertions(+) diff --git a/packages/devtools_app/lib/src/standalone_ui/api/impl/vs_code_api.dart b/packages/devtools_app/lib/src/standalone_ui/api/impl/vs_code_api.dart index a00cbbb4ef9..4876ecdcaf6 100644 --- a/packages/devtools_app/lib/src/standalone_ui/api/impl/vs_code_api.dart +++ b/packages/devtools_app/lib/src/standalone_ui/api/impl/vs_code_api.dart @@ -167,6 +167,7 @@ class VsCodeDebugSessionImpl implements VsCodeDebugSession { required this.flutterMode, required this.flutterDeviceId, required this.debuggerType, + required this.projectRootPath, }); VsCodeDebugSessionImpl.fromJson(Map json) @@ -180,6 +181,8 @@ class VsCodeDebugSessionImpl implements VsCodeDebugSession { json[VsCodeDebugSession.jsonFlutterDeviceIdField] as String?, debuggerType: json[VsCodeDebugSession.jsonDebuggerTypeField] as String?, + projectRootPath: + json[VsCodeDebugSession.jsonProjectRootPathField] as String?, ); @override @@ -200,6 +203,9 @@ class VsCodeDebugSessionImpl implements VsCodeDebugSession { @override final String? debuggerType; + @override + final String? projectRootPath; + Map toJson() => { VsCodeDebugSession.jsonIdField: id, VsCodeDebugSession.jsonNameField: name, @@ -207,6 +213,7 @@ class VsCodeDebugSessionImpl implements VsCodeDebugSession { VsCodeDebugSession.jsonFlutterModeField: flutterMode, VsCodeDebugSession.jsonFlutterDeviceIdField: flutterDeviceId, VsCodeDebugSession.jsonDebuggerTypeField: debuggerType, + VsCodeDebugSession.jsonProjectRootPathField: projectRootPath, }; } diff --git a/packages/devtools_app/lib/src/standalone_ui/api/vs_code_api.dart b/packages/devtools_app/lib/src/standalone_ui/api/vs_code_api.dart index 75872af65cb..c7870421da0 100644 --- a/packages/devtools_app/lib/src/standalone_ui/api/vs_code_api.dart +++ b/packages/devtools_app/lib/src/standalone_ui/api/vs_code_api.dart @@ -151,12 +151,23 @@ abstract interface class VsCodeDebugSession { /// - WebTest (webdev test) String? get debuggerType; + /// The full path to the root of this project (the folder that contains the + /// `pubspec.yaml`). + /// + /// This path might not always be available, for example: + /// + /// - When the version of Dart-Code is from before this field was added + /// - When a debug session was an attach and we didn't know the source + /// - When the program being run is a lose file without any pubspec + String? get projectRootPath; + static const jsonIdField = 'id'; static const jsonNameField = 'name'; static const jsonVmServiceUriField = 'vmServiceUri'; static const jsonFlutterModeField = 'flutterMode'; static const jsonFlutterDeviceIdField = 'flutterDeviceId'; static const jsonDebuggerTypeField = 'debuggerType'; + static const jsonProjectRootPathField = 'projectRootPath'; } /// This class defines a device event sent by the Dart/Flutter extensions in VS diff --git a/packages/devtools_app/test/test_infra/test_data/dart_tooling_api/mock_api.dart b/packages/devtools_app/test/test_infra/test_data/dart_tooling_api/mock_api.dart index ac7504c1fd2..21b6fc77226 100644 --- a/packages/devtools_app/test/test_infra/test_data/dart_tooling_api/mock_api.dart +++ b/packages/devtools_app/test/test_infra/test_data/dart_tooling_api/mock_api.dart @@ -220,6 +220,7 @@ class MockDartToolingApi extends DartToolingApiImpl { flutterMode: mode, flutterDeviceId: deviceId, debuggerType: 'Flutter', + projectRootPath: null, ), ); _sendDebugSessionsChanged();