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

Unified Diff: lib/src/messages.dart

Issue 11450020: (Fix #215) better error printing in editor & extension, adds mapping for editor (Closed) Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years 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/dwc.dart ('k') | lib/src/options.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/messages.dart
diff --git a/lib/src/messages.dart b/lib/src/messages.dart
index 8ae12b46f7bdf17d14c89c6aa72ef55308459d32..45a88aa95e2473858c03694aee3b3858523b4861 100644
--- a/lib/src/messages.dart
+++ b/lib/src/messages.dart
@@ -4,6 +4,8 @@
library messages;
+import 'dart:json';
+
import 'package:html5lib/dom_parsing.dart' show SourceSpan;
import 'package:logging/logging.dart' show Level;
@@ -55,23 +57,39 @@ class Message {
return output.toString();
}
-}
-typedef void PrintHandler(Object obj);
+ String toJson() {
+ if (file == null) return toString();
+
+ var kind = (level == Level.SEVERE ? 'error' :
+ (level == Level.WARNING ? 'warning' : 'info'));
+ var json = {
+ 'method': kind,
+ 'params': {
+ 'file': file.toString(),
+ 'message': message,
+ 'line': span == null ? 1 : span.line + 1,
+ }
+ };
+ if (span != null) {
+ json['params']['charStart'] = span.start;
+ json['params']['charEnd'] = span.end;
+ }
+ return JSON.stringify([json]);
+ }
+}
/**
* This class tracks and prints information, warnings, and errors emitted by the
* compiler.
*/
class Messages {
- /** Called on every error. Set to blank function to supress printing. */
- final PrintHandler printHandler;
-
final CompilerOptions options;
+ final bool shouldPrint;
final List<Message> messages = <Message>[];
- Messages({CompilerOptions options, this.printHandler: print})
+ Messages({CompilerOptions options, this.shouldPrint: true})
: options = options != null ? options : new CompilerOptions();
// Convenience methods for testing
@@ -87,8 +105,9 @@ class Messages {
useColors: options.useColors);
messages.add(msg);
-
- printHandler(msg);
+ if (shouldPrint) {
Jennifer Messerly 2012/12/06 19:59:54 Put this in a helper function? (since we had that
Siggi Cherem (dart-lang) 2012/12/06 20:03:14 Done.
+ print(options.jsonFormat ? msg.toJson() : msg);
+ }
}
/** [message] is considered a type warning by the Dart lang. */
@@ -100,8 +119,9 @@ class Messages {
span: span, useColors: options.useColors);
messages.add(msg);
-
- printHandler(msg);
+ if (shouldPrint) {
+ print(options.jsonFormat ? msg.toJson() : msg);
+ }
}
}
@@ -114,7 +134,9 @@ class Messages {
useColors: options.useColors);
messages.add(msg);
-
- if (options.verbose) printHandler(msg);
+ if (shouldPrint && options.verbose) {
+ print(options.jsonFormat ? msg.toJson() : msg);
+ }
}
+
}
« no previous file with comments | « lib/dwc.dart ('k') | lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698