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

Unified Diff: lib/src/file.dart

Issue 1028813002: Introduce span with line context (Closed) Base URL: git@github.com:dart-lang/source_span.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/source_span.dart ('k') | lib/src/span.dart » ('j') | lib/src/span.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/file.dart
diff --git a/lib/src/file.dart b/lib/src/file.dart
index ed5f6a8371226ed65065789a6ec8ee043701426f..953a6afdbfce86b2aaf23eb2f21052a801f71280 100644
--- a/lib/src/file.dart
+++ b/lib/src/file.dart
@@ -12,6 +12,7 @@ import 'package:path/path.dart' as p;
import 'colors.dart' as colors;
import 'location.dart';
import 'span.dart';
+import 'span_context.dart';
import 'span_mixin.dart';
import 'utils.dart';
@@ -183,7 +184,7 @@ class FileLocation extends SourceLocation {
/// [FileSpan.union] will return a [FileSpan] if possible.
///
/// A [FileSpan] can be created using [SourceFile.span].
-class FileSpan extends SourceSpanMixin {
+class FileSpan extends SourceSpanMixin implements SourceSpanContext {
/// The [file] that [this] belongs to.
final SourceFile file;
@@ -262,40 +263,9 @@ class FileSpan extends SourceSpanMixin {
return new FileSpan._(file, start, end);
}
- String message(String message, {color}) {
Siggi Cherem (dart-lang) 2015/03/21 00:19:59 the old logic basically is now shared with the def
- if (color == true) color = colors.RED;
- if (color == false) color = null;
-
+ String get contextLine {
nweiz 2015/03/24 23:01:17 Nit: put getters above the constructor.
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Done.
var line = start.line;
- var column = start.column;
-
- var buffer = new StringBuffer();
- buffer.write('line ${start.line + 1}, column ${start.column + 1}');
- if (sourceUrl != null) buffer.write(' of ${p.prettyUri(sourceUrl)}');
- buffer.write(': $message\n');
-
- var textLine = file.getText(file.getOffset(line),
+ return file.getText(file.getOffset(line),
line == file.lines - 1 ? null : file.getOffset(line + 1));
-
- column = math.min(column, textLine.length - 1);
- var toColumn =
- math.min(column + end.offset - start.offset, textLine.length);
-
- if (color != null) {
- buffer.write(textLine.substring(0, column));
- buffer.write(color);
- buffer.write(textLine.substring(column, toColumn));
- buffer.write(colors.NONE);
- buffer.write(textLine.substring(toColumn));
- } else {
- buffer.write(textLine);
- }
- if (!textLine.endsWith('\n')) buffer.write('\n');
-
- buffer.write(' ' * column);
- if (color != null) buffer.write(color);
- buffer.write('^' * math.max(toColumn - column, 1));
- if (color != null) buffer.write(colors.NONE);
- return buffer.toString();
}
}
« no previous file with comments | « lib/source_span.dart ('k') | lib/src/span.dart » ('j') | lib/src/span.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698