Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: tests/compiler/dart2js/sourcemaps/sourcemap_html_helper.dart

Issue 2788373002: Add Source.getTextLine and use it to display source snippets in error messages. (Closed)
Patch Set: dartfmt Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Helper for creating HTML visualization of the source map information 5 /// Helper for creating HTML visualization of the source map information
6 /// generated by a [SourceMapProcessor]. 6 /// generated by a [SourceMapProcessor].
7 7
8 library sourcemap.html.helper; 8 library sourcemap.html.helper;
9 9
10 import 'dart:convert'; 10 import 'dart:convert';
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 dartCodeBuffer.write('<h4>${uri.pathSegments.last}, ' 508 dartCodeBuffer.write('<h4>${uri.pathSegments.last}, '
509 '${firstLineIndex - windowSize + 1}-' 509 '${firstLineIndex - windowSize + 1}-'
510 '${lastLineIndex + windowSize + 1}' 510 '${lastLineIndex + windowSize + 1}'
511 '</h4>\n'); 511 '</h4>\n');
512 dartCodeBuffer.write('<pre>\n'); 512 dartCodeBuffer.write('<pre>\n');
513 for (int line = firstLineIndex - windowSize; 513 for (int line = firstLineIndex - windowSize;
514 line < firstLineIndex; 514 line < firstLineIndex;
515 line++) { 515 line++) {
516 if (line >= 0) { 516 if (line >= 0) {
517 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth)); 517 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth));
518 dartCodeBuffer.write(sourceFile.getLineText(line)); 518 dartCodeBuffer.write(sourceFile.kernelSource.getTextLine(line + 1));
519 } 519 }
520 } 520 }
521 dartCodeBuffer.write(codeBuffer); 521 dartCodeBuffer.write(codeBuffer);
522 for (int line = lastLineIndex + 1; 522 for (int line = lastLineIndex + 1;
523 line <= lastLineIndex + windowSize; 523 line <= lastLineIndex + windowSize;
524 line++) { 524 line++) {
525 if (line < sourceFile.lines) { 525 if (line < sourceFile.lines) {
526 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth)); 526 dartCodeBuffer.write(lineNumber(line, width: lineNoWidth));
527 dartCodeBuffer.write(sourceFile.getLineText(line)); 527 dartCodeBuffer.write(sourceFile.kernelSource.getTextLine(line + 1));
528 } 528 }
529 } 529 }
530 dartCodeBuffer.write('</pre>\n'); 530 dartCodeBuffer.write('</pre>\n');
531 firstLineIndex = null; 531 firstLineIndex = null;
532 lastLineIndex = null; 532 lastLineIndex = null;
533 } 533 }
534 codeBuffer.clear(); 534 codeBuffer.clear();
535 } 535 }
536 536
537 lineIndices.forEach((int lineIndex) { 537 lineIndices.forEach((int lineIndex) {
538 List<SourceLocation> locations = uriMap[lineIndex]; 538 List<SourceLocation> locations = uriMap[lineIndex];
539 if (lastLineIndex != null && lastLineIndex + windowSize * 4 < lineIndex) { 539 if (lastLineIndex != null && lastLineIndex + windowSize * 4 < lineIndex) {
540 flush(); 540 flush();
541 } 541 }
542 if (firstLineIndex == null) { 542 if (firstLineIndex == null) {
543 firstLineIndex = lineIndex; 543 firstLineIndex = lineIndex;
544 } else { 544 } else {
545 for (int line = lastLineIndex + 1; line < lineIndex; line++) { 545 for (int line = lastLineIndex + 1; line < lineIndex; line++) {
546 codeBuffer.write(lineNumber(line, width: lineNoWidth)); 546 codeBuffer.write(lineNumber(line, width: lineNoWidth));
547 codeBuffer.write(sourceFile.getLineText(line)); 547 codeBuffer.write(sourceFile.kernelSource.getTextLine(line + 1));
548 } 548 }
549 } 549 }
550 String line = sourceFile.getLineText(lineIndex); 550 String line = sourceFile.kernelSource.getTextLine(lineIndex + 1);
551 locations.sort((a, b) => a.offset.compareTo(b.offset)); 551 locations.sort((a, b) => a.offset.compareTo(b.offset));
552 for (int i = 0; i < locations.length; i++) { 552 for (int i = 0; i < locations.length; i++) {
553 SourceLocation sourceLocation = locations[i]; 553 SourceLocation sourceLocation = locations[i];
554 int index = collection.getIndex(sourceLocation); 554 int index = collection.getIndex(sourceLocation);
555 int start = sourceLocation.column; 555 int start = sourceLocation.column;
556 int end = line.length; 556 int end = line.length;
557 if (i + 1 < locations.length) { 557 if (i + 1 < locations.length) {
558 end = locations[i + 1].column; 558 end = locations[i + 1].column;
559 } 559 }
560 if (i == 0) { 560 if (i == 0) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 String dartCode = truncate(codePoint.dartCode, 50); 620 String dartCode = truncate(codePoint.dartCode, 50);
621 buffer.write('<td class="code">${dartCode}</td>'); 621 buffer.write('<td class="code">${dartCode}</td>');
622 buffer.write('<td>${escape(codePoint.sourceLocation.shortText)}</td>'); 622 buffer.write('<td>${escape(codePoint.sourceLocation.shortText)}</td>');
623 } 623 }
624 buffer.write('</tr>'); 624 buffer.write('</tr>');
625 }); 625 });
626 buffer.write('</table>'); 626 buffer.write('</table>');
627 627
628 return buffer.toString(); 628 return buffer.toString();
629 } 629 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698