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

Commit 77e0003

Browse files
author
Alexander Regueiro
committed
Various cosmetic improvements.
1 parent 9c790df commit 77e0003

22 files changed

+395
-395
lines changed

rls/src/actions/diagnostics.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Conversion of raw rustc-emitted JSON messages into LSP diagnostics.
22
//!
33
//! Data definitions for diagnostics can be found in the Rust compiler for:
4-
//! 1. Internal diagnostics at src/librustc_errors/diagnostic.rs.
5-
//! 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`.
66
77
use std::collections::HashMap;
88
use std::iter;
@@ -88,7 +88,8 @@ pub fn parse_diagnostics(
8888

8989
let mut diagnostics = HashMap::new();
9090

91-
// 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.
9293
let diagnostic_spans = if related_information_support { &primaries } else { &message.spans };
9394

9495
for (path, diagnostic) in diagnostic_spans.iter().map(|span| {
@@ -121,8 +122,8 @@ pub fn parse_diagnostics(
121122

122123
let rls_span = {
123124
let mut span = span;
124-
// if span points to a macro, search through the expansions
125-
// for a more useful source location
125+
// If span points to a macro, search through the expansions
126+
// for a more useful source location.
126127
while span.file_name.ends_with(" macros>") && span.expansion.is_some() {
127128
span = &span.expansion.as_ref().unwrap().span;
128129
}
@@ -234,8 +235,8 @@ fn make_suggestions<'a>(
234235
.collect();
235236

236237
// Suggestions are displayed at primary span, so if the change is somewhere
237-
// else, be sure to specify that
238-
// 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?
239240
for suggestion in &mut suggestions {
240241
if !suggestion.range.is_within(&primary_range) {
241242
let line = suggestion.range.start.line + 1; // as 1-based
@@ -265,7 +266,7 @@ fn label_suggestion(span: &DiagnosticSpan, label: &str) -> Option<Suggestion> {
265266

266267
trait IsWithin {
267268
/// Returns whether `other` is considered within `self`
268-
/// note: a thing should be 'within' itself
269+
/// NOTE: a thing should be 'within' itself.
269270
fn is_within(&self, other: &Self) -> bool;
270271
}
271272

@@ -294,9 +295,9 @@ impl IsWithin for Range {
294295
}
295296
}
296297

297-
/// Tests for formatted messages from the compilers json output
298-
/// run cargo with `--message-format=json` to generate the json for new tests and add .json
299-
/// 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.
300301
#[cfg(test)]
301302
mod diagnostic_message_test {
302303
use super::*;
@@ -322,7 +323,7 @@ mod diagnostic_message_test {
322323

323324
pub(super) trait FileDiagnosticTestExt {
324325
fn single_file_results(&self) -> &Vec<(Diagnostic, Vec<Suggestion>)>;
325-
/// Returns (primary message, secondary messages)
326+
/// Returns `(primary message, secondary messages)`.
326327
fn to_messages(&self) -> Vec<(String, Vec<String>)>;
327328
fn to_primary_messages(&self) -> Vec<String>;
328329
fn to_secondary_messages(&self) -> Vec<String>;
@@ -409,7 +410,7 @@ mod diagnostic_message_test {
409410
assert_eq!(messages[0].1, vec!["consider giving `v` a type", "cannot infer type for `T`"]);
410411

411412
// Check if we don't emit related information if it's not supported and
412-
// if secondary spans are emitted as separate diagnostics
413+
// if secondary spans are emitted as separate diagnostics.
413414
let messages = parse_compiler_message(
414415
&read_fixture("compiler_message/type-annotations-needed.json"),
415416
false,
@@ -467,7 +468,7 @@ mod diagnostic_message_test {
467468
cannot borrow mutably",
468469
);
469470

470-
// note: consider message becomes a suggestion
471+
// NOTE: 'consider' message becomes a suggestion.
471472
assert_eq!(
472473
messages[0].1,
473474
vec!["consider changing this to `mut string`", "cannot borrow mutably",]
@@ -665,7 +666,7 @@ help: consider borrowing here: `&string`"#,
665666
}
666667
}
667668

668-
/// Tests for creating suggestions from the compilers json output
669+
/// Tests for creating suggestions from the compilers JSON output.
669670
#[cfg(test)]
670671
mod diagnostic_suggestion_test {
671672
use self::diagnostic_message_test::*;

rls/src/actions/format.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Code formatting using Rustfmt - by default using statically-linked one or
1+
//! Code formatting using Rustfmt -- by default using statically-linked one or
22
//! possibly running Rustfmt binary specified by the user.
33
44
use std::env::temp_dir;
@@ -12,12 +12,12 @@ use rand::{distributions, thread_rng, Rng};
1212
use rustfmt_nightly::{Config, Input, Session};
1313
use serde_json;
1414

15-
/// Specified which `rustfmt` to use.
15+
/// Specifies which `rustfmt` to use.
1616
#[derive(Clone)]
1717
pub enum Rustfmt {
18-
/// (Path to external `rustfmt`, cwd where it should be spawned at)
18+
/// `(path to external `rustfmt`, current working directory to spawn at)`
1919
External(PathBuf, PathBuf),
20-
/// Statically linked `rustfmt`
20+
/// Statically linked `rustfmt`.
2121
Internal,
2222
}
2323

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

8181
match session.format(Input::Text(input)) {
8282
Ok(report) => {
83-
// 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.
8485
if session.has_operational_errors() || session.has_parsing_errors() {
8586
debug!("reformat: format_input failed: has errors, report = {}", report);
8687

rls/src/actions/hover.rs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
use crate::actions::format::Rustfmt;
2-
use crate::actions::requests;
3-
use crate::actions::InitActionContext;
4-
use crate::config::FmtConfig;
5-
use crate::lsp_data::*;
6-
use crate::server::ResponseError;
1+
use std::path::{Path, PathBuf};
72

83
use home;
4+
use log::*;
95
use racer;
106
use rls_analysis::{Def, DefKind};
117
use rls_span::{Column, Range, Row, Span, ZeroIndexed};
128
use rls_vfs::{self as vfs, Vfs};
139
use rustfmt_nightly::NewlineStyle;
1410
use serde_derive::{Deserialize, Serialize};
1511

16-
use log::*;
17-
use std::path::{Path, PathBuf};
12+
use crate::actions::format::Rustfmt;
13+
use crate::actions::requests;
14+
use crate::actions::InitActionContext;
15+
use crate::config::FmtConfig;
16+
use crate::lsp_data::*;
17+
use crate::server::ResponseError;
1818

1919
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
2020
pub struct Tooltip {
@@ -53,7 +53,7 @@ pub fn process_docs(docs: &str) -> String {
5353
line.to_string()
5454
};
5555

56-
// Racer sometimes pulls out comment block headers from the standard library
56+
// Racer sometimes pulls out comment block headers from the standard library.
5757
let ignore_slashes = line.starts_with("////");
5858

5959
let maybe_attribute = trimmed.starts_with("#[") || trimmed.starts_with("#![");
@@ -114,7 +114,7 @@ pub fn extract_docs(
114114
let attr_start = line.starts_with("#[") || line.starts_with("#![");
115115

116116
if attr_start && line.ends_with(']') && !hit_top {
117-
// Ignore single line attributes
117+
// Ignore single-line attributes.
118118
trace!(
119119
"extract_docs: ignoring single-line attribute, next_row: {:?}, up: {}",
120120
next_row,
@@ -124,7 +124,7 @@ pub fn extract_docs(
124124
}
125125

126126
// Continue with the next line when transitioning out of a
127-
// multi-line attribute
127+
// multi-line attribute.
128128
if attr_start || (line.ends_with(']') && !line.starts_with("//")) {
129129
in_meta = !in_meta;
130130
if !in_meta && !hit_top {
@@ -138,7 +138,7 @@ pub fn extract_docs(
138138
}
139139

140140
if !hit_top && in_meta {
141-
// Ignore milti-line attributes
141+
// Ignore milti-line attributes.
142142
trace!(
143143
"extract_docs: ignoring multi-line attribute, next_row: {:?}, up: {}, in_meta: {}",
144144
next_row,
@@ -171,7 +171,7 @@ pub fn extract_docs(
171171
}
172172

173173
if hit_top {
174-
// The top of the file was reached
174+
// The top of the file was reached.
175175
debug!(
176176
"extract_docs: bailing out: prev_row == next_row; next_row = {:?}, up = {}",
177177
next_row, up
@@ -214,8 +214,7 @@ fn extract_and_process_docs(vfs: &Vfs, file: &Path, row_start: Row<ZeroIndexed>)
214214
.and_then(empty_to_none)
215215
}
216216

217-
/// Extracts a function, method, struct, enum, or trait declaration
218-
/// from source.
217+
/// Extracts a function, method, struct, enum, or trait declaration from source.
219218
pub fn extract_decl(
220219
vfs: &Vfs,
221220
file: &Path,
@@ -318,10 +317,10 @@ fn tooltip_struct_enum_union_trait(
318317

319318
let vfs = ctx.vfs.clone();
320319
let fmt_config = ctx.fmt_config();
321-
// We hover often so use the in-process one to speed things up
320+
// We hover often, so use the in-process one to speed things up.
322321
let fmt = Rustfmt::Internal;
323322

324-
// fallback in case source extration fails
323+
// Fallback in case source extration fails.
325324
let the_type = || match def.kind {
326325
DefKind::Struct => format!("struct {}", def.name),
327326
DefKind::Enum => format!("enum {}", def.name),
@@ -373,7 +372,7 @@ fn tooltip_function_method(
373372

374373
let vfs = ctx.vfs.clone();
375374
let fmt_config = ctx.fmt_config();
376-
// We hover often so use the in-process one to speed things up
375+
// We hover often, so use the in-process one to speed things up.
377376
let fmt = Rustfmt::Internal;
378377

379378
let the_type = || {
@@ -461,7 +460,7 @@ fn empty_to_none(s: String) -> Option<String> {
461460
}
462461
}
463462

464-
/// Extract and process source documentation for the give `def`.
463+
/// Extracts and processes source documentation for the give `def`.
465464
fn def_docs(def: &Def, vfs: &Vfs) -> Option<String> {
466465
let save_analysis_docs = || empty_to_none(def.docs.trim().into());
467466
extract_and_process_docs(&vfs, def.span.file.as_ref(), def.span.range.row_start)
@@ -545,7 +544,7 @@ fn skip_path_components<P: AsRef<Path>>(
545544
})
546545
}
547546

548-
/// Collapse parent directory references inside of paths.
547+
/// Collapses parent directory references inside of paths.
549548
///
550549
/// # Example
551550
///
@@ -626,12 +625,12 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
626625
let contextstr_path = PathBuf::from(&contextstr);
627626
let contextstr_path = collapse_parents(contextstr_path);
628627

629-
// Tidy up the module path
630-
// Skips toolchains/$TOOLCHAIN/lib/rustlib/src/rust/src
628+
// Tidy up the module path.
629+
// Skips `toolchains/$TOOLCHAIN/lib/rustlib/src/rust/src`.
631630
skip_path_components(&contextstr_path, rustup_home, 7)
632-
// Skips /registry/src/github.com-1ecc6299db9ec823/
631+
// Skips `/registry/src/github.com-1ecc6299db9ec823/`.
633632
.or_else(|| skip_path_components(&contextstr_path, cargo_home, 3))
634-
// Make the path relative to the root of the project, if possible
633+
// Make the path relative to the root of the project, if possible.
635634
.or_else(|| {
636635
contextstr_path.strip_prefix(&ctx.current_project).ok().map(|x| x.to_owned())
637636
})
@@ -682,7 +681,7 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
682681
})
683682
}
684683

685-
/// Use racer to synthesize a `Def` for the given `span`. If no appropriate
684+
/// Uses racer to synthesize a `Def` for the given `span`. If no appropriate
686685
/// match is found with coordinates, `None` is returned.
687686
fn racer_def(ctx: &InitActionContext, span: &Span<ZeroIndexed>) -> Option<Def> {
688687
let vfs = ctx.vfs.clone();
@@ -711,7 +710,7 @@ fn racer_def(ctx: &InitActionContext, span: &Span<ZeroIndexed>) -> Option<Def> {
711710
let racer_match = racer::find_definition(file_path, location, &session);
712711
trace!("racer_def: match: {:?}", racer_match);
713712
racer_match
714-
// Avoid creating tooltip text that is exactly the item being hovered over
713+
// Avoid creating tooltip text that is exactly the item being hovered over.
715714
.filter(|m| name.as_ref().map(|name| name != &m.contextstr).unwrap_or(true))
716715
.and_then(|m| racer_match_to_def(ctx, &m))
717716
});
@@ -731,7 +730,7 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
731730
config.set().newline_style(NewlineStyle::Unix);
732731
let trimmed = the_type.trim();
733732

734-
// Normalize the ending for rustfmt
733+
// Normalize the ending for rustfmt.
735734
let object = if trimmed.ends_with(')') {
736735
format!("{};", trimmed)
737736
} else if trimmed.ends_with('}') || trimmed.ends_with(';') {
@@ -755,7 +754,7 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
755754
};
756755

757756
// If it's a tuple, remove the trailing ';' and hide non-pub components
758-
// for pub types
757+
// for pub types.
759758
let result = if formatted.trim().ends_with(';') {
760759
let mut decl = formatted.trim().trim_end_matches(';');
761760
if let (Some(pos), true) = (decl.rfind('('), decl.ends_with(')')) {
@@ -779,11 +778,11 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
779778
decl.to_string()
780779
}
781780
} else {
782-
// not a tuple
781+
// Not a tuple.
783782
decl.into()
784783
}
785784
} else {
786-
// not a tuple or unit struct
785+
// Not a tuple or unit struct.
787786
formatted
788787
};
789788

@@ -855,8 +854,7 @@ pub fn tooltip(
855854

856855
let racer_fallback_enabled = ctx.config.lock().unwrap().racer_completion;
857856

858-
// Fallback to racer if the def was not available and
859-
// racer is enabled.
857+
// Fallback to racer if the def was not available and racer is enabled.
860858
let hover_span_def = hover_span_def.or_else(|e| {
861859
debug!("tooltip: racer_fallback_enabled: {}", racer_fallback_enabled);
862860
if racer_fallback_enabled {

rls/src/actions/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ impl InitActionContext {
365365
self.build_queue.block_on_build();
366366
}
367367

368-
/// Returns true if there are no builds pending or in progress.
368+
/// Returns `true` if there are no builds pending or in progress.
369369
fn build_ready(&self) -> bool {
370370
self.build_queue.build_ready()
371371
}
372372

373-
/// Returns true if there are no builds or post-build (analysis) tasks pending
373+
/// Returns `true` if there are no builds or post-build (analysis) tasks pending
374374
/// or in progress.
375375
fn analysis_ready(&self) -> bool {
376376
self.active_build_count.load(Ordering::SeqCst) == 0

0 commit comments

Comments
 (0)