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
83use home;
4+ use log:: * ;
95use racer;
106use rls_analysis:: { Def , DefKind } ;
117use rls_span:: { Column , Range , Row , Span , ZeroIndexed } ;
128use rls_vfs:: { self as vfs, Vfs } ;
139use rustfmt_nightly:: NewlineStyle ;
1410use 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 ) ]
2020pub 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.
219218pub 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`.
465464fn 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.
687686fn 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 {
0 commit comments