diff options
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 46cc0722b..28e0a12b2 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -7,8 +7,6 @@ extern crate ra_editor; | |||
7 | extern crate ra_syntax; | 7 | extern crate ra_syntax; |
8 | extern crate rayon; | 8 | extern crate rayon; |
9 | extern crate relative_path; | 9 | extern crate relative_path; |
10 | #[macro_use] | ||
11 | extern crate crossbeam_channel; | ||
12 | extern crate im; | 10 | extern crate im; |
13 | extern crate rustc_hash; | 11 | extern crate rustc_hash; |
14 | extern crate salsa; | 12 | extern crate salsa; |
@@ -16,27 +14,40 @@ extern crate salsa; | |||
16 | mod db; | 14 | mod db; |
17 | mod descriptors; | 15 | mod descriptors; |
18 | mod imp; | 16 | mod imp; |
19 | mod job; | ||
20 | mod module_map; | 17 | mod module_map; |
21 | mod roots; | 18 | mod roots; |
22 | mod symbol_index; | 19 | mod symbol_index; |
23 | 20 | ||
24 | use std::{fmt::Debug, sync::Arc}; | 21 | use std::{fmt::Debug, sync::Arc}; |
25 | 22 | ||
26 | use crate::imp::{AnalysisHostImpl, AnalysisImpl, FileResolverImp}; | ||
27 | use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; | 23 | use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; |
28 | use relative_path::{RelativePath, RelativePathBuf}; | 24 | use relative_path::{RelativePath, RelativePathBuf}; |
29 | use rustc_hash::FxHashMap; | 25 | use rustc_hash::FxHashMap; |
30 | 26 | ||
27 | use crate::imp::{AnalysisHostImpl, AnalysisImpl, FileResolverImp}; | ||
28 | |||
31 | pub use crate::{ | 29 | pub use crate::{ |
32 | descriptors::FnDescriptor, | 30 | descriptors::FnDescriptor, |
33 | job::{JobHandle, JobToken}, | ||
34 | }; | 31 | }; |
35 | pub use ra_editor::{ | 32 | pub use ra_editor::{ |
36 | CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, | 33 | CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, |
37 | RunnableKind, StructureNode, | 34 | RunnableKind, StructureNode, |
38 | }; | 35 | }; |
39 | 36 | ||
37 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
38 | pub struct Canceled; | ||
39 | |||
40 | pub type Cancelable<T> = Result<T, Canceled>; | ||
41 | |||
42 | impl std::fmt::Display for Canceled { | ||
43 | fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
44 | fmt.write_str("Canceled") | ||
45 | } | ||
46 | } | ||
47 | |||
48 | impl std::error::Error for Canceled { | ||
49 | } | ||
50 | |||
40 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 51 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
41 | pub struct FileId(pub u32); | 52 | pub struct FileId(pub u32); |
42 | 53 | ||
@@ -205,60 +216,57 @@ impl Analysis { | |||
205 | let file = self.imp.file_syntax(file_id); | 216 | let file = self.imp.file_syntax(file_id); |
206 | ra_editor::file_structure(&file) | 217 | ra_editor::file_structure(&file) |
207 | } | 218 | } |
208 | pub fn symbol_search(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> { | 219 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { |
209 | self.imp.world_symbols(query, token) | 220 | let file = self.imp.file_syntax(file_id); |
221 | ra_editor::folding_ranges(&file) | ||
222 | } | ||
223 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { | ||
224 | self.imp.world_symbols(query) | ||
210 | } | 225 | } |
211 | pub fn approximately_resolve_symbol( | 226 | pub fn approximately_resolve_symbol( |
212 | &self, | 227 | &self, |
213 | file_id: FileId, | 228 | file_id: FileId, |
214 | offset: TextUnit, | 229 | offset: TextUnit |
215 | token: &JobToken, | 230 | ) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
216 | ) -> Vec<(FileId, FileSymbol)> { | ||
217 | self.imp | 231 | self.imp |
218 | .approximately_resolve_symbol(file_id, offset, token) | 232 | .approximately_resolve_symbol(file_id, offset) |
219 | } | 233 | } |
220 | pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, TextRange)> { | 234 | pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Cancelable<Vec<(FileId, TextRange)>> { |
221 | self.imp.find_all_refs(file_id, offset, token) | 235 | Ok(self.imp.find_all_refs(file_id, offset)) |
222 | } | 236 | } |
223 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { | 237 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
224 | self.imp.parent_module(file_id) | 238 | self.imp.parent_module(file_id) |
225 | } | 239 | } |
226 | pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { | 240 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
227 | self.imp.crate_for(file_id) | 241 | self.imp.crate_for(file_id) |
228 | } | 242 | } |
229 | pub fn crate_root(&self, crate_id: CrateId) -> FileId { | 243 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { |
230 | self.imp.crate_root(crate_id) | 244 | Ok(self.imp.crate_root(crate_id)) |
231 | } | 245 | } |
232 | pub fn runnables(&self, file_id: FileId) -> Vec<Runnable> { | 246 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { |
233 | let file = self.imp.file_syntax(file_id); | 247 | let file = self.imp.file_syntax(file_id); |
234 | ra_editor::runnables(&file) | 248 | Ok(ra_editor::runnables(&file)) |
235 | } | 249 | } |
236 | pub fn highlight(&self, file_id: FileId) -> Vec<HighlightedRange> { | 250 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
237 | let file = self.imp.file_syntax(file_id); | 251 | let file = self.imp.file_syntax(file_id); |
238 | ra_editor::highlight(&file) | 252 | Ok(ra_editor::highlight(&file)) |
239 | } | 253 | } |
240 | pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Option<Vec<CompletionItem>> { | 254 | pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Cancelable<Option<Vec<CompletionItem>>> { |
241 | let file = self.imp.file_syntax(file_id); | 255 | let file = self.imp.file_syntax(file_id); |
242 | ra_editor::scope_completion(&file, offset) | 256 | Ok(ra_editor::scope_completion(&file, offset)) |
243 | } | 257 | } |
244 | pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec<SourceChange> { | 258 | pub fn assists(&self, file_id: FileId, range: TextRange) -> Cancelable<Vec<SourceChange>> { |
245 | self.imp.assists(file_id, range) | 259 | Ok(self.imp.assists(file_id, range)) |
246 | } | 260 | } |
247 | pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { | 261 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
248 | self.imp.diagnostics(file_id) | 262 | self.imp.diagnostics(file_id) |
249 | } | 263 | } |
250 | pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { | ||
251 | let file = self.imp.file_syntax(file_id); | ||
252 | ra_editor::folding_ranges(&file) | ||
253 | } | ||
254 | |||
255 | pub fn resolve_callable( | 264 | pub fn resolve_callable( |
256 | &self, | 265 | &self, |
257 | file_id: FileId, | 266 | file_id: FileId, |
258 | offset: TextUnit, | 267 | offset: TextUnit, |
259 | token: &JobToken, | 268 | ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { |
260 | ) -> Option<(FnDescriptor, Option<usize>)> { | 269 | self.imp.resolve_callable(file_id, offset) |
261 | self.imp.resolve_callable(file_id, offset, token) | ||
262 | } | 270 | } |
263 | } | 271 | } |
264 | 272 | ||