Skip to content

Commit 92e1583

Browse files
committed
Fix tests, implement getExtensionRpcs for WebSocketAppInspector
1 parent 4085b15 commit 92e1583

File tree

6 files changed

+64
-69
lines changed

6 files changed

+64
-69
lines changed

dwds/lib/src/debugging/chrome_inspector.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import 'package:dwds/src/utilities/objects.dart';
2424
import 'package:dwds/src/utilities/server.dart';
2525
import 'package:dwds/src/utilities/shared.dart';
2626
import 'package:logging/logging.dart';
27+
import 'package:meta/meta.dart';
2728
import 'package:vm_service/vm_service.dart';
2829
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
2930

@@ -38,7 +39,10 @@ class ChromeAppInspector extends AppInspector {
3839
final RemoteDebugger remoteDebugger;
3940
final ExecutionContext _executionContext;
4041

41-
late ChromeLibraryHelper _libraryHelper;
42+
@override
43+
@protected
44+
late final libraryHelper = ChromeLibraryHelper(this);
45+
4246
late ChromeAppClassHelper _classHelper;
4347
late ChromeAppInstanceHelper _instanceHelper;
4448

@@ -51,15 +55,10 @@ class ChromeAppInspector extends AppInspector {
5155
/// Regex used to extract the message from an exception description.
5256
static final exceptionMessageRegex = RegExp(r'^.*$', multiLine: true);
5357

54-
/// Flutter widget inspector library.
55-
@override
56-
Future<LibraryRef?> get flutterWidgetInspectorLibrary => _libraryHelper
57-
.libraryRefFor('package:flutter/src/widgets/widget_inspector.dart');
58-
5958
/// Regex used to extract a stack trace line from the exception description.
6059
static final stackTraceLineRegex = RegExp(r'^\s*at\s.*$', multiLine: true);
6160

62-
ChromeAppInspector(
61+
ChromeAppInspector._(
6362
super.appConnection,
6463
super.isolate,
6564
this.remoteDebugger,
@@ -119,7 +118,7 @@ class ChromeAppInspector extends AppInspector {
119118
isSystemIsolate: false,
120119
isolateFlags: [],
121120
)..extensionRPCs = [];
122-
final inspector = ChromeAppInspector(
121+
final inspector = ChromeAppInspector._(
123122
appConnection,
124123
isolate,
125124
remoteDebugger,
@@ -343,7 +342,7 @@ class ChromeAppInspector extends AppInspector {
343342
Future<Library?> getLibrary(String objectId) async {
344343
final libraryRef = await libraryRefFor(objectId);
345344
if (libraryRef == null) return null;
346-
return _libraryHelper.libraryFor(libraryRef);
345+
return libraryHelper.libraryFor(libraryRef);
347346
}
348347

349348
Future<Obj> getObject(String objectId, {int? offset, int? count}) async {
@@ -437,11 +436,6 @@ class ChromeAppInspector extends AppInspector {
437436
Future<SourceReport> getSourceReport(
438437
List<String> reports, {
439438
String? scriptId,
440-
int? tokenPos,
441-
int? endTokenPos,
442-
bool? forceCompile,
443-
bool? reportLines,
444-
List<String>? libraryFilters,
445439
}) {
446440
if (reports.contains(SourceReportKind.kCoverage)) {
447441
throwInvalidParam(

dwds/lib/src/debugging/inspector.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ abstract class AppInspector {
4949

5050
final AppConnection appConnection;
5151

52-
late LibraryHelper _libraryHelper;
52+
@protected
53+
LibraryHelper get libraryHelper;
5354

5455
/// The root URI from which the application is served.
5556
final String root;
@@ -61,7 +62,7 @@ abstract class AppInspector {
6162
static final exceptionMessageRegex = RegExp(r'^.*$', multiLine: true);
6263

6364
/// Flutter widget inspector library.
64-
Future<LibraryRef?> get flutterWidgetInspectorLibrary => _libraryHelper
65+
Future<LibraryRef?> get flutterWidgetInspectorLibrary => libraryHelper
6566
.libraryRefFor('package:flutter/src/widgets/widget_inspector.dart');
6667

6768
/// Regex used to extract a stack trace line from the exception description.
@@ -73,23 +74,22 @@ abstract class AppInspector {
7374
/// Reset all caches and recompute any mappings.
7475
///
7576
/// Should be called across hot reloads with a valid [ModifiedModuleReport].
77+
@protected
7678
@mustCallSuper
7779
Future<void> initialize({ModifiedModuleReport? modifiedModuleReport}) async {
7880
_scriptCacheMemoizer = AsyncMemoizer<List<ScriptRef>>();
7981

80-
if (modifiedModuleReport != null) {
81-
// Invalidate `_libraryHelper` as we use it populate any script caches.
82-
_libraryHelper.initialize(modifiedModuleReport: modifiedModuleReport);
83-
} else {
84-
_libraryHelper = LibraryHelper(this)..initialize();
82+
// Invalidate `_libraryHelper` as we use it populate any script caches.
83+
libraryHelper.initialize(modifiedModuleReport: modifiedModuleReport);
84+
if (modifiedModuleReport == null) {
8585
_scriptRefsById.clear();
8686
_serverPathToScriptRef.clear();
8787
_scriptIdToLibraryId.clear();
8888
_libraryIdToScriptRefs.clear();
8989
}
9090

91-
final libraries = await _libraryHelper.libraryRefs;
92-
isolate.rootLib = await _libraryHelper.rootLib;
91+
final libraries = await libraryHelper.libraryRefs;
92+
isolate.rootLib = await libraryHelper.rootLib;
9393
isolate.libraries?.clear();
9494
isolate.libraries?.addAll(libraries);
9595

@@ -111,7 +111,7 @@ abstract class AppInspector {
111111
);
112112

113113
Future<LibraryRef?> libraryRefFor(String objectId) =>
114-
_libraryHelper.libraryRefFor(objectId);
114+
libraryHelper.libraryRefFor(objectId);
115115

116116
/// Returns the [ScriptRef] for the provided Dart server path [uri].
117117
Future<ScriptRef?> scriptRefFor(String uri) async {
@@ -152,7 +152,7 @@ abstract class AppInspector {
152152
// Invalidate any script caches that were computed for the now invalid
153153
// libraries. They will get repopulated below.
154154
for (final libraryUri in modifiedModuleReport.modifiedLibraries) {
155-
final libraryRef = await _libraryHelper.libraryRefFor(libraryUri);
155+
final libraryRef = await libraryHelper.libraryRefFor(libraryUri);
156156
final libraryId = libraryRef?.id;
157157
// If this was not a pre-existing library, nothing to invalidate.
158158
if (libraryId == null) continue;
@@ -185,7 +185,7 @@ abstract class AppInspector {
185185
ScriptRef(uri: uri, id: createId()),
186186
for (final part in parts ?? []) ScriptRef(uri: part, id: createId()),
187187
];
188-
final libraryRef = await _libraryHelper.libraryRefFor(uri);
188+
final libraryRef = await libraryHelper.libraryRefFor(uri);
189189
final libraryId = libraryRef?.id;
190190
if (libraryId != null) {
191191
final libraryIdToScriptRefs = _libraryIdToScriptRefs.putIfAbsent(

dwds/lib/src/debugging/libraries.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:dwds/src/debugging/metadata/class.dart';
1010
import 'package:dwds/src/debugging/metadata/provider.dart';
1111
import 'package:dwds/src/services/chrome_debug_exception.dart';
1212
import 'package:logging/logging.dart';
13+
import 'package:meta/meta.dart';
1314
import 'package:vm_service/vm_service.dart';
1415
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
1516

@@ -33,6 +34,7 @@ class LibraryHelper<T extends AppInspector> {
3334
///
3435
/// If [modifiedModuleReport] is not null, invalidates only modified libraries
3536
/// from the cache and recomputes values for any eager caches.
37+
@mustCallSuper
3638
void initialize({ModifiedModuleReport? modifiedModuleReport}) {
3739
_rootLib = null;
3840
if (modifiedModuleReport != null) {

dwds/lib/src/debugging/web_socket_inspector.dart

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44

55
import 'package:dwds/src/connections/app_connection.dart';
66
import 'package:dwds/src/debugging/inspector.dart';
7+
import 'package:dwds/src/debugging/libraries.dart';
8+
import 'package:dwds/src/services/web_socket_proxy_service.dart';
9+
import 'package:meta/meta.dart';
710
import 'package:vm_service/vm_service.dart';
811

912
/// Provides information about the currently loaded program.
1013
class WebSocketAppInspector extends AppInspector {
1114
/// Counter for generating unique isolate IDs across page refreshes
1215
static int _globalIsolateIdCounter = 0;
1316

14-
WebSocketAppInspector(super.appConnection, super.isolate, super.root);
17+
WebSocketAppInspector._(
18+
super.appConnection,
19+
super.isolate,
20+
super.root,
21+
this._service,
22+
);
1523

1624
static Future<WebSocketAppInspector> create(
25+
WebSocketProxyService service,
1726
AppConnection appConnection,
1827
String root,
1928
) async {
@@ -27,31 +36,43 @@ class WebSocketAppInspector extends AppInspector {
2736
startTime: time,
2837
runnable: true,
2938
pauseOnExit: false,
30-
pauseEvent: Event(
31-
kind: EventKind.kPauseStart,
32-
timestamp: time,
33-
isolate: IsolateRef(
34-
id: id,
35-
name: name,
36-
number: id,
37-
isSystemIsolate: false,
38-
),
39-
),
4039
livePorts: 0,
4140
libraries: [],
4241
breakpoints: [],
4342
isSystemIsolate: false,
4443
isolateFlags: [],
45-
)..extensionRPCs = [];
46-
final inspector = WebSocketAppInspector(appConnection, isolate, root);
44+
);
45+
final inspector = WebSocketAppInspector._(
46+
appConnection,
47+
isolate,
48+
root,
49+
service,
50+
);
4751

4852
await inspector.initialize();
4953
return inspector;
5054
}
5155

5256
@override
53-
Future<Set<String>> getExtensionRpcs() {
54-
// TODO: implement getExtensionRpcs
55-
throw UnimplementedError();
57+
@protected
58+
late final libraryHelper = LibraryHelper(this);
59+
60+
final WebSocketProxyService _service;
61+
62+
/// Invokes the `getExtensionRpcs` service extension, which returns the list
63+
/// of registered extensions.
64+
///
65+
/// Combines this with the RPCs registered in the [isolate]. Use this over
66+
/// [Isolate.extensionRPCs] as this computes a live set.
67+
///
68+
/// Updates [Isolate.extensionRPCs] to this set.
69+
@override
70+
Future<Set<String>> getExtensionRpcs() async {
71+
final response = await _service.callServiceExtension('getExtensionRpcs');
72+
final extensionRpcs = (response.json!['rpcs'] as List)
73+
.cast<String>()
74+
.toSet();
75+
isolate.extensionRPCs = List.of(extensionRpcs);
76+
return extensionRpcs;
5677
}
5778
}

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -855,50 +855,28 @@ class ChromeProxyService extends ProxyService<ChromeAppInspector> {
855855
String isolateId,
856856
List<String> reports, {
857857
String? scriptId,
858+
// Note: Ignore the following optional parameters. They are here to match
859+
// the VM service interface.
858860
int? tokenPos,
859861
int? endTokenPos,
860862
bool? forceCompile,
861863
bool? reportLines,
862864
List<String>? libraryFilters,
863-
// Note: Ignore the optional librariesAlreadyCompiled parameter. It is here
864-
// to match the VM service interface.
865865
List<String>? librariesAlreadyCompiled,
866866
}) => wrapInErrorHandlerAsync(
867867
'getSourceReport',
868-
() => _getSourceReport(
869-
isolateId,
870-
reports,
871-
scriptId: scriptId,
872-
tokenPos: tokenPos,
873-
endTokenPos: endTokenPos,
874-
forceCompile: forceCompile,
875-
reportLines: reportLines,
876-
libraryFilters: libraryFilters,
877-
),
868+
() => _getSourceReport(isolateId, reports, scriptId: scriptId),
878869
);
879870

880871
Future<SourceReport> _getSourceReport(
881872
String isolateId,
882873
List<String> reports, {
883874
String? scriptId,
884-
int? tokenPos,
885-
int? endTokenPos,
886-
bool? forceCompile,
887-
bool? reportLines,
888-
List<String>? libraryFilters,
889875
}) {
890876
return captureElapsedTime(() async {
891877
await isInitialized;
892878
_checkIsolate('getSourceReport', isolateId);
893-
return await inspector.getSourceReport(
894-
reports,
895-
scriptId: scriptId,
896-
tokenPos: tokenPos,
897-
endTokenPos: endTokenPos,
898-
forceCompile: forceCompile,
899-
reportLines: reportLines,
900-
libraryFilters: libraryFilters,
901-
);
879+
return await inspector.getSourceReport(reports, scriptId: scriptId);
902880
}, (result) => DwdsEvent.getSourceReport());
903881
}
904882

dwds/lib/src/services/web_socket_proxy_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class WebSocketProxyService extends ProxyService<WebSocketAppInspector> {
201201
return;
202202
}
203203

204-
inspector = await WebSocketAppInspector.create(appConnection, root);
204+
inspector = await WebSocketAppInspector.create(this, appConnection, root);
205205

206206
final isolateRef = inspector.isolateRef;
207207
vm.isolates?.add(isolateRef);

0 commit comments

Comments
 (0)