aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src')
-rw-r--r--crates/libanalysis/src/imp.rs5
-rw-r--r--crates/libanalysis/src/lib.rs16
-rw-r--r--crates/libanalysis/src/roots.rs3
3 files changed, 18 insertions, 6 deletions
diff --git a/crates/libanalysis/src/imp.rs b/crates/libanalysis/src/imp.rs
index 3ea27947e..50855551e 100644
--- a/crates/libanalysis/src/imp.rs
+++ b/crates/libanalysis/src/imp.rs
@@ -57,9 +57,8 @@ impl AnalysisHostImpl {
57 } 57 }
58 self.data_mut().crate_graph = graph; 58 self.data_mut().crate_graph = graph;
59 } 59 }
60 pub fn add_library(&mut self, files: impl Iterator<Item=(FileId, String)>) { 60 pub fn add_library(&mut self, root: ReadonlySourceRoot) {
61 let libs = ReadonlySourceRoot::new(files); 61 self.data_mut().libs.push(Arc::new(root));
62 self.data_mut().libs.push(Arc::new(libs));
63 } 62 }
64 fn data_mut(&mut self) -> &mut WorldData { 63 fn data_mut(&mut self) -> &mut WorldData {
65 Arc::make_mut(&mut self.data) 64 Arc::make_mut(&mut self.data)
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs
index e9e0c51d5..a8152939b 100644
--- a/crates/libanalysis/src/lib.rs
+++ b/crates/libanalysis/src/lib.rs
@@ -68,8 +68,8 @@ impl AnalysisHost {
68 pub fn set_crate_graph(&mut self, graph: CrateGraph) { 68 pub fn set_crate_graph(&mut self, graph: CrateGraph) {
69 self.imp.set_crate_graph(graph) 69 self.imp.set_crate_graph(graph)
70 } 70 }
71 pub fn add_library(&mut self, files: impl Iterator<Item=(FileId, String)>) { 71 pub fn add_library(&mut self, data: LibraryData) {
72 self.imp.add_library(files) 72 self.imp.add_library(data.root)
73 } 73 }
74} 74}
75 75
@@ -216,3 +216,15 @@ impl Analysis {
216 self.imp.diagnostics(file_id) 216 self.imp.diagnostics(file_id)
217 } 217 }
218} 218}
219
220#[derive(Debug)]
221pub struct LibraryData {
222 root: roots::ReadonlySourceRoot
223}
224
225impl LibraryData {
226 pub fn prepare(files: Vec<(FileId, String)>) -> LibraryData {
227 let root = roots::ReadonlySourceRoot::new(files);
228 LibraryData { root }
229 }
230}
diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs
index a65668c9b..f1bc72e33 100644
--- a/crates/libanalysis/src/roots.rs
+++ b/crates/libanalysis/src/roots.rs
@@ -136,9 +136,10 @@ pub(crate) struct ReadonlySourceRoot {
136} 136}
137 137
138impl ReadonlySourceRoot { 138impl ReadonlySourceRoot {
139 pub fn new(files: impl Iterator<Item=(FileId, String)>) -> ReadonlySourceRoot { 139 pub fn new(files: Vec<(FileId, String)>) -> ReadonlySourceRoot {
140 let mut module_map = ModuleMap::new(); 140 let mut module_map = ModuleMap::new();
141 let file_map: HashMap<FileId, FileData> = files 141 let file_map: HashMap<FileId, FileData> = files
142 .into_iter()
142 .map(|(id, text)| { 143 .map(|(id, text)| {
143 module_map.update_file(id, ChangeKind::Insert); 144 module_map.update_file(id, ChangeKind::Insert);
144 (id, FileData::new(text)) 145 (id, FileData::new(text))