Skip to content

Commit

Permalink
Accept project root paths in debug sessions for sidebar (flutter#6715)
Browse files Browse the repository at this point in the history
See flutter#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.
  • Loading branch information
DanTup authored Nov 14, 2023
1 parent 27e55f7 commit 3fb237d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class VsCodeDebugSessionImpl implements VsCodeDebugSession {
required this.flutterMode,
required this.flutterDeviceId,
required this.debuggerType,
required this.projectRootPath,
});

VsCodeDebugSessionImpl.fromJson(Map<String, Object?> json)
Expand All @@ -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
Expand All @@ -200,13 +203,17 @@ class VsCodeDebugSessionImpl implements VsCodeDebugSession {
@override
final String? debuggerType;

@override
final String? projectRootPath;

Map<String, Object?> toJson() => {
VsCodeDebugSession.jsonIdField: id,
VsCodeDebugSession.jsonNameField: name,
VsCodeDebugSession.jsonVmServiceUriField: vmServiceUri,
VsCodeDebugSession.jsonFlutterModeField: flutterMode,
VsCodeDebugSession.jsonFlutterDeviceIdField: flutterDeviceId,
VsCodeDebugSession.jsonDebuggerTypeField: debuggerType,
VsCodeDebugSession.jsonProjectRootPathField: projectRootPath,
};
}

Expand Down
11 changes: 11 additions & 0 deletions packages/devtools_app/lib/src/standalone_ui/api/vs_code_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class MockDartToolingApi extends DartToolingApiImpl {
flutterMode: mode,
flutterDeviceId: deviceId,
debuggerType: 'Flutter',
projectRootPath: null,
),
);
_sendDebugSessionsChanged();
Expand Down

0 comments on commit 3fb237d

Please sign in to comment.