aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/lib.rs')
-rw-r--r--crates/libanalysis/src/lib.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs
index ff4fc709b..80cde079f 100644
--- a/crates/libanalysis/src/lib.rs
+++ b/crates/libanalysis/src/lib.rs
@@ -19,11 +19,12 @@ mod roots;
19use std::{ 19use std::{
20 sync::Arc, 20 sync::Arc,
21 collections::HashMap, 21 collections::HashMap,
22 fmt::Debug,
22}; 23};
23 24
24use relative_path::{RelativePath, RelativePathBuf}; 25use relative_path::{RelativePath, RelativePathBuf};
25use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; 26use libsyntax2::{File, TextRange, TextUnit, AtomEdit};
26use imp::{AnalysisImpl, AnalysisHostImpl}; 27use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp};
27 28
28pub use libeditor::{ 29pub use libeditor::{
29 StructureNode, LineIndex, FileSymbol, 30 StructureNode, LineIndex, FileSymbol,
@@ -42,9 +43,9 @@ pub struct CrateGraph {
42 pub crate_roots: HashMap<CrateId, FileId>, 43 pub crate_roots: HashMap<CrateId, FileId>,
43} 44}
44 45
45pub trait FileResolver: Send + Sync + 'static { 46pub trait FileResolver: Debug + Send + Sync + 'static {
46 fn file_stem(&self, id: FileId) -> String; 47 fn file_stem(&self, file_id: FileId) -> String;
47 fn resolve(&self, id: FileId, path: &RelativePath) -> Option<FileId>; 48 fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
48} 49}
49 50
50#[derive(Debug)] 51#[derive(Debug)]
@@ -56,8 +57,8 @@ impl AnalysisHost {
56 pub fn new() -> AnalysisHost { 57 pub fn new() -> AnalysisHost {
57 AnalysisHost { imp: AnalysisHostImpl::new() } 58 AnalysisHost { imp: AnalysisHostImpl::new() }
58 } 59 }
59 pub fn analysis(&self, file_resolver: impl FileResolver) -> Analysis { 60 pub fn analysis(&self) -> Analysis {
60 Analysis { imp: self.imp.analysis(Arc::new(file_resolver)) } 61 Analysis { imp: self.imp.analysis() }
61 } 62 }
62 pub fn change_file(&mut self, file_id: FileId, text: Option<String>) { 63 pub fn change_file(&mut self, file_id: FileId, text: Option<String>) {
63 self.change_files(::std::iter::once((file_id, text))); 64 self.change_files(::std::iter::once((file_id, text)));
@@ -65,6 +66,9 @@ impl AnalysisHost {
65 pub fn change_files(&mut self, mut changes: impl Iterator<Item=(FileId, Option<String>)>) { 66 pub fn change_files(&mut self, mut changes: impl Iterator<Item=(FileId, Option<String>)>) {
66 self.imp.change_files(&mut changes) 67 self.imp.change_files(&mut changes)
67 } 68 }
69 pub fn set_file_resolver(&mut self, resolver: Arc<FileResolver>) {
70 self.imp.set_file_resolver(FileResolverImp::new(resolver));
71 }
68 pub fn set_crate_graph(&mut self, graph: CrateGraph) { 72 pub fn set_crate_graph(&mut self, graph: CrateGraph) {
69 self.imp.set_crate_graph(graph) 73 self.imp.set_crate_graph(graph)
70 } 74 }
@@ -223,8 +227,9 @@ pub struct LibraryData {
223} 227}
224 228
225impl LibraryData { 229impl LibraryData {
226 pub fn prepare(files: Vec<(FileId, String)>) -> LibraryData { 230 pub fn prepare(files: Vec<(FileId, String)>, file_resolver: Arc<FileResolver>) -> LibraryData {
227 let root = roots::ReadonlySourceRoot::new(files); 231 let file_resolver = FileResolverImp::new(file_resolver);
232 let root = roots::ReadonlySourceRoot::new(files, file_resolver);
228 LibraryData { root } 233 LibraryData { root }
229 } 234 }
230} 235}