File tree 3 files changed +17
-29
lines changed
3 files changed +17
-29
lines changed Original file line number Diff line number Diff line change @@ -51,28 +51,26 @@ impl DiagnosticCode {
51
51
52
52
#[ derive( Debug ) ]
53
53
pub struct Diagnostic {
54
- // pub name: Option<String> ,
54
+ pub code : DiagnosticCode ,
55
55
pub message : String ,
56
56
pub range : TextRange ,
57
57
pub severity : Severity ,
58
- pub fixes : Option < Vec < Assist > > ,
59
58
pub unused : bool ,
60
- pub code : Option < DiagnosticCode > ,
61
59
pub experimental : bool ,
60
+ pub fixes : Option < Vec < Assist > > ,
62
61
}
63
62
64
63
impl Diagnostic {
65
64
fn new ( code : & ' static str , message : impl Into < String > , range : TextRange ) -> Diagnostic {
66
65
let message = message. into ( ) ;
67
- let code = Some ( DiagnosticCode ( code ) ) ;
68
- Self {
66
+ Diagnostic {
67
+ code : DiagnosticCode ( code ) ,
69
68
message,
70
69
range,
71
70
severity : Severity :: Error ,
72
- fixes : None ,
73
71
unused : false ,
74
- code,
75
72
experimental : false ,
73
+ fixes : None ,
76
74
}
77
75
}
78
76
@@ -181,15 +179,8 @@ pub(crate) fn diagnostics(
181
179
}
182
180
183
181
res. retain ( |d| {
184
- if let Some ( code) = d. code {
185
- if ctx. config . disabled . contains ( code. as_str ( ) ) {
186
- return false ;
187
- }
188
- }
189
- if ctx. config . disable_experimental && d. experimental {
190
- return false ;
191
- }
192
- true
182
+ !ctx. config . disabled . contains ( d. code . as_str ( ) )
183
+ && !( ctx. config . disable_experimental && d. experimental )
193
184
} ) ;
194
185
195
186
res
Original file line number Diff line number Diff line change @@ -65,9 +65,14 @@ mod baz {}
65
65
expect ! [ [ r#"
66
66
[
67
67
Diagnostic {
68
+ code: DiagnosticCode(
69
+ "unresolved-module",
70
+ ),
68
71
message: "unresolved module",
69
72
range: 0..8,
70
73
severity: Error,
74
+ unused: false,
75
+ experimental: false,
71
76
fixes: Some(
72
77
[
73
78
Assist {
@@ -98,13 +103,6 @@ mod baz {}
98
103
},
99
104
],
100
105
),
101
- unused: false,
102
- code: Some(
103
- DiagnosticCode(
104
- "unresolved-module",
105
- ),
106
- ),
107
- experimental: false,
108
106
},
109
107
]
110
108
"# ] ] ,
Original file line number Diff line number Diff line change @@ -1229,14 +1229,13 @@ pub(crate) fn publish_diagnostics(
1229
1229
. map ( |d| Diagnostic {
1230
1230
range : to_proto:: range ( & line_index, d. range ) ,
1231
1231
severity : Some ( to_proto:: diagnostic_severity ( d. severity ) ) ,
1232
- code : d. code . map ( |d| d . as_str ( ) . to_owned ( ) ) . map ( NumberOrString :: String ) ,
1233
- code_description : d . code . and_then ( |code| {
1234
- lsp_types:: Url :: parse ( & format ! (
1232
+ code : Some ( NumberOrString :: String ( d. code . as_str ( ) . to_string ( ) ) ) ,
1233
+ code_description : Some ( lsp_types :: CodeDescription {
1234
+ href : lsp_types:: Url :: parse ( & format ! (
1235
1235
"https://rust-analyzer.github.io/manual.html#{}" ,
1236
- code. as_str( )
1236
+ d . code. as_str( )
1237
1237
) )
1238
- . ok ( )
1239
- . map ( |href| lsp_types:: CodeDescription { href } )
1238
+ . unwrap ( ) ,
1240
1239
} ) ,
1241
1240
source : Some ( "rust-analyzer" . to_string ( ) ) ,
1242
1241
message : d. message ,
You can’t perform that action at this time.
0 commit comments