Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 17a4394

Browse files
committed
Auto merge of #1326 - Xanewok:alexreg-cosmetic-2, r=Xanewok
Various cosmetic improvements Closes #1314 (same PR + follow up test fixes).
2 parents b5a02e0 + e384730 commit 17a4394

File tree

110 files changed

+576
-951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+576
-951
lines changed

rls/src/actions/diagnostics.rs

+16-25
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
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-
111
//! Conversion of raw rustc-emitted JSON messages into LSP diagnostics.
122
//!
133
//! 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`.
166
177
use std::collections::HashMap;
188
use std::iter;
@@ -98,7 +88,8 @@ pub fn parse_diagnostics(
9888

9989
let mut diagnostics = HashMap::new();
10090

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.
10293
let diagnostic_spans = if related_information_support { &primaries } else { &message.spans };
10394

10495
for (path, diagnostic) in diagnostic_spans.iter().map(|span| {
@@ -131,8 +122,8 @@ pub fn parse_diagnostics(
131122

132123
let rls_span = {
133124
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.
136127
while span.file_name.ends_with(" macros>") && span.expansion.is_some() {
137128
span = &span.expansion.as_ref().unwrap().span;
138129
}
@@ -244,8 +235,8 @@ fn make_suggestions<'a>(
244235
.collect();
245236

246237
// 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?
249240
for suggestion in &mut suggestions {
250241
if !suggestion.range.is_within(&primary_range) {
251242
let line = suggestion.range.start.line + 1; // as 1-based
@@ -275,7 +266,7 @@ fn label_suggestion(span: &DiagnosticSpan, label: &str) -> Option<Suggestion> {
275266

276267
trait IsWithin {
277268
/// Returns whether `other` is considered within `self`
278-
/// note: a thing should be 'within' itself
269+
/// NOTE: a thing should be 'within' itself.
279270
fn is_within(&self, other: &Self) -> bool;
280271
}
281272

@@ -304,9 +295,9 @@ impl IsWithin for Range {
304295
}
305296
}
306297

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.
310301
#[cfg(test)]
311302
mod diagnostic_message_test {
312303
use super::*;
@@ -332,7 +323,7 @@ mod diagnostic_message_test {
332323

333324
pub(super) trait FileDiagnosticTestExt {
334325
fn single_file_results(&self) -> &Vec<(Diagnostic, Vec<Suggestion>)>;
335-
/// Returns (primary message, secondary messages)
326+
/// Returns `(primary message, secondary messages)`.
336327
fn to_messages(&self) -> Vec<(String, Vec<String>)>;
337328
fn to_primary_messages(&self) -> Vec<String>;
338329
fn to_secondary_messages(&self) -> Vec<String>;
@@ -419,7 +410,7 @@ mod diagnostic_message_test {
419410
assert_eq!(messages[0].1, vec!["consider giving `v` a type", "cannot infer type for `T`"]);
420411

421412
// 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.
423414
let messages = parse_compiler_message(
424415
&read_fixture("compiler_message/type-annotations-needed.json"),
425416
false,
@@ -477,7 +468,7 @@ mod diagnostic_message_test {
477468
cannot borrow mutably",
478469
);
479470

480-
// note: consider message becomes a suggestion
471+
// NOTE: 'consider' message becomes a suggestion.
481472
assert_eq!(
482473
messages[0].1,
483474
vec!["consider changing this to `mut string`", "cannot borrow mutably",]
@@ -675,7 +666,7 @@ help: consider borrowing here: `&string`"#,
675666
}
676667
}
677668

678-
/// Tests for creating suggestions from the compilers json output
669+
/// Tests for creating suggestions from the compilers JSON output.
679670
#[cfg(test)]
680671
mod diagnostic_suggestion_test {
681672
use self::diagnostic_message_test::*;

rls/src/actions/format.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
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-
//! Code formatting using Rustfmt - by default using statically-linked one or
1+
//! Code formatting using Rustfmt -- by default using statically-linked one or
122
//! possibly running Rustfmt binary specified by the user.
133
144
use std::env::temp_dir;
@@ -22,12 +12,12 @@ use rand::{distributions, thread_rng, Rng};
2212
use rustfmt_nightly::{Config, Input, Session};
2313
use serde_json;
2414

25-
/// Specified which `rustfmt` to use.
15+
/// Specifies which `rustfmt` to use.
2616
#[derive(Clone)]
2717
pub enum Rustfmt {
28-
/// (Path to external `rustfmt`, cwd where it should be spawned at)
18+
/// `(path to external `rustfmt`, current working directory to spawn at)`
2919
External(PathBuf, PathBuf),
30-
/// Statically linked `rustfmt`
20+
/// Statically linked `rustfmt`.
3121
Internal,
3222
}
3323

@@ -90,7 +80,8 @@ fn format_internal(input: String, config: Config) -> Result<String, String> {
9080

9181
match session.format(Input::Text(input)) {
9282
Ok(report) => {
93-
// Session::format returns Ok even if there are any errors, i.e., parsing errors.
83+
// `Session::format` returns `Ok` even if there are any errors, i.e., parsing
84+
// errors.
9485
if session.has_operational_errors() || session.has_parsing_errors() {
9586
debug!("reformat: format_input failed: has errors, report = {}", report);
9687

0 commit comments

Comments
 (0)