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.rs19
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;
15mod imp; 15mod imp;
16mod job; 16mod job;
17 17
18use std::sync::Arc; 18use std::{
19 sync::Arc,
20 collections::HashMap,
21};
19 22
20use relative_path::{RelativePath, RelativePathBuf}; 23use relative_path::{RelativePath, RelativePathBuf};
21use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; 24use 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)]
31pub struct FileId(pub u32); 34pub struct FileId(pub u32);
32 35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
37pub struct CrateId(pub u32);
38
39#[derive(Debug, Clone, Default)]
40pub struct CrateGraph {
41 pub crate_roots: HashMap<CrateId, FileId>,
42}
43
33pub trait FileResolver: Send + Sync + 'static { 44pub 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)