File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,10 @@ impl FileSetConfig {
132
132
///
133
133
/// `scratch_space` is used as a buffer and will be entirely replaced.
134
134
fn classify ( & self , path : & VfsPath , scratch_space : & mut Vec < u8 > ) -> usize {
135
+ // `path` is a file, but r-a only cares about the containing directory. We don't
136
+ // want `/foo/bar_baz.rs` to be attributed to source root directory `/foo/bar`.
137
+ let path = path. parent ( ) . unwrap_or_else ( || path. clone ( ) ) ;
138
+
135
139
scratch_space. clear ( ) ;
136
140
path. encode ( scratch_space) ;
137
141
let automaton = PrefixOf :: new ( scratch_space. as_slice ( ) ) ;
Original file line number Diff line number Diff line change @@ -40,3 +40,26 @@ fn name_prefix() {
40
40
let partition = file_set. partition ( & vfs) . into_iter ( ) . map ( |it| it. len ( ) ) . collect :: < Vec < _ > > ( ) ;
41
41
assert_eq ! ( partition, vec![ 1 , 1 , 0 ] ) ;
42
42
}
43
+
44
+ /// Ensure that we don't consider `/foo/bar_baz.rs` to be in the
45
+ /// `/foo/bar/` root.
46
+ #[ test]
47
+ fn name_prefix_partially_matches ( ) {
48
+ let mut file_set = FileSetConfig :: builder ( ) ;
49
+ file_set. add_file_set ( vec ! [ VfsPath :: new_virtual_path( "/foo" . into( ) ) ] ) ;
50
+ file_set. add_file_set ( vec ! [ VfsPath :: new_virtual_path( "/foo/bar" . into( ) ) ] ) ;
51
+ let file_set = file_set. build ( ) ;
52
+
53
+ let mut vfs = Vfs :: default ( ) ;
54
+
55
+ // These two are both in /foo.
56
+ vfs. set_file_contents ( VfsPath :: new_virtual_path ( "/foo/lib.rs" . into ( ) ) , Some ( Vec :: new ( ) ) ) ;
57
+ vfs. set_file_contents ( VfsPath :: new_virtual_path ( "/foo/bar_baz.rs" . into ( ) ) , Some ( Vec :: new ( ) ) ) ;
58
+
59
+ // Only this file is in /foo/bar.
60
+ vfs. set_file_contents ( VfsPath :: new_virtual_path ( "/foo/bar/biz.rs" . into ( ) ) , Some ( Vec :: new ( ) ) ) ;
61
+
62
+ let partition = file_set. partition ( & vfs) . into_iter ( ) . map ( |it| it. len ( ) ) . collect :: < Vec < _ > > ( ) ;
63
+
64
+ assert_eq ! ( partition, vec![ 2 , 1 , 0 ] ) ;
65
+ }
You can’t perform that action at this time.
0 commit comments