9
9
10
10
// FIXME: spec the JSON output properly.
11
11
12
- use rustc_span:: source_map:: SourceMap ;
13
- use termcolor:: { ColorSpec , WriteColor } ;
14
-
15
12
use crate :: emitter:: {
16
13
should_show_source_code, ColorConfig , Destination , Emitter , HumanEmitter ,
17
14
HumanReadableErrorType ,
@@ -22,32 +19,39 @@ use crate::{
22
19
diagnostic:: IsLint , CodeSuggestion , FluentBundle , LazyFallbackBundle , MultiSpan , SpanLabel ,
23
20
Subdiag , TerminalUrl ,
24
21
} ;
25
- use rustc_lint_defs:: Applicability ;
26
-
22
+ use derive_setters:: Setters ;
27
23
use rustc_data_structures:: sync:: { IntoDynSyncSend , Lrc } ;
28
24
use rustc_error_messages:: FluentArgs ;
25
+ use rustc_lint_defs:: Applicability ;
29
26
use rustc_span:: hygiene:: ExpnData ;
27
+ use rustc_span:: source_map:: SourceMap ;
30
28
use rustc_span:: Span ;
29
+ use serde:: Serialize ;
31
30
use std:: error:: Report ;
32
31
use std:: io:: { self , Write } ;
33
32
use std:: path:: Path ;
34
33
use std:: sync:: { Arc , Mutex } ;
35
34
use std:: vec;
36
-
37
- use serde:: Serialize ;
35
+ use termcolor:: { ColorSpec , WriteColor } ;
38
36
39
37
#[ cfg( test) ]
40
38
mod tests;
41
39
40
+ #[ derive( Setters ) ]
42
41
pub struct JsonEmitter {
42
+ #[ setters( skip) ]
43
43
dst : IntoDynSyncSend < Box < dyn Write + Send > > ,
44
44
registry : Option < Registry > ,
45
+ #[ setters( skip) ]
45
46
sm : Lrc < SourceMap > ,
46
47
fluent_bundle : Option < Lrc < FluentBundle > > ,
48
+ #[ setters( skip) ]
47
49
fallback_bundle : LazyFallbackBundle ,
50
+ #[ setters( skip) ]
48
51
pretty : bool ,
49
52
ui_testing : bool ,
50
53
ignored_directories_in_source_blocks : Vec < String > ,
54
+ #[ setters( skip) ]
51
55
json_rendered : HumanReadableErrorType ,
52
56
diagnostic_width : Option < usize > ,
53
57
macro_backtrace : bool ,
@@ -58,42 +62,28 @@ pub struct JsonEmitter {
58
62
impl JsonEmitter {
59
63
pub fn new (
60
64
dst : Box < dyn Write + Send > ,
61
- registry : Option < Registry > ,
62
- source_map : Lrc < SourceMap > ,
63
- fluent_bundle : Option < Lrc < FluentBundle > > ,
65
+ sm : Lrc < SourceMap > ,
64
66
fallback_bundle : LazyFallbackBundle ,
65
67
pretty : bool ,
66
68
json_rendered : HumanReadableErrorType ,
67
- diagnostic_width : Option < usize > ,
68
- macro_backtrace : bool ,
69
- track_diagnostics : bool ,
70
- terminal_url : TerminalUrl ,
71
69
) -> JsonEmitter {
72
70
JsonEmitter {
73
71
dst : IntoDynSyncSend ( dst) ,
74
- registry,
75
- sm : source_map ,
76
- fluent_bundle,
72
+ registry : None ,
73
+ sm,
74
+ fluent_bundle : None ,
77
75
fallback_bundle,
78
76
pretty,
79
77
ui_testing : false ,
80
78
ignored_directories_in_source_blocks : Vec :: new ( ) ,
81
79
json_rendered,
82
- diagnostic_width,
83
- macro_backtrace,
84
- track_diagnostics,
85
- terminal_url,
80
+ diagnostic_width : None ,
81
+ macro_backtrace : false ,
82
+ track_diagnostics : false ,
83
+ terminal_url : TerminalUrl :: No ,
86
84
}
87
85
}
88
86
89
- pub fn ui_testing ( self , ui_testing : bool ) -> Self {
90
- Self { ui_testing, ..self }
91
- }
92
-
93
- pub fn ignored_directories_in_source_blocks ( self , value : Vec < String > ) -> Self {
94
- Self { ignored_directories_in_source_blocks : value, ..self }
95
- }
96
-
97
87
fn emit ( & mut self , val : EmitTyped < ' _ > ) -> io:: Result < ( ) > {
98
88
if self . pretty {
99
89
serde_json:: to_writer_pretty ( & mut * self . dst , & val) ?
0 commit comments