@@ -6,7 +6,7 @@ use include_dir::Dir;
6
6
use indexmap:: indexmap;
7
7
use indexmap:: IndexMap ;
8
8
use smol_str:: SmolStr ;
9
- use std:: collections:: HashMap ;
9
+ use std:: collections:: BTreeMap ;
10
10
use std:: ops:: Range ;
11
11
use std:: path:: Path ;
12
12
use std:: { fs, io} ;
@@ -24,7 +24,10 @@ pub struct SourceFileId(pub u128);
24
24
25
25
impl SourceFile {
26
26
pub fn new ( name : & str , content : & str ) -> Self {
27
- let hash = keccak:: full_as_bytes ( content. as_bytes ( ) ) ;
27
+ // Canonicalize new line character for Windows.
28
+ let content_canonicalized = content. replace ( "\r \n " , "\n " ) ;
29
+ let hash = keccak:: full_as_bytes ( content_canonicalized. as_bytes ( ) ) ;
30
+
28
31
let line_starts = cs:: files:: line_starts ( content) . collect ( ) ;
29
32
Self {
30
33
id : SourceFileId ( u128:: from_be_bytes ( hash[ ..16 ] . try_into ( ) . unwrap ( ) ) ) ,
@@ -63,21 +66,21 @@ impl FileLoader for OsFileLoader {
63
66
}
64
67
65
68
pub struct FileStore {
66
- pub files : HashMap < SourceFileId , SourceFile > ,
69
+ pub files : BTreeMap < SourceFileId , SourceFile > ,
67
70
loader : Box < dyn FileLoader > ,
68
71
}
69
72
70
73
impl FileStore {
71
74
pub fn new ( ) -> Self {
72
75
Self {
73
- files : HashMap :: new ( ) ,
76
+ files : BTreeMap :: new ( ) ,
74
77
loader : Box :: new ( OsFileLoader ) ,
75
78
}
76
79
}
77
80
78
81
pub fn with_loader ( loader : Box < dyn FileLoader > ) -> Self {
79
82
Self {
80
- files : HashMap :: new ( ) ,
83
+ files : BTreeMap :: new ( ) ,
81
84
loader,
82
85
}
83
86
}
0 commit comments