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

Side by Side 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 unified diff | Download patch
OLDNEW
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';
8
7 import 'package:html5lib/dom_parsing.dart' show SourceSpan; 9 import 'package:html5lib/dom_parsing.dart' show SourceSpan;
8 import 'package:logging/logging.dart' show Level; 10 import 'package:logging/logging.dart' show Level;
9 11
10 import 'file_system/path.dart'; 12 import 'file_system/path.dart';
11 import 'options.dart'; 13 import 'options.dart';
12 import 'utils.dart'; 14 import 'utils.dart';
13 15
14 // TODO(jmesserly): remove the global messages. We instead use some 16 // TODO(jmesserly): remove the global messages. We instead use some
15 // object that tracks compilation state. 17 // object that tracks compilation state.
16 18
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (span == null) { 50 if (span == null) {
49 if (file != null) output.add('$file: '); 51 if (file != null) output.add('$file: ');
50 output.add(message); 52 output.add(message);
51 } else { 53 } else {
52 output.add(span.toMessageString( 54 output.add(span.toMessageString(
53 file.toString(), message, useColors: colors)); 55 file.toString(), message, useColors: colors));
54 } 56 }
55 57
56 return output.toString(); 58 return output.toString();
57 } 59 }
60
61 String toJson() {
62 var kind = (level == Level.SEVERE ? 'error' :
63 (level == Level.WARNING ? 'warning' : 'info'));
64 var json = {
65 'method': kind,
66 'params': {
67 'file': file.toString(),
68 'line': span.line + 1,
Jennifer Messerly 2012/12/06 04:00:08 Not all messages have a span. IIRC, info messages
Siggi Cherem (dart-lang) 2012/12/06 18:46:42 good point - this made me realize that we have pla
69 'message': message,
70 'charStart': span.start,
71 'charEnd': span.end
72 }
73 };
74 return JSON.stringify([json]);
75 }
58 } 76 }
59 77
60 typedef void PrintHandler(Object obj);
61
62 /** 78 /**
63 * This class tracks and prints information, warnings, and errors emitted by the 79 * This class tracks and prints information, warnings, and errors emitted by the
64 * compiler. 80 * compiler.
65 */ 81 */
66 class Messages { 82 class Messages {
67 /** Called on every error. Set to blank function to supress printing. */
68 final PrintHandler printHandler;
Jennifer Messerly 2012/12/06 04:00:08 I think we should keep printHandler, so we can pri
69
70 final CompilerOptions options; 83 final CompilerOptions options;
71 84
72 final List<Message> messages = <Message>[]; 85 final List<Message> messages = <Message>[];
73 86
74 Messages({CompilerOptions options, this.printHandler: print}) 87 Messages({CompilerOptions options})
75 : options = options != null ? options : new CompilerOptions(); 88 : options = options != null ? options : new CompilerOptions();
76 89
77 // Convenience methods for testing 90 // Convenience methods for testing
78 int get length => messages.length; 91 int get length => messages.length;
79 Message operator[](int index) => messages[index]; 92 Message operator[](int index) => messages[index];
80 void clear() { 93 void clear() {
81 messages.clear(); 94 messages.clear();
82 } 95 }
83 96
84 /** [message] is considered a static compile-time error by the Dart lang. */ 97 /** [message] is considered a static compile-time error by the Dart lang. */
85 void error(String message, SourceSpan span, {Path file}) { 98 void error(String message, SourceSpan span, {Path file}) {
86 var msg = new Message(Level.SEVERE, message, file: file, span: span, 99 var msg = new Message(Level.SEVERE, message, file: file, span: span,
87 useColors: options.useColors); 100 useColors: options.useColors);
88 101
89 messages.add(msg); 102 messages.add(msg);
90
91 printHandler(msg);
92 } 103 }
93 104
94 /** [message] is considered a type warning by the Dart lang. */ 105 /** [message] is considered a type warning by the Dart lang. */
95 void warning(String message, SourceSpan span, {Path file}) { 106 void warning(String message, SourceSpan span, {Path file}) {
96 if (options.warningsAsErrors) { 107 if (options.warningsAsErrors) {
97 error(message, span, file: file); 108 error(message, span, file: file);
98 } else { 109 } else {
99 var msg = new Message(Level.WARNING, message, file: file, 110 var msg = new Message(Level.WARNING, message, file: file,
100 span: span, useColors: options.useColors); 111 span: span, useColors: options.useColors);
101 112
102 messages.add(msg); 113 messages.add(msg);
103
104 printHandler(msg);
105 } 114 }
106 } 115 }
107 116
108 /** 117 /**
109 * [message] at [file] will tell the user about what the compiler 118 * [message] at [file] will tell the user about what the compiler
110 * is doing. 119 * is doing.
111 */ 120 */
112 void info(String message, SourceSpan span, {Path file}) { 121 void info(String message, SourceSpan span, {Path file}) {
113 var msg = new Message(Level.INFO, message, file: file, span: span, 122 var msg = new Message(Level.INFO, message, file: file, span: span,
114 useColors: options.useColors); 123 useColors: options.useColors);
115 124
116 messages.add(msg); 125 messages.add(msg);
117
118 if (options.verbose) printHandler(msg);
119 } 126 }
120 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698