aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r--crates/ra_analysis/src/lib.rs76
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;
7extern crate ra_syntax; 7extern crate ra_syntax;
8extern crate rayon; 8extern crate rayon;
9extern crate relative_path; 9extern crate relative_path;
10#[macro_use]
11extern crate crossbeam_channel;
12extern crate im; 10extern crate im;
13extern crate rustc_hash; 11extern crate rustc_hash;
14extern crate salsa; 12extern crate salsa;
@@ -16,27 +14,40 @@ extern crate salsa;
16mod db; 14mod db;
17mod descriptors; 15mod descriptors;
18mod imp; 16mod imp;
19mod job;
20mod module_map; 17mod module_map;
21mod roots; 18mod roots;
22mod symbol_index; 19mod symbol_index;
23 20
24use std::{fmt::Debug, sync::Arc}; 21use std::{fmt::Debug, sync::Arc};
25 22
26use crate::imp::{AnalysisHostImpl, AnalysisImpl, FileResolverImp};
27use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; 23use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
28use relative_path::{RelativePath, RelativePathBuf}; 24use relative_path::{RelativePath, RelativePathBuf};
29use rustc_hash::FxHashMap; 25use rustc_hash::FxHashMap;
30 26
27use crate::imp::{AnalysisHostImpl, AnalysisImpl, FileResolverImp};
28
31pub use crate::{ 29pub use crate::{
32 descriptors::FnDescriptor, 30 descriptors::FnDescriptor,
33 job::{JobHandle, JobToken},
34}; 31};
35pub use ra_editor::{ 32pub 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)]
38pub struct Canceled;
39
40pub type Cancelable<T> = Result<T, Canceled>;
41
42impl 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
48impl 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)]
41pub struct FileId(pub u32); 52pub 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