OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 messages; | 5 library messages; |
6 | 6 |
7 import 'dart:json' as json; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:source_maps/span.dart' show Span; | 9 import 'package:source_maps/span.dart' show Span; |
10 import 'package:logging/logging.dart' show Level; | 10 import 'package:logging/logging.dart' show Level; |
11 | 11 |
12 import 'options.dart'; | 12 import 'options.dart'; |
13 import 'utils.dart'; | 13 import 'utils.dart'; |
14 | 14 |
15 /** Map between error levels and their display color. */ | 15 /** Map between error levels and their display color. */ |
16 final Map<Level, String> _ERROR_COLORS = (() { | 16 final Map<Level, String> _ERROR_COLORS = (() { |
17 var colorsMap = new Map<Level, String>(); | 17 var colorsMap = new Map<Level, String>(); |
(...skipping 28 matching lines...) Expand all Loading... |
46 } else { | 46 } else { |
47 output.write(span.getLocationMessage(message, useColors: colors, | 47 output.write(span.getLocationMessage(message, useColors: colors, |
48 color: levelColor)); | 48 color: levelColor)); |
49 } | 49 } |
50 | 50 |
51 return output.toString(); | 51 return output.toString(); |
52 } | 52 } |
53 | 53 |
54 String toJson() { | 54 String toJson() { |
55 if (span == null) return toString(); | 55 if (span == null) return toString(); |
56 return json.stringify([{ | 56 return JSON.encode([{ |
57 'method': kind, | 57 'method': kind, |
58 'params': { | 58 'params': { |
59 'file': span.sourceUrl, | 59 'file': span.sourceUrl, |
60 'message': message, | 60 'message': message, |
61 'line': span.start.line + 1, | 61 'line': span.start.line + 1, |
62 'charStart': span.start.offset, | 62 'charStart': span.start.offset, |
63 'charEnd': span.end.offset, | 63 'charEnd': span.end.offset, |
64 } | 64 } |
65 }]); | 65 }]); |
66 } | 66 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 useColors: options.useColors); | 139 useColors: options.useColors); |
140 | 140 |
141 messages.add(msg); | 141 messages.add(msg); |
142 if (options.verbose) printMessage(msg); | 142 if (options.verbose) printMessage(msg); |
143 } | 143 } |
144 | 144 |
145 void printMessage(msg) { | 145 void printMessage(msg) { |
146 if (shouldPrint) print(options.jsonFormat ? msg.toJson() : msg); | 146 if (shouldPrint) print(options.jsonFormat ? msg.toJson() : msg); |
147 } | 147 } |
148 } | 148 } |
OLD | NEW |