1
- // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
- // file at the top-level directory of this distribution and at
3
- // http://rust-lang.org/COPYRIGHT.
4
- //
5
- // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
- // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
- // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
- // option. This file may not be copied, modified, or distributed
9
- // except according to those terms.
10
-
11
1
//! Conversion of raw rustc-emitted JSON messages into LSP diagnostics.
12
2
//!
13
3
//! Data definitions for diagnostics can be found in the Rust compiler for:
14
- //! 1. Internal diagnostics at src/librustc_errors/diagnostic.rs.
15
- //! 2. Emitted JSON format at src/libsyntax/json.rs.
4
+ //! 1. Internal diagnostics at ` src/librustc_errors/diagnostic.rs` .
5
+ //! 2. Emitted JSON format at ` src/libsyntax/json.rs` .
16
6
17
7
use std:: collections:: HashMap ;
18
8
use std:: iter;
@@ -98,7 +88,8 @@ pub fn parse_diagnostics(
98
88
99
89
let mut diagnostics = HashMap :: new ( ) ;
100
90
101
- // If the client doesn't support related information, emit separate diagnostics for secondary spans
91
+ // If the client doesn't support related information, emit separate diagnostics for
92
+ // secondary spans.
102
93
let diagnostic_spans = if related_information_support { & primaries } else { & message. spans } ;
103
94
104
95
for ( path, diagnostic) in diagnostic_spans. iter ( ) . map ( |span| {
@@ -131,8 +122,8 @@ pub fn parse_diagnostics(
131
122
132
123
let rls_span = {
133
124
let mut span = span;
134
- // if span points to a macro, search through the expansions
135
- // for a more useful source location
125
+ // If span points to a macro, search through the expansions
126
+ // for a more useful source location.
136
127
while span. file_name . ends_with ( " macros>" ) && span. expansion . is_some ( ) {
137
128
span = & span. expansion . as_ref ( ) . unwrap ( ) . span ;
138
129
}
@@ -244,8 +235,8 @@ fn make_suggestions<'a>(
244
235
. collect ( ) ;
245
236
246
237
// Suggestions are displayed at primary span, so if the change is somewhere
247
- // else, be sure to specify that
248
- // TODO: In theory this can even point to different files - does that happen in practice?
238
+ // else, be sure to specify that.
239
+ // TODO: In theory this can even point to different files -- does that happen in practice?
249
240
for suggestion in & mut suggestions {
250
241
if !suggestion. range . is_within ( & primary_range) {
251
242
let line = suggestion. range . start . line + 1 ; // as 1-based
@@ -275,7 +266,7 @@ fn label_suggestion(span: &DiagnosticSpan, label: &str) -> Option<Suggestion> {
275
266
276
267
trait IsWithin {
277
268
/// Returns whether `other` is considered within `self`
278
- /// note : a thing should be 'within' itself
269
+ /// NOTE : a thing should be 'within' itself.
279
270
fn is_within ( & self , other : & Self ) -> bool ;
280
271
}
281
272
@@ -304,9 +295,9 @@ impl IsWithin for Range {
304
295
}
305
296
}
306
297
307
- /// Tests for formatted messages from the compilers json output
308
- /// run cargo with `--message-format=json` to generate the json for new tests and add .json
309
- /// message files to ' $FIXTURES_DIR/compiler_message/'
298
+ /// Tests for formatted messages from the compiler's JSON output.
299
+ /// Runs cargo with `--message-format=json` to generate the JSON for new tests and add JSON
300
+ /// message files to the ` $FIXTURES_DIR/compiler_message/` directory.
310
301
#[ cfg( test) ]
311
302
mod diagnostic_message_test {
312
303
use super :: * ;
@@ -332,7 +323,7 @@ mod diagnostic_message_test {
332
323
333
324
pub ( super ) trait FileDiagnosticTestExt {
334
325
fn single_file_results ( & self ) -> & Vec < ( Diagnostic , Vec < Suggestion > ) > ;
335
- /// Returns (primary message, secondary messages)
326
+ /// Returns ` (primary message, secondary messages)`.
336
327
fn to_messages ( & self ) -> Vec < ( String , Vec < String > ) > ;
337
328
fn to_primary_messages ( & self ) -> Vec < String > ;
338
329
fn to_secondary_messages ( & self ) -> Vec < String > ;
@@ -419,7 +410,7 @@ mod diagnostic_message_test {
419
410
assert_eq ! ( messages[ 0 ] . 1 , vec![ "consider giving `v` a type" , "cannot infer type for `T`" ] ) ;
420
411
421
412
// Check if we don't emit related information if it's not supported and
422
- // if secondary spans are emitted as separate diagnostics
413
+ // if secondary spans are emitted as separate diagnostics.
423
414
let messages = parse_compiler_message (
424
415
& read_fixture ( "compiler_message/type-annotations-needed.json" ) ,
425
416
false ,
@@ -477,7 +468,7 @@ mod diagnostic_message_test {
477
468
cannot borrow mutably",
478
469
) ;
479
470
480
- // note: consider message becomes a suggestion
471
+ // NOTE: ' consider' message becomes a suggestion.
481
472
assert_eq ! (
482
473
messages[ 0 ] . 1 ,
483
474
vec![ "consider changing this to `mut string`" , "cannot borrow mutably" , ]
@@ -675,7 +666,7 @@ help: consider borrowing here: `&string`"#,
675
666
}
676
667
}
677
668
678
- /// Tests for creating suggestions from the compilers json output
669
+ /// Tests for creating suggestions from the compilers JSON output.
679
670
#[ cfg( test) ]
680
671
mod diagnostic_suggestion_test {
681
672
use self :: diagnostic_message_test:: * ;
0 commit comments