Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can add breakpoints to a project using macros #2403

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 47 additions & 21 deletions dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,17 @@ class Locations {
// Create TokenPos for each entry in the source map.
for (var lineEntry in mapping.lines) {
for (var entry in lineEntry.entries) {
final index = entry.sourceUrlId;
if (index == null) continue;
// Source map URLS are relative to the script. They may have platform separators
// or they may use URL semantics. To be sure, we split and re-join them.
// This works on Windows because path treats both / and \ as separators.
// It will fail if the path has both separators in it.
final relativeSegments = p.split(mapping.urls[index]);
final path = p.url.normalize(
p.url.joinAll([scriptLocation, ...relativeSegments]),
);

final dartUri = DartUri(path, _root);

result.add(
Location.from(
modulePath,
lineEntry,
entry,
dartUri,
runtimeScriptId,
),
final location = _locationForSourceMapEntry(
lineEntry: lineEntry,
entry: entry,
modulePath: modulePath,
runtimeScriptId: runtimeScriptId,
sourceUrls: mapping.urls,
scriptLocation: scriptLocation,
);
if (location != null) {
result.add(location);
}
}
}
}
Expand All @@ -379,4 +368,41 @@ class Locations {
return _moduleToLocations[module] = result;
});
}

/// Creates a TokenPos [Location] for an entry in the source map.
Location? _locationForSourceMapEntry({
required TargetLineEntry lineEntry,
required TargetEntry entry,
required String modulePath,
required String? runtimeScriptId,
required List<String> sourceUrls,
required String scriptLocation,
}) {
final index = entry.sourceUrlId;
if (index == null) return null;
// Source map URLS are relative to the script. They may have platform separators
// or they may use URL semantics. To be sure, we split and re-join them.
// This works on Windows because path treats both / and \ as separators.
// It will fail if the path has both separators in it.
final relativeSegments = p.split(sourceUrls[index]);
final path = p.url.normalize(
p.url.joinAll([scriptLocation, ...relativeSegments]),
);

try {
final dartUri = DartUri(path, _root);
return Location.from(
modulePath,
lineEntry,
entry,
dartUri,
runtimeScriptId,
);
} catch (error) {
// DartUri throws if the path format is unrecognized. Log any errors and
// return null in that case.
_logger.warning('Error adding location for $path: $error');
return null;
}
}
}
Loading