Skip to content

Commit 6e3200e

Browse files
author
Anna Gringauze
authored
Implement lookupResolvedPackageUris and lookupPackageUris (#1458)
* Implement lookupResolvedPackageUris and lookupPackageUris - implement the new API from vm service 7.4.0 - add tests - does not suport dart: scheme uris yet: #1457 Closes: #1446 * Mentiion new issue in TODO * Added examples of path conversion * fix comments * Support resolving SDK uris, add tests * Addressed CR comments * Build * Revert some merge breaks and formatting changes, address more CR comments * Revert accidental formatting changes, fix converting uri to file path on Windows
1 parent cdb7fb4 commit 6e3200e

10 files changed

+362
-115
lines changed

dwds/CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
## 11.5.2-dev
1+
## 12.0.0-dev
22

3+
- Implement `lookupResolvedPackageUris` and `lookupPackageUris` vm service API.
4+
- Update `vm_service` version to `^7.5.0`.
5+
- Make `ExpressionCompilerService` infer location of `libraries.json` from
6+
`sdkDir` parameter.
37
- Show an alert in the Dart Debug Extension for a multi-app scenario.
48

9+
**Breaking changes:**
10+
11+
- Add `sdkDir` argument to `Dwds.start` to help file resolution for sdk uris.
12+
513
## 11.5.1
614

715
- Update SDK contraint to `>=2.15.0 <3.0.0`.

dwds/lib/dwds.dart

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import 'src/readers/asset_reader.dart';
2424
import 'src/servers/devtools.dart';
2525
import 'src/servers/extension_backend.dart';
2626
import 'src/services/expression_compiler.dart';
27+
import 'src/utilities/dart_uri.dart';
2728

2829
export 'src/connections/app_connection.dart' show AppConnection;
2930
export 'src/connections/debug_connection.dart' show DebugConnection;
@@ -111,6 +112,7 @@ class Dwds {
111112
bool spawnDds,
112113
bool enableDevtoolsLaunch,
113114
DevtoolsLauncher devtoolsLauncher,
115+
Uri sdkDir,
114116
}) async {
115117
hostname ??= 'localhost';
116118
enableDebugging ??= true;
@@ -122,6 +124,8 @@ class Dwds {
122124
spawnDds ??= true;
123125
globalLoadStrategy = loadStrategy;
124126

127+
await DartUri.initialize(sdkDir: sdkDir);
128+
125129
DevTools devTools;
126130
Future<String> extensionUri;
127131
ExtensionBackend extensionBackend;

dwds/lib/src/debugging/inspector.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ class AppInspector extends Domain {
8787
Future<void> _initialize() async {
8888
var libraries = await libraryHelper.libraryRefs;
8989
isolate.rootLib = await libraryHelper.rootLib;
90-
9190
isolate.libraries.addAll(libraries);
92-
await DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri));
9391

9492
var scripts = await scriptRefs;
93+
94+
await DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri));
9595
await DartUri.recordAbsoluteUris(scripts.map((script) => script.uri));
9696

9797
isolate.extensionRPCs.addAll(await _getExtensionRpcs());

dwds/lib/src/services/chrome_proxy_service.dart

+13-13
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,19 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
655655
return (await _debugger).pause();
656656
}
657657

658+
@override
659+
Future<UriList> lookupResolvedPackageUris(
660+
String isolateId, List<String> uris) async {
661+
await isInitialized;
662+
return UriList(uris: uris.map(DartUri.toResolvedUri).toList());
663+
}
664+
665+
@override
666+
Future<UriList> lookupPackageUris(String isolateId, List<String> uris) async {
667+
await isInitialized;
668+
return UriList(uris: uris.map(DartUri.toPackageUri).toList());
669+
}
670+
658671
@override
659672
Future<Success> registerService(String service, String alias) async {
660673
return _rpcNotSupportedFuture('registerService');
@@ -1037,19 +1050,6 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
10371050
String isolateId, String breakpointId, bool enable) =>
10381051
throw UnimplementedError();
10391052

1040-
@override
1041-
Future<UriList> lookupPackageUris(String isolateId, List<String> uris) {
1042-
// TODO(https://github.com/dart-lang/webdev/issues/1446): implement.
1043-
throw UnimplementedError();
1044-
}
1045-
1046-
@override
1047-
Future<UriList> lookupResolvedPackageUris(
1048-
String isolateId, List<String> uris) {
1049-
// TODO(https://github.com/dart-lang/webdev/issues/1446): implement.
1050-
throw UnimplementedError();
1051-
}
1052-
10531053
/// Prevent DWDS from blocking Dart SDK rolls if changes in package:vm_service
10541054
/// are unimplemented in DWDS.
10551055
@override

dwds/lib/src/services/expression_compiler_service.dart

+11-17
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,8 @@ class _Compiler {
235235
/// Uses [_address] and [_port] to communicate and [_assetHandler] to
236236
/// redirect asset requests to the asset server.
237237
///
238-
/// [_sdkRoot] is the path to the directory containing the sdk summary files,
239-
/// [_workerPath] is the path to the DDC worker snapshot,
240-
/// [_librariesPath] is the path to libraries definitions file
241-
/// libraries.json.
238+
/// [_sdkDir] is the path to the SDK installation directory.
239+
/// [_workerPath] is the path to the DDC worker snapshot.
242240
///
243241
/// Users need to stop the service by calling [stop].
244242
class ExpressionCompilerService implements ExpressionCompiler {
@@ -248,15 +246,13 @@ class ExpressionCompilerService implements ExpressionCompiler {
248246
final Handler _assetHandler;
249247
final bool _verbose;
250248

251-
final String _sdkRoot;
252-
final String _librariesPath;
249+
final String _sdkDir;
253250
final String _workerPath;
254251

255252
ExpressionCompilerService(
256253
this._address, this._port, this._assetHandler, this._verbose,
257-
{String sdkRoot, String librariesPath, String workerPath})
258-
: _sdkRoot = sdkRoot,
259-
_librariesPath = librariesPath,
254+
{String sdkDir, String workerPath})
255+
: _sdkDir = sdkDir,
260256
_workerPath = workerPath;
261257

262258
@override
@@ -277,16 +273,14 @@ class ExpressionCompilerService implements ExpressionCompiler {
277273
if (_compiler.isCompleted) return;
278274
soundNullSafety ??= false;
279275

280-
final executable = Platform.resolvedExecutable;
281-
final binDir = p.dirname(executable);
282-
final sdkDir = p.dirname(binDir);
276+
final binDir = p.dirname(Platform.resolvedExecutable);
277+
var sdkDir = _sdkDir ?? p.dirname(binDir);
283278

284-
var sdkRoot = _sdkRoot ?? p.join(sdkDir, 'lib', '_internal');
279+
var sdkSummaryRoot = p.join(sdkDir, 'lib', '_internal');
285280
var sdkSummaryPath = soundNullSafety
286-
? p.join(sdkRoot, 'ddc_outline_sound.dill')
287-
: p.join(sdkRoot, 'ddc_sdk.dill');
288-
var librariesPath =
289-
_librariesPath ?? p.join(sdkDir, 'lib', 'libraries.json');
281+
? p.join(sdkSummaryRoot, 'ddc_outline_sound.dill')
282+
: p.join(sdkSummaryRoot, 'ddc_sdk.dill');
283+
var librariesPath = p.join(sdkDir, 'lib', 'libraries.json');
290284
var workerPath =
291285
_workerPath ?? p.join(binDir, 'snapshots', 'dartdevc.dart.snapshot');
292286

0 commit comments

Comments
 (0)