Skip to content

Commit 63c67a6

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Ignore zero length regions in the preview tool
The zero length regions are being produced when server indicates that navigation ought to target an unnamed constructor, a closure, a library, or any other unnamed element. This might be a bug in server's navigation support, but I don't want to have to fix that before the preview tool can be used in a UX study. Change-Id: I35c9978d38937006ee00d76516f3ee607fca6850 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124860 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
1 parent 5cce1e4 commit 63c67a6

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

pkg/analysis_server/lib/src/edit/nnbd_migration/instrumentation_renderer.dart

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,37 +265,45 @@ class InstrumentationRenderer {
265265
// Compute insertions for navigation targets.
266266
//
267267
for (NavigationTarget region in unitInfo.targets) {
268-
int openOffset = mapper.map(region.offset);
269-
String openInsertion = openInsertions[openOffset] ?? '';
270-
openInsertion = '<a id="o${region.offset}">$openInsertion';
271-
openInsertions[openOffset] = openInsertion;
272-
273-
int closeOffset = openOffset + region.length;
274-
String closeInsertion = closeInsertions[closeOffset] ?? '';
275-
closeInsertion = '$closeInsertion</a>';
276-
closeInsertions[closeOffset] = closeInsertion;
277-
}
278-
//
279-
// Compute insertions for navigation sources, but skip the sources that
280-
// point at themselves.
281-
//
282-
for (NavigationSource region in unitInfo.sources ?? <NavigationSource>[]) {
283-
int openOffset = mapper.map(region.offset);
284-
NavigationTarget target = region.target;
285-
if (target.filePath != unitInfo.path || region.offset != target.offset) {
268+
int regionLength = region.length;
269+
if (regionLength > 0) {
270+
int openOffset = mapper.map(region.offset);
286271
String openInsertion = openInsertions[openOffset] ?? '';
287-
String htmlPath = pathContext.relative(pathMapper.map(target.filePath),
288-
from: unitDir);
289-
openInsertion = '<a href="$htmlPath#o${target.offset}">$openInsertion';
272+
openInsertion = '<a id="o${region.offset}">$openInsertion';
290273
openInsertions[openOffset] = openInsertion;
291274

292-
int closeOffset = openOffset + region.length;
275+
int closeOffset = openOffset + regionLength;
293276
String closeInsertion = closeInsertions[closeOffset] ?? '';
294277
closeInsertion = '$closeInsertion</a>';
295278
closeInsertions[closeOffset] = closeInsertion;
296279
}
297280
}
298281
//
282+
// Compute insertions for navigation sources, but skip the sources that
283+
// point at themselves.
284+
//
285+
for (NavigationSource region in unitInfo.sources ?? <NavigationSource>[]) {
286+
int regionLength = region.length;
287+
if (regionLength > 0) {
288+
int openOffset = mapper.map(region.offset);
289+
NavigationTarget target = region.target;
290+
if (target.filePath != unitInfo.path ||
291+
region.offset != target.offset) {
292+
String openInsertion = openInsertions[openOffset] ?? '';
293+
String htmlPath = pathContext
294+
.relative(pathMapper.map(target.filePath), from: unitDir);
295+
openInsertion =
296+
'<a href="$htmlPath#o${target.offset}">$openInsertion';
297+
openInsertions[openOffset] = openInsertion;
298+
299+
int closeOffset = openOffset + regionLength;
300+
String closeInsertion = closeInsertions[closeOffset] ?? '';
301+
closeInsertion = '$closeInsertion</a>';
302+
closeInsertions[closeOffset] = closeInsertion;
303+
}
304+
}
305+
}
306+
//
299307
// Apply the insertions that have been computed.
300308
//
301309
List<int> offsets = []

0 commit comments

Comments
 (0)