@@ -92,25 +92,54 @@ fn span_to_str(sp: span, cm: codemap) -> str {
92
92
ret res;
93
93
}
94
94
95
- fn emit_diagnostic ( sp : option:: t < span > , msg : str , kind : str , color : u8 ,
95
+ tag diagnostictype {
96
+ warning;
97
+ error;
98
+ note;
99
+ }
100
+
101
+ fn diagnosticstr ( t : diagnostictype ) -> str {
102
+ alt t {
103
+ warning. { "warning" }
104
+ error. { "error" }
105
+ note. { "note" }
106
+ }
107
+ }
108
+
109
+ fn diagnosticcolor ( t : diagnostictype ) -> u8 {
110
+ alt t {
111
+ warning. { term : : color_bright_yellow }
112
+ error. { term:: color_bright_red }
113
+ note. { term:: color_bright_green }
114
+ }
115
+ }
116
+
117
+ fn print_diagnostic ( topic : str , t : diagnostictype , msg : str ) {
118
+ if str:: is_not_empty ( topic) {
119
+ io:: stdout ( ) . write_str ( #fmt[ "%s " , topic] ) ;
120
+ }
121
+ if term:: color_supported ( ) {
122
+ term:: fg ( io:: stdout ( ) . get_buf_writer ( ) , diagnosticcolor ( t) ) ;
123
+ }
124
+ io:: stdout ( ) . write_str ( #fmt[ "%s:" , diagnosticstr ( t) ] ) ;
125
+ if term:: color_supported ( ) {
126
+ term:: reset ( io:: stdout ( ) . get_buf_writer ( ) ) ;
127
+ }
128
+ io:: stdout ( ) . write_str ( #fmt[ " %s\n " , msg] ) ;
129
+ }
130
+
131
+ fn emit_diagnostic ( sp : option:: t < span > , msg : str , t : diagnostictype ,
96
132
cm : codemap ) {
97
133
let ss = "" ;
98
134
let maybe_lines: option:: t < @file_lines > = none;
99
135
alt sp {
100
136
some( ssp) {
101
- ss = span_to_str ( ssp, cm) + " " ;
137
+ ss = span_to_str ( ssp, cm) ;
102
138
maybe_lines = some ( span_to_lines ( ssp, cm) ) ;
103
139
}
104
140
none. { }
105
141
}
106
- io:: stdout ( ) . write_str ( ss) ;
107
- if term:: color_supported ( ) {
108
- term:: fg ( io:: stdout ( ) . get_buf_writer ( ) , color) ;
109
- }
110
- io:: stdout ( ) . write_str ( #fmt[ "%s:" , kind] ) ;
111
- if term:: color_supported ( ) { term:: reset ( io:: stdout ( ) . get_buf_writer ( ) ) ; }
112
- io:: stdout ( ) . write_str ( #fmt[ " %s\n " , msg] ) ;
113
-
142
+ print_diagnostic ( ss, t, msg) ;
114
143
maybe_highlight_lines ( sp, cm, maybe_lines) ;
115
144
}
116
145
@@ -183,13 +212,13 @@ fn maybe_highlight_lines(sp: option::t<span>, cm: codemap,
183
212
}
184
213
185
214
fn emit_warning ( sp : option:: t < span > , msg : str , cm : codemap ) {
186
- emit_diagnostic ( sp, msg, " warning" , term :: color_bright_yellow , cm) ;
215
+ emit_diagnostic ( sp, msg, warning, cm) ;
187
216
}
188
217
fn emit_error ( sp : option:: t < span > , msg : str , cm : codemap ) {
189
- emit_diagnostic ( sp, msg, " error" , term :: color_bright_red , cm) ;
218
+ emit_diagnostic ( sp, msg, error, cm) ;
190
219
}
191
220
fn emit_note ( sp : option:: t < span > , msg : str , cm : codemap ) {
192
- emit_diagnostic ( sp, msg, " note" , term :: color_bright_green , cm) ;
221
+ emit_diagnostic ( sp, msg, note, cm) ;
193
222
}
194
223
195
224
type file_lines = { name : str , lines : [ uint ] } ;
0 commit comments