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

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

Issue 2788373002: Add Source.getTextLine and use it to display source snippets in error messages. (Closed)
Patch Set: Remove getLine, getColumn, and getLineText. 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library sourcemap.diff; 5 library sourcemap.diff;
6 6
7 import 'package:compiler/src/io/source_file.dart'; 7 import 'package:compiler/src/io/source_file.dart';
8 8
9 import 'html_parts.dart'; 9 import 'html_parts.dart';
10 import 'output_structure.dart'; 10 import 'output_structure.dart';
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 List<HtmlPart> codeLinesFromCodeSource(CodeSource codeSource) { 533 List<HtmlPart> codeLinesFromCodeSource(CodeSource codeSource) {
534 List<HtmlPart> lines = <HtmlPart>[]; 534 List<HtmlPart> lines = <HtmlPart>[];
535 SourceFile sourceFile = sourceFileManager.getSourceFile(codeSource.uri); 535 SourceFile sourceFile = sourceFileManager.getSourceFile(codeSource.uri);
536 String elementName = codeSource.name; 536 String elementName = codeSource.name;
537 HtmlLine line = new HtmlLine(); 537 HtmlLine line = new HtmlLine();
538 line.htmlParts.add(new ConstHtmlPart('<span class="comment">')); 538 line.htmlParts.add(new ConstHtmlPart('<span class="comment">'));
539 line.htmlParts.add(new HtmlText('${elementName}: ${sourceFile.filename}')); 539 line.htmlParts.add(new HtmlText('${elementName}: ${sourceFile.filename}'));
540 line.htmlParts.add(new ConstHtmlPart('</span>')); 540 line.htmlParts.add(new ConstHtmlPart('</span>'));
541 lines.add(line); 541 lines.add(line);
542 if (codeSource.begin != null) { 542 if (codeSource.begin != null) {
543 int startLine = sourceFile.getLine(codeSource.begin); 543 int startLine = sourceFile.getLocation(codeSource.begin).line - 1;
544 int endLine = sourceFile.getLine(codeSource.end) + 1; 544 int endLine = sourceFile.getLocation(codeSource.end).line;
545 for (CodeLine codeLine in convertAnnotatedCodeToCodeLines( 545 for (CodeLine codeLine in convertAnnotatedCodeToCodeLines(
546 sourceFile.slowText(), const <Annotation>[], 546 sourceFile.slowText(), const <Annotation>[],
547 startLine: startLine, endLine: endLine)) { 547 startLine: startLine, endLine: endLine)) {
548 codeLine.lineAnnotation = codeSource; 548 codeLine.lineAnnotation = codeSource;
549 lines.add(codeLine); 549 lines.add(codeLine);
550 } 550 }
551 } 551 }
552 return lines; 552 return lines;
553 } 553 }
554 554
(...skipping 30 matching lines...) Expand all
585 startLine: interval.from, endLine: interval.to, uri: currentUri); 585 startLine: interval.from, endLine: interval.to, uri: currentUri);
586 if (codeSources != null) { 586 if (codeSources != null) {
587 CodeSource currentCodeSource; 587 CodeSource currentCodeSource;
588 Interval currentLineInterval; 588 Interval currentLineInterval;
589 for (CodeLine dartCodeLine in annotatedDartCodeLines) { 589 for (CodeLine dartCodeLine in annotatedDartCodeLines) {
590 if (currentCodeSource == null || 590 if (currentCodeSource == null ||
591 !currentLineInterval.contains(dartCodeLine.lineNo)) { 591 !currentLineInterval.contains(dartCodeLine.lineNo)) {
592 currentCodeSource = null; 592 currentCodeSource = null;
593 for (CodeSource codeSource in codeSources) { 593 for (CodeSource codeSource in codeSources) {
594 Interval interval = new Interval( 594 Interval interval = new Interval(
595 sourceFile.getLine(codeSource.begin), 595 sourceFile.getLocation(codeSource.begin).line - 1,
596 sourceFile.getLine(codeSource.end) + 1); 596 sourceFile.getLocation(codeSource.end).line);
597 if (interval.contains(dartCodeLine.lineNo)) { 597 if (interval.contains(dartCodeLine.lineNo)) {
598 currentCodeSource = codeSource; 598 currentCodeSource = codeSource;
599 currentLineInterval = interval; 599 currentLineInterval = interval;
600 break; 600 break;
601 } 601 }
602 } 602 }
603 } 603 }
604 if (currentCodeSource != null) { 604 if (currentCodeSource != null) {
605 dartCodeLine.lineAnnotation = currentCodeSource; 605 dartCodeLine.lineAnnotation = currentCodeSource;
606 } 606 }
(...skipping 25 matching lines...) Expand all
632 codeLineInterval.clear(); 632 codeLineInterval.clear();
633 codeLineInterval[codeLine] = interval; 633 codeLineInterval[codeLine] = interval;
634 } 634 }
635 635
636 for (CodeLine jsCodeLine in jsCodeLines) { 636 for (CodeLine jsCodeLine in jsCodeLines) {
637 for (Annotation annotation in jsCodeLine.annotations) { 637 for (Annotation annotation in jsCodeLine.annotations) {
638 CodeLineAnnotation codeLineAnnotation = annotation.data; 638 CodeLineAnnotation codeLineAnnotation = annotation.data;
639 639
640 for (CodeLocation location in codeLineAnnotation.codeLocations) { 640 for (CodeLocation location in codeLineAnnotation.codeLocations) {
641 SourceFile sourceFile = sourceFileManager.getSourceFile(location.uri); 641 SourceFile sourceFile = sourceFileManager.getSourceFile(location.uri);
642 int line = sourceFile.getLine(location.offset); 642 int line = sourceFile.getLocation(location.offset).line - 1;
643 if (currentUri != location.uri) { 643 if (currentUri != location.uri) {
644 restart(jsCodeLine, location, line); 644 restart(jsCodeLine, location, line);
645 } else if (interval.inWindow(line, windowSize: 2)) { 645 } else if (interval.inWindow(line, windowSize: 2)) {
646 interval = interval.include(line); 646 interval = interval.include(line);
647 codeLineInterval[jsCodeLine] = interval; 647 codeLineInterval[jsCodeLine] = interval;
648 } else { 648 } else {
649 restart(jsCodeLine, location, line); 649 restart(jsCodeLine, location, line);
650 } 650 }
651 651
652 annotations.add(new Annotation(codeLineAnnotation.annotationType, 652 annotations.add(new Annotation(codeLineAnnotation.annotationType,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 annotationType: AnnotationType.values[json['annotationType']], 759 annotationType: AnnotationType.values[json['annotationType']],
760 codeLocations: json['codeLocations'] 760 codeLocations: json['codeLocations']
761 .map((j) => CodeLocation.fromJson(j, strategy)) 761 .map((j) => CodeLocation.fromJson(j, strategy))
762 .toList(), 762 .toList(),
763 codeSources: 763 codeSources:
764 json['codeSources'].map((j) => CodeSource.fromJson(j)).toList(), 764 json['codeSources'].map((j) => CodeSource.fromJson(j)).toList(),
765 stepInfo: json['stepInfo'], 765 stepInfo: json['stepInfo'],
766 sourceMappingIndex: json['sourceMappingIndex']); 766 sourceMappingIndex: json['sourceMappingIndex']);
767 } 767 }
768 } 768 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698