diff options
Diffstat (limited to 'crates/libanalysis/src/api.rs')
-rw-r--r-- | crates/libanalysis/src/api.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/crates/libanalysis/src/api.rs b/crates/libanalysis/src/api.rs index 02eaf7b1c..ded88cd15 100644 --- a/crates/libanalysis/src/api.rs +++ b/crates/libanalysis/src/api.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use relative_path::RelativePathBuf; | 1 | use relative_path::{RelativePath, RelativePathBuf}; |
2 | use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; | 2 | use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; |
3 | use libeditor; | 3 | use libeditor; |
4 | use {imp::AnalysisImpl, FileId, Query}; | 4 | use {imp::{AnalysisImpl, AnalysisHostImpl}, Query}; |
5 | 5 | ||
6 | pub use libeditor::{ | 6 | pub use libeditor::{ |
7 | LocalEdit, StructureNode, LineIndex, FileSymbol, | 7 | LocalEdit, StructureNode, LineIndex, FileSymbol, |
@@ -109,3 +109,34 @@ impl Analysis { | |||
109 | self.imp.diagnostics(file_id) | 109 | self.imp.diagnostics(file_id) |
110 | } | 110 | } |
111 | } | 111 | } |
112 | |||
113 | pub trait FileResolver: Send + Sync + 'static { | ||
114 | fn file_stem(&self, id: FileId) -> String; | ||
115 | fn resolve(&self, id: FileId, path: &RelativePath) -> Option<FileId>; | ||
116 | } | ||
117 | |||
118 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
119 | pub struct FileId(pub u32); | ||
120 | |||
121 | #[derive(Debug)] | ||
122 | pub struct AnalysisHost { | ||
123 | pub(crate) imp: AnalysisHostImpl | ||
124 | } | ||
125 | |||
126 | impl AnalysisHost { | ||
127 | pub fn new() -> AnalysisHost { | ||
128 | AnalysisHost { imp: AnalysisHostImpl::new() } | ||
129 | } | ||
130 | |||
131 | pub fn analysis(&self, file_resolver: impl FileResolver) -> Analysis { | ||
132 | Analysis { imp: self.imp.analysis(file_resolver) } | ||
133 | } | ||
134 | |||
135 | pub fn change_file(&mut self, file_id: FileId, text: Option<String>) { | ||
136 | self.change_files(::std::iter::once((file_id, text))); | ||
137 | } | ||
138 | |||
139 | pub fn change_files(&mut self, changes: impl Iterator<Item=(FileId, Option<String>)>) { | ||
140 | self.imp.change_files(changes) | ||
141 | } | ||
142 | } | ||