diff options
Diffstat (limited to 'crates/libanalysis/src/lib.rs')
-rw-r--r-- | crates/libanalysis/src/lib.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index a59fd1c09..041abbb89 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -15,7 +15,10 @@ mod module_map; | |||
15 | mod imp; | 15 | mod imp; |
16 | mod job; | 16 | mod job; |
17 | 17 | ||
18 | use std::sync::Arc; | 18 | use std::{ |
19 | sync::Arc, | ||
20 | collections::HashMap, | ||
21 | }; | ||
19 | 22 | ||
20 | use relative_path::{RelativePath, RelativePathBuf}; | 23 | use relative_path::{RelativePath, RelativePathBuf}; |
21 | use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; | 24 | use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; |
@@ -30,6 +33,14 @@ pub use job::{JobToken, JobHandle}; | |||
30 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 33 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
31 | pub struct FileId(pub u32); | 34 | pub struct FileId(pub u32); |
32 | 35 | ||
36 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
37 | pub struct CrateId(pub u32); | ||
38 | |||
39 | #[derive(Debug, Clone, Default)] | ||
40 | pub struct CrateGraph { | ||
41 | pub crate_roots: HashMap<CrateId, FileId>, | ||
42 | } | ||
43 | |||
33 | pub trait FileResolver: Send + Sync + 'static { | 44 | pub trait FileResolver: Send + Sync + 'static { |
34 | fn file_stem(&self, id: FileId) -> String; | 45 | fn file_stem(&self, id: FileId) -> String; |
35 | fn resolve(&self, id: FileId, path: &RelativePath) -> Option<FileId>; | 46 | fn resolve(&self, id: FileId, path: &RelativePath) -> Option<FileId>; |
@@ -53,6 +64,9 @@ impl AnalysisHost { | |||
53 | pub fn change_files(&mut self, mut changes: impl Iterator<Item=(FileId, Option<String>)>) { | 64 | pub fn change_files(&mut self, mut changes: impl Iterator<Item=(FileId, Option<String>)>) { |
54 | self.imp.change_files(&mut changes) | 65 | self.imp.change_files(&mut changes) |
55 | } | 66 | } |
67 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { | ||
68 | self.imp.set_crate_graph(graph) | ||
69 | } | ||
56 | } | 70 | } |
57 | 71 | ||
58 | #[derive(Debug)] | 72 | #[derive(Debug)] |
@@ -168,6 +182,9 @@ impl Analysis { | |||
168 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { | 182 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { |
169 | self.imp.parent_module(file_id) | 183 | self.imp.parent_module(file_id) |
170 | } | 184 | } |
185 | pub fn crate_root(&self, file_id: FileId) -> Vec<CrateId> { | ||
186 | self.imp.crate_root(file_id) | ||
187 | } | ||
171 | pub fn runnables(&self, file_id: FileId) -> Vec<Runnable> { | 188 | pub fn runnables(&self, file_id: FileId) -> Vec<Runnable> { |
172 | let file = self.file_syntax(file_id); | 189 | let file = self.file_syntax(file_id); |
173 | libeditor::runnables(&file) | 190 | libeditor::runnables(&file) |