diff options
author | Aleksey Kladov <[email protected]> | 2018-10-20 19:52:49 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-20 19:52:49 +0100 |
commit | c4b0d3cd56ab68f4fa23f7c1f6c76f7f6148153e (patch) | |
tree | 90b7472979686314ca041dfe5ee7f95277827f9d | |
parent | 61518580ed60bb16edcd4fb7200d0b564b5ee9e9 (diff) |
make parent module cancelable
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 9 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 11 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 2 |
3 files changed, 16 insertions, 6 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> { |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 639fe4553..b0b983d0c 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -238,7 +238,7 @@ pub fn handle_parent_module( | |||
238 | ) -> Result<Vec<Location>> { | 238 | ) -> Result<Vec<Location>> { |
239 | let file_id = params.try_conv_with(&world)?; | 239 | let file_id = params.try_conv_with(&world)?; |
240 | let mut res = Vec::new(); | 240 | let mut res = Vec::new(); |
241 | for (file_id, symbol) in world.analysis().parent_module(file_id) { | 241 | for (file_id, symbol) in world.analysis().parent_module(file_id)? { |
242 | let line_index = world.analysis().file_line_index(file_id); | 242 | let line_index = world.analysis().file_line_index(file_id); |
243 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; | 243 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; |
244 | res.push(location); | 244 | res.push(location); |