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 } ;
7
2
8
3
use home;
4
+ use log:: * ;
9
5
use racer;
10
6
use rls_analysis:: { Def , DefKind } ;
11
7
use rls_span:: { Column , Range , Row , Span , ZeroIndexed } ;
12
8
use rls_vfs:: { self as vfs, Vfs } ;
13
9
use rustfmt_nightly:: NewlineStyle ;
14
10
use serde_derive:: { Deserialize , Serialize } ;
15
11
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 ;
18
18
19
19
#[ derive( Debug , Deserialize , Serialize , PartialEq , Eq ) ]
20
20
pub struct Tooltip {
@@ -53,7 +53,7 @@ pub fn process_docs(docs: &str) -> String {
53
53
line. to_string ( )
54
54
} ;
55
55
56
- // Racer sometimes pulls out comment block headers from the standard library
56
+ // Racer sometimes pulls out comment block headers from the standard library.
57
57
let ignore_slashes = line. starts_with ( "////" ) ;
58
58
59
59
let maybe_attribute = trimmed. starts_with ( "#[" ) || trimmed. starts_with ( "#![" ) ;
@@ -114,7 +114,7 @@ pub fn extract_docs(
114
114
let attr_start = line. starts_with ( "#[" ) || line. starts_with ( "#![" ) ;
115
115
116
116
if attr_start && line. ends_with ( ']' ) && !hit_top {
117
- // Ignore single line attributes
117
+ // Ignore single- line attributes.
118
118
trace ! (
119
119
"extract_docs: ignoring single-line attribute, next_row: {:?}, up: {}" ,
120
120
next_row,
@@ -124,7 +124,7 @@ pub fn extract_docs(
124
124
}
125
125
126
126
// Continue with the next line when transitioning out of a
127
- // multi-line attribute
127
+ // multi-line attribute.
128
128
if attr_start || ( line. ends_with ( ']' ) && !line. starts_with ( "//" ) ) {
129
129
in_meta = !in_meta;
130
130
if !in_meta && !hit_top {
@@ -138,7 +138,7 @@ pub fn extract_docs(
138
138
}
139
139
140
140
if !hit_top && in_meta {
141
- // Ignore milti-line attributes
141
+ // Ignore milti-line attributes.
142
142
trace ! (
143
143
"extract_docs: ignoring multi-line attribute, next_row: {:?}, up: {}, in_meta: {}" ,
144
144
next_row,
@@ -171,7 +171,7 @@ pub fn extract_docs(
171
171
}
172
172
173
173
if hit_top {
174
- // The top of the file was reached
174
+ // The top of the file was reached.
175
175
debug ! (
176
176
"extract_docs: bailing out: prev_row == next_row; next_row = {:?}, up = {}" ,
177
177
next_row, up
@@ -214,8 +214,7 @@ fn extract_and_process_docs(vfs: &Vfs, file: &Path, row_start: Row<ZeroIndexed>)
214
214
. and_then ( empty_to_none)
215
215
}
216
216
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.
219
218
pub fn extract_decl (
220
219
vfs : & Vfs ,
221
220
file : & Path ,
@@ -318,10 +317,10 @@ fn tooltip_struct_enum_union_trait(
318
317
319
318
let vfs = ctx. vfs . clone ( ) ;
320
319
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.
322
321
let fmt = Rustfmt :: Internal ;
323
322
324
- // fallback in case source extration fails
323
+ // Fallback in case source extration fails.
325
324
let the_type = || match def. kind {
326
325
DefKind :: Struct => format ! ( "struct {}" , def. name) ,
327
326
DefKind :: Enum => format ! ( "enum {}" , def. name) ,
@@ -373,7 +372,7 @@ fn tooltip_function_method(
373
372
374
373
let vfs = ctx. vfs . clone ( ) ;
375
374
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.
377
376
let fmt = Rustfmt :: Internal ;
378
377
379
378
let the_type = || {
@@ -461,7 +460,7 @@ fn empty_to_none(s: String) -> Option<String> {
461
460
}
462
461
}
463
462
464
- /// Extract and process source documentation for the give `def`.
463
+ /// Extracts and processes source documentation for the give `def`.
465
464
fn def_docs ( def : & Def , vfs : & Vfs ) -> Option < String > {
466
465
let save_analysis_docs = || empty_to_none ( def. docs . trim ( ) . into ( ) ) ;
467
466
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>>(
545
544
} )
546
545
}
547
546
548
- /// Collapse parent directory references inside of paths.
547
+ /// Collapses parent directory references inside of paths.
549
548
///
550
549
/// # Example
551
550
///
@@ -626,12 +625,12 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
626
625
let contextstr_path = PathBuf :: from ( & contextstr) ;
627
626
let contextstr_path = collapse_parents ( contextstr_path) ;
628
627
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`.
631
630
skip_path_components ( & contextstr_path, rustup_home, 7 )
632
- // Skips /registry/src/github.com-1ecc6299db9ec823/
631
+ // Skips ` /registry/src/github.com-1ecc6299db9ec823/`.
633
632
. 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.
635
634
. or_else ( || {
636
635
contextstr_path. strip_prefix ( & ctx. current_project ) . ok ( ) . map ( |x| x. to_owned ( ) )
637
636
} )
@@ -682,7 +681,7 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
682
681
} )
683
682
}
684
683
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
686
685
/// match is found with coordinates, `None` is returned.
687
686
fn racer_def ( ctx : & InitActionContext , span : & Span < ZeroIndexed > ) -> Option < Def > {
688
687
let vfs = ctx. vfs . clone ( ) ;
@@ -711,7 +710,7 @@ fn racer_def(ctx: &InitActionContext, span: &Span<ZeroIndexed>) -> Option<Def> {
711
710
let racer_match = racer:: find_definition ( file_path, location, & session) ;
712
711
trace ! ( "racer_def: match: {:?}" , racer_match) ;
713
712
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.
715
714
. filter ( |m| name. as_ref ( ) . map ( |name| name != & m. contextstr ) . unwrap_or ( true ) )
716
715
. and_then ( |m| racer_match_to_def ( ctx, & m) )
717
716
} ) ;
@@ -731,7 +730,7 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
731
730
config. set ( ) . newline_style ( NewlineStyle :: Unix ) ;
732
731
let trimmed = the_type. trim ( ) ;
733
732
734
- // Normalize the ending for rustfmt
733
+ // Normalize the ending for rustfmt.
735
734
let object = if trimmed. ends_with ( ')' ) {
736
735
format ! ( "{};" , trimmed)
737
736
} else if trimmed. ends_with ( '}' ) || trimmed. ends_with ( ';' ) {
@@ -755,7 +754,7 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
755
754
} ;
756
755
757
756
// If it's a tuple, remove the trailing ';' and hide non-pub components
758
- // for pub types
757
+ // for pub types.
759
758
let result = if formatted. trim ( ) . ends_with ( ';' ) {
760
759
let mut decl = formatted. trim ( ) . trim_end_matches ( ';' ) ;
761
760
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) ->
779
778
decl. to_string ( )
780
779
}
781
780
} else {
782
- // not a tuple
781
+ // Not a tuple.
783
782
decl. into ( )
784
783
}
785
784
} else {
786
- // not a tuple or unit struct
785
+ // Not a tuple or unit struct.
787
786
formatted
788
787
} ;
789
788
@@ -855,8 +854,7 @@ pub fn tooltip(
855
854
856
855
let racer_fallback_enabled = ctx. config . lock ( ) . unwrap ( ) . racer_completion ;
857
856
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.
860
858
let hover_span_def = hover_span_def. or_else ( |e| {
861
859
debug ! ( "tooltip: racer_fallback_enabled: {}" , racer_fallback_enabled) ;
862
860
if racer_fallback_enabled {
0 commit comments