aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/libanalysis/Cargo.toml2
-rw-r--r--crates/libanalysis/src/roots.rs23
2 files changed, 11 insertions, 14 deletions
diff --git a/crates/libanalysis/Cargo.toml b/crates/libanalysis/Cargo.toml
index 9c7977e92..4d565e95f 100644
--- a/crates/libanalysis/Cargo.toml
+++ b/crates/libanalysis/Cargo.toml
@@ -8,7 +8,7 @@ relative-path = "0.3.7"
8log = "0.4.2" 8log = "0.4.2"
9crossbeam-channel = "0.2.4" 9crossbeam-channel = "0.2.4"
10parking_lot = "0.6.3" 10parking_lot = "0.6.3"
11once_cell = "0.1.4" 11once_cell = "0.1.5"
12rayon = "1.0.2" 12rayon = "1.0.2"
13fst = "0.3.1" 13fst = "0.3.1"
14libsyntax2 = { path = "../libsyntax2" } 14libsyntax2 = { path = "../libsyntax2" }
diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs
index 675bce54c..eb14e7567 100644
--- a/crates/libanalysis/src/roots.rs
+++ b/crates/libanalysis/src/roots.rs
@@ -18,7 +18,7 @@ use {
18 18
19#[derive(Clone, Default, Debug)] 19#[derive(Clone, Default, Debug)]
20pub(crate) struct SourceRoot { 20pub(crate) struct SourceRoot {
21 file_map: HashMap<FileId, Arc<FileData>>, 21 file_map: HashMap<FileId, Arc<(FileData, OnceCell<FileSymbols>)>>,
22 module_map: ModuleMap, 22 module_map: ModuleMap,
23} 23}
24 24
@@ -37,9 +37,7 @@ impl SourceRoot {
37 self.file_map.remove(&file_id); 37 self.file_map.remove(&file_id);
38 if let Some(text) = text { 38 if let Some(text) = text {
39 let file_data = FileData::new(text); 39 let file_data = FileData::new(text);
40 self.file_map.insert(file_id, Arc::new(file_data)); 40 self.file_map.insert(file_id, Arc::new((file_data, Default::default())));
41 } else {
42 self.file_map.remove(&file_id);
43 } 41 }
44 } 42 }
45 pub fn module_map(&self) -> &ModuleMap { 43 pub fn module_map(&self) -> &ModuleMap {
@@ -64,7 +62,7 @@ impl SourceRoot {
64 pub(crate) fn symbols(&self) -> Vec<(FileId, &FileSymbols)> { 62 pub(crate) fn symbols(&self) -> Vec<(FileId, &FileSymbols)> {
65 self.file_map 63 self.file_map
66 .iter() 64 .iter()
67 .map(|(&file_id, data)| (file_id, data.symbols())) 65 .map(|(&file_id, data)| (file_id, symbols(data)))
68 .collect() 66 .collect()
69 } 67 }
70 pub fn reindex(&self) { 68 pub fn reindex(&self) {
@@ -72,32 +70,35 @@ impl SourceRoot {
72 self.file_map 70 self.file_map
73 .par_iter() 71 .par_iter()
74 .for_each(|(_, data)| { 72 .for_each(|(_, data)| {
75 data.symbols(); 73 symbols(data);
76 }); 74 });
77 info!("parallel indexing took {:?}", now.elapsed()); 75 info!("parallel indexing took {:?}", now.elapsed());
78 76
79 } 77 }
80 fn data(&self, file_id: FileId) -> &FileData { 78 fn data(&self, file_id: FileId) -> &FileData {
81 match self.file_map.get(&file_id) { 79 match self.file_map.get(&file_id) {
82 Some(data) => data, 80 Some(data) => &data.0,
83 None => panic!("unknown file: {:?}", file_id), 81 None => panic!("unknown file: {:?}", file_id),
84 } 82 }
85 } 83 }
86} 84}
87 85
86fn symbols((data, symbols): &(FileData, OnceCell<FileSymbols>)) -> &FileSymbols {
87 let syntax = data.syntax_transient();
88 symbols.get_or_init(|| FileSymbols::new(&syntax))
89}
90
88#[derive(Debug)] 91#[derive(Debug)]
89struct FileData { 92struct FileData {
90 text: String, 93 text: String,
91 lines: OnceCell<LineIndex>, 94 lines: OnceCell<LineIndex>,
92 syntax: OnceCell<File>, 95 syntax: OnceCell<File>,
93 symbols: OnceCell<FileSymbols>,
94} 96}
95 97
96impl FileData { 98impl FileData {
97 fn new(text: String) -> FileData { 99 fn new(text: String) -> FileData {
98 FileData { 100 FileData {
99 text, 101 text,
100 symbols: OnceCell::new(),
101 syntax: OnceCell::new(), 102 syntax: OnceCell::new(),
102 lines: OnceCell::new(), 103 lines: OnceCell::new(),
103 } 104 }
@@ -106,8 +107,4 @@ impl FileData {
106 self.syntax.get().map(|s| s.clone()) 107 self.syntax.get().map(|s| s.clone())
107 .unwrap_or_else(|| File::parse(&self.text)) 108 .unwrap_or_else(|| File::parse(&self.text))
108 } 109 }
109 fn symbols(&self) -> &FileSymbols {
110 let syntax = self.syntax_transient();
111 self.symbols.get_or_init(|| FileSymbols::new(&syntax))
112 }
113} 110}