@@ -54,17 +54,24 @@ pub fn format_symbol_with(symbol: Symbol, options: SymbolFormatOptions) -> Strin
54
54
parts. push ( scheme) ;
55
55
}
56
56
57
- if let Some ( package) = package {
58
- if options. include_package_manager && !package. manager . is_empty ( ) {
59
- parts. push ( package. manager ) ;
57
+ if options. include_package_manager {
58
+ match & package {
59
+ Some ( package) if !package. manager . is_empty ( ) => parts. push ( package. manager . clone ( ) ) ,
60
+ _ => parts. push ( "." . to_string ( ) ) ,
60
61
}
62
+ }
61
63
62
- if options. include_package_name && !package. name . is_empty ( ) {
63
- parts. push ( package. name ) ;
64
+ if options. include_package_name {
65
+ match & package {
66
+ Some ( package) if !package. name . is_empty ( ) => parts. push ( package. name . clone ( ) ) ,
67
+ _ => parts. push ( "." . to_string ( ) ) ,
64
68
}
69
+ }
65
70
66
- if options. include_package_version && !package. version . is_empty ( ) {
67
- parts. push ( package. version ) ;
71
+ if options. include_package_version {
72
+ match & package {
73
+ Some ( package) if !package. version . is_empty ( ) => parts. push ( package. version . clone ( ) ) ,
74
+ _ => parts. push ( "." . to_string ( ) ) ,
68
75
}
69
76
}
70
77
@@ -136,7 +143,7 @@ pub fn parse_symbol(symbol: &str) -> Result<Symbol, SymbolError> {
136
143
Ok ( Symbol {
137
144
scheme,
138
145
package : protobuf:: MessageField :: some ( crate :: types:: Package {
139
- manager : parser. accept_space_escaped_identifier ( "package.manager" ) ?,
146
+ manager : dot ( parser. accept_space_escaped_identifier ( "package.manager" ) ?) ,
140
147
name : dot ( parser. accept_space_escaped_identifier ( "package.name" ) ?) ,
141
148
version : dot ( parser. accept_space_escaped_identifier ( "package.version" ) ?) ,
142
149
special_fields : SpecialFields :: default ( ) ,
@@ -483,4 +490,38 @@ mod test {
483
490
format_symbol( parse_symbol( input_symbol) . expect( "rust symbol" ) )
484
491
)
485
492
}
493
+
494
+ #[ test]
495
+ fn formats_symbol_with_dots ( ) {
496
+ assert_eq ! (
497
+ "scip-ctags . . . foo." ,
498
+ format_symbol( Symbol {
499
+ scheme: "scip-ctags" . to_string( ) ,
500
+ package: None . into( ) ,
501
+ descriptors: vec![ new_descriptor( "foo" . to_string( ) , descriptor:: Suffix :: Term ) ] ,
502
+ ..Default :: default ( )
503
+ } )
504
+ ) ;
505
+
506
+ // Handles randomly some are empty and some are dots
507
+ assert_eq ! (
508
+ "scip-ctags manager . . MyType#foo." ,
509
+ format_symbol( Symbol {
510
+ scheme: "scip-ctags" . to_string( ) ,
511
+ package: Some ( Package {
512
+ manager: "manager" . to_string( ) ,
513
+ name: "." . to_string( ) ,
514
+ version: "" . to_string( ) ,
515
+ ..Default :: default ( )
516
+ } )
517
+ . into( ) ,
518
+
519
+ descriptors: vec![
520
+ new_descriptor( "MyType" . to_string( ) , descriptor:: Suffix :: Type ) ,
521
+ new_descriptor( "foo" . to_string( ) , descriptor:: Suffix :: Term )
522
+ ] ,
523
+ ..Default :: default ( )
524
+ } )
525
+ ) ;
526
+ }
486
527
}
0 commit comments