diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 9 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 11 |
2 files changed, 15 insertions, 5 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index a67b1717a..3a135ef13 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem}, | 20 | descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem}, |
21 | roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, | 21 | roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, |
22 | CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position, | 22 | CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position, |
23 | Query, SourceChange, SourceFileEdit, | 23 | Query, SourceChange, SourceFileEdit, Cancelable, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | #[derive(Clone, Debug)] | 26 | #[derive(Clone, Debug)] |
@@ -157,10 +157,10 @@ impl AnalysisImpl { | |||
157 | } | 157 | } |
158 | query.search(&buf, token) | 158 | query.search(&buf, token) |
159 | } | 159 | } |
160 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { | 160 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
161 | let root = self.root(file_id); | 161 | let root = self.root(file_id); |
162 | let module_tree = root.module_tree(); | 162 | let module_tree = root.module_tree(); |
163 | module_tree | 163 | let res = module_tree |
164 | .parent_modules(file_id) | 164 | .parent_modules(file_id) |
165 | .iter() | 165 | .iter() |
166 | .map(|link| { | 166 | .map(|link| { |
@@ -174,7 +174,8 @@ impl AnalysisImpl { | |||
174 | }; | 174 | }; |
175 | (file_id, sym) | 175 | (file_id, sym) |
176 | }) | 176 | }) |
177 | .collect() | 177 | .collect(); |
178 | Ok(res) | ||
178 | } | 179 | } |
179 | pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { | 180 | pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { |
180 | let module_tree = self.root(file_id).module_tree(); | 181 | let module_tree = self.root(file_id).module_tree(); |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index b1d5c4936..988a45b46 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -42,6 +42,15 @@ pub struct Cancel; | |||
42 | 42 | ||
43 | pub type Cancelable<T> = Result<T, Cancel>; | 43 | pub type Cancelable<T> = Result<T, Cancel>; |
44 | 44 | ||
45 | impl std::fmt::Display for Cancel { | ||
46 | fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
47 | fmt.write_str("Canceled") | ||
48 | } | ||
49 | } | ||
50 | |||
51 | impl std::error::Error for Cancel { | ||
52 | } | ||
53 | |||
45 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 54 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
46 | pub struct FileId(pub u32); | 55 | pub struct FileId(pub u32); |
47 | 56 | ||
@@ -225,7 +234,7 @@ impl Analysis { | |||
225 | 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, token: &JobToken) -> Vec<(FileId, TextRange)> { |
226 | self.imp.find_all_refs(file_id, offset, token) | 235 | self.imp.find_all_refs(file_id, offset, token) |
227 | } | 236 | } |
228 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { | 237 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
229 | self.imp.parent_module(file_id) | 238 | self.imp.parent_module(file_id) |
230 | } | 239 | } |
231 | pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { | 240 | pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { |