Skip to content

Commit 881a4f8

Browse files
author
Anna Gringauze
authored
Fix breakpoints not hitting after changing a base in index.html. (#1556)
* Add screen field to DebuggerReady event * Fix breakpoints not hitting after changing a base in index.html * Updated changelog * Updated changelog. * Fix failing tests * Try fix breakpoint setting problem for org-dartlang uris * Fix finding dart location for js, remove adding root to absolute paths * Removed printing and locaton fixes, updted version * Address CR comments
1 parent 8c814f9 commit 881a4f8

File tree

11 files changed

+64
-118
lines changed

11 files changed

+64
-118
lines changed

dwds/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 13.1.1-dev
1+
## 14.0.0-dev
22
- Add column information to breakpoints to allow precise breakpoint placement.
33
- Split SDK validation methods to allow validation of separate components.
44
- Remove dependency on `package:_fe_analyzer_shared`.
@@ -8,6 +8,10 @@
88
used.
99
- Fix crash when using flutter tools with web server device.
1010
- Remove clearing all scripts on page load for extension debugger.
11+
- Fix breakpoints not hitting after changing a base in index.html.
12+
13+
**Breaking changes:**
14+
- Add `basePath` parameter to `FrontendServerRequireStrategy`.
1115

1216
## 13.1.0
1317
- Update _fe_analyzer_shared to version ^38.0.0.

dwds/lib/src/injected/client.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/lib/src/loaders/frontend_server_require.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ class FrontendServerRequireStrategyProvider {
1414
final ReloadConfiguration _configuration;
1515
final AssetReader _assetReader;
1616
final Future<Map<String, String>> Function() _digestsProvider;
17+
final String _basePath;
1718

1819
RequireStrategy _requireStrategy;
1920

20-
FrontendServerRequireStrategyProvider(
21-
this._configuration, this._assetReader, this._digestsProvider);
21+
FrontendServerRequireStrategyProvider(this._configuration, this._assetReader,
22+
this._digestsProvider, String basePath)
23+
: _basePath = basePathForServerUri(basePath);
2224

2325
RequireStrategy get strategy => _requireStrategy ??= RequireStrategy(
2426
_configuration,
@@ -32,28 +34,35 @@ class FrontendServerRequireStrategyProvider {
3234
_assetReader,
3335
);
3436

37+
String _removeBasePath(String path) =>
38+
path.startsWith(_basePath) ? path.substring(_basePath.length) : null;
39+
40+
String _addBasePath(String serverPath) => p.join(_basePath, serverPath);
41+
3542
Future<Map<String, String>> _moduleProvider(
3643
MetadataProvider metadataProvider) async =>
3744
(await metadataProvider.moduleToModulePath).map((key, value) =>
3845
MapEntry(key, relativizePath(removeJsExtension(value))));
3946

4047
Future<String> _moduleForServerPath(
41-
MetadataProvider metadataProvider, String serverPath) async =>
42-
(await metadataProvider.modulePathToModule)[serverPath];
48+
MetadataProvider metadataProvider, String serverPath) async {
49+
var modulePathToModule = await metadataProvider.modulePathToModule;
50+
return modulePathToModule[_removeBasePath(serverPath)];
51+
}
4352

4453
Future<String> _serverPathForModule(
4554
MetadataProvider metadataProvider, String module) async =>
46-
(await metadataProvider.moduleToModulePath)[module] ?? '';
55+
_addBasePath((await metadataProvider.moduleToModulePath)[module] ?? '');
4756

4857
Future<String> _sourceMapPathForModule(
4958
MetadataProvider metadataProvider, String module) async {
5059
var path = (await metadataProvider.moduleToSourceMap)[module] ?? '';
51-
return relativizePath(path);
60+
return _addBasePath(relativizePath(path));
5261
}
5362

5463
String _serverPathForAppUri(String appUri) {
5564
if (appUri.startsWith('org-dartlang-app:')) {
56-
return Uri.parse(appUri).path.substring(1);
65+
return _addBasePath(Uri.parse(appUri).path.substring(1));
5766
}
5867
return null;
5968
}

dwds/lib/src/loaders/require.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ import 'package:shelf/shelf.dart';
1111

1212
import '../../dwds.dart';
1313

14+
/// Find the path we are serving from the url.
15+
///
16+
/// Example:
17+
/// https://localhost/base/index.html => /base
18+
/// https://localhost/base => /base
19+
String basePathForServerUri(String url) {
20+
if (url == null) return null;
21+
var uri = Uri.parse(url);
22+
var base = uri.path.endsWith('.html') ? p.dirname(uri.path) : uri.path;
23+
if (base.isNotEmpty) {
24+
base = base.startsWith('/') ? base : '/$base';
25+
}
26+
return base;
27+
}
28+
1429
String relativizePath(String path) =>
1530
path.startsWith('/') ? path.substring(1) : path;
1631

dwds/lib/src/services/expression_evaluator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ class ExpressionEvaluator {
179179
'Cannot find Dart location for JS location: '
180180
'url: $url, '
181181
'function: $functionName, '
182-
'line: $jsLine');
182+
'line: $jsLine, '
183+
'column: $jsColumn');
183184
}
184185

185186
var dartLocation = locationMap.dartLocation;

dwds/lib/src/utilities/dart_uri.dart

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:logging/logging.dart';
88
import 'package:package_config/package_config.dart';
99
import 'package:path/path.dart' as p;
1010

11+
import '../loaders/require.dart';
1112
import '../loaders/strategy.dart';
1213
import 'sdk_configuration.dart';
1314

@@ -36,38 +37,48 @@ class DartUri {
3637
/// JS script. The dirname of that path should give us the missing prefix.
3738
factory DartUri(String uri, [String serverUri]) {
3839
var serverPath = globalLoadStrategy.serverPathForAppUri(uri);
39-
if (serverPath != null) return DartUri._(serverPath);
40+
if (serverPath != null) {
41+
return DartUri._(serverPath);
42+
}
4043
// TODO(annagrin): Support creating DartUris from `dart:` uris.
4144
// Issue: https://github.com/dart-lang/webdev/issues/1584
4245
if (uri.startsWith('package:')) {
4346
return DartUri._fromPackageUri(uri, serverUri: serverUri);
4447
}
45-
if (uri.startsWith('file:')) return DartUri._fromFileUri(uri);
48+
if (uri.startsWith('file:')) {
49+
return DartUri._fromFileUri(uri, serverUri: serverUri);
50+
}
4651
if (uri.startsWith('/packages/')) {
4752
return DartUri._fromRelativePath(uri, serverUri: serverUri);
4853
}
49-
if (uri.startsWith('/')) return DartUri._fromRelativePath(uri);
54+
if (uri.startsWith('/')) {
55+
return DartUri._fromRelativePath(uri);
56+
}
5057
if (uri.startsWith('http:') || uri.startsWith('https:')) {
5158
return DartUri(Uri.parse(uri).path);
5259
}
5360

5461
throw FormatException('Unsupported URI form', uri);
5562
}
5663

64+
@override
65+
String toString() => 'DartUri: $serverPath';
66+
5767
/// Construct from a package: URI
5868
factory DartUri._fromPackageUri(String uri, {String serverUri}) {
69+
var basePath = basePathForServerUri(serverUri);
5970
var packagePath = 'packages/${uri.substring("package:".length)}';
6071
if (serverUri != null) {
61-
return DartUri._fromRelativePath(
62-
p.url.join(_dirForServerUri(serverUri), packagePath));
72+
var relativePath = p.url.join(basePath, packagePath);
73+
return DartUri._fromRelativePath(relativePath);
6374
}
6475
return DartUri._(packagePath);
6576
}
6677

6778
/// Construct from a file: URI
68-
factory DartUri._fromFileUri(String uri) {
79+
factory DartUri._fromFileUri(String uri, {String serverUri}) {
6980
var libraryName = _resolvedUriToUri[uri];
70-
if (libraryName != null) return DartUri(libraryName);
81+
if (libraryName != null) return DartUri(libraryName, serverUri);
7182
// This is not one of our recorded libraries.
7283
throw ArgumentError.value(uri, 'uri', 'Unknown library');
7384
}
@@ -78,8 +89,8 @@ class DartUri {
7889
uri = uri[0] == '/' ? uri.substring(1) : uri;
7990

8091
if (serverUri != null) {
81-
return DartUri._fromRelativePath(
82-
p.url.join(_dirForServerUri(serverUri), uri));
92+
var basePath = basePathForServerUri(serverUri);
93+
return DartUri._fromRelativePath(p.url.join(basePath, uri));
8394
}
8495
return DartUri._(uri);
8596
}
@@ -179,9 +190,6 @@ class DartUri {
179190
}
180191
}
181192

182-
/// Returns the dirname for the server URI.
183-
static String _dirForServerUri(String uri) => p.dirname(Uri.parse(uri).path);
184-
185193
/// Load the .dart_tool/package_config.json file associated with the running
186194
/// application so we can resolve file URLs into package: URLs appropriately.
187195
static Future<void> _loadPackageConfig(Uri uri) async {

dwds/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dwds
22
# Every time this changes you need to run `dart run build_runner build`.
3-
version: 13.1.1-dev
3+
version: 14.0.0-dev
44
description: >-
55
A service that proxies between the Chrome debug protocol and the Dart VM
66
service protocol.

dwds/test/build_daemon_nested_directory_breakpoint_test.dart

Lines changed: 0 additions & 92 deletions
This file was deleted.

dwds/test/dart_uri_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void main() {
3535
test('parses package : paths with root', () {
3636
var uri = DartUri(
3737
'package:path/path.dart', 'http://localhost:8080/foo/bar/blah');
38-
expect(uri.serverPath, 'foo/bar/packages/path/path.dart');
38+
expect(uri.serverPath, 'foo/bar/blah/packages/path/path.dart');
3939
});
4040

4141
test('parses org-dartlang-app paths', () {

0 commit comments

Comments
 (0)