@@ -208,6 +208,9 @@ class InstrumentationRenderer {
208208 /// Creates an output object for the given library info.
209209 InstrumentationRenderer (this .unitInfo, this .migrationInfo, this .pathMapper);
210210
211+ /// Return the path context used to manipulate paths.
212+ path.Context get pathContext => migrationInfo.pathContext;
213+
211214 /// Builds an HTML view of the instrumentation information in [unitInfo] .
212215 String render () {
213216 // TODO(brianwilkerson) Restore syntactic highlighting.
@@ -228,6 +231,7 @@ class InstrumentationRenderer {
228231
229232 /// Return the content of the file with navigation links and anchors added.
230233 String _computeNavigationContent (UnitInfo unitInfo) {
234+ String unitDir = _directoryContaining (unitInfo);
231235 String content = unitInfo.content;
232236 OffsetMapper mapper = unitInfo.offsetMapper;
233237 Map <int , String > openInsertions = {};
@@ -255,7 +259,8 @@ class InstrumentationRenderer {
255259 NavigationTarget target = region.target;
256260 if (target.filePath != unitInfo.path || region.offset != target.offset) {
257261 String openInsertion = openInsertions[openOffset] ?? '' ;
258- String htmlPath = pathMapper.map (target.filePath);
262+ String htmlPath = pathContext.relative (pathMapper.map (target.filePath),
263+ from: unitDir);
259264 openInsertion = '<a href="$htmlPath #o${target .offset }">$openInsertion ' ;
260265 openInsertions[openOffset] = openInsertion;
261266
@@ -295,6 +300,7 @@ class InstrumentationRenderer {
295300 /// * 'explanation': The Mustache context for the tooltip explaining why the
296301 /// content in this region was modified.
297302 List <Map > _computeRegions (UnitInfo unitInfo) {
303+ String unitDir = _directoryContaining (unitInfo);
298304 String content = unitInfo.content;
299305 List <Map > regions = [];
300306 int previousOffset = 0 ;
@@ -313,7 +319,7 @@ class InstrumentationRenderer {
313319 for (var detail in region.details) {
314320 details.add ({
315321 'description' : detail.description,
316- 'target' : _uriForTarget (detail.target),
322+ 'target' : _uriForTarget (detail.target, unitDir ),
317323 'isLink' : detail.target != null ,
318324 });
319325 }
@@ -334,17 +340,21 @@ class InstrumentationRenderer {
334340 return regions;
335341 }
336342
343+ /// Return the path to the directory containing the output generated from the
344+ /// [unitInfo] .
345+ String _directoryContaining (UnitInfo unitInfo) {
346+ return pathContext.dirname (pathMapper.map (unitInfo.path));
347+ }
348+
337349 /// Return the URL that will navigate to the given [target] .
338- String _uriForTarget (NavigationTarget target) {
350+ String _uriForTarget (NavigationTarget target, String unitDir ) {
339351 if (target == null ) {
340352 // TODO(brianwilkerson) This is temporary support until we can get targets
341353 // for all nodes.
342354 return '' ;
343355 }
344- path.Context pathContext = migrationInfo.pathContext;
345- String targetPath = pathContext.setExtension (target.filePath, '.html' );
346- String sourceDir = pathContext.dirname (unitInfo.path);
347- String relativePath = pathContext.relative (targetPath, from: sourceDir);
356+ String relativePath =
357+ pathContext.relative (pathMapper.map (target.filePath), from: unitDir);
348358 return '$relativePath #o${target .offset .toString ()}' ;
349359 }
350360}
0 commit comments