aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-15 15:30:58 +0000
committerAleksey Kladov <[email protected]>2019-01-15 15:30:58 +0000
commitc159e414b42e2fd43ed88bbf4113fbe8c8e372fe (patch)
treef8035b08462e192462528c9f3942431162aa9068 /crates
parentca52cf1ecd4f65ff2a8c3953c35b006e73a60ea8 (diff)
remove Cancelable from Module API, part 2
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model_api.rs14
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs30
-rw-r--r--crates/ra_hir/src/ids.rs2
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs2
-rw-r--r--crates/ra_ide_api/src/imp.rs10
-rw-r--r--crates/ra_ide_api/src/lib.rs2
-rw-r--r--crates/ra_ide_api/src/runnables.rs1
7 files changed, 28 insertions, 33 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index aed0ea958..81638e384 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -97,14 +97,14 @@ impl Module {
97 } 97 }
98 98
99 /// Returns the crate this module is part of. 99 /// Returns the crate this module is part of.
100 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 100 pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
101 self.krate_impl(db) 101 self.krate_impl(db)
102 } 102 }
103 103
104 /// Topmost parent of this module. Every module has a `crate_root`, but some 104 /// Topmost parent of this module. Every module has a `crate_root`, but some
105 /// might be missing `krate`. This can happen if a module's file is not included 105 /// might be missing `krate`. This can happen if a module's file is not included
106 /// in the module tree of any target in Cargo.toml. 106 /// in the module tree of any target in Cargo.toml.
107 pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable<Module> { 107 pub fn crate_root(&self, db: &impl HirDatabase) -> Module {
108 self.crate_root_impl(db) 108 self.crate_root_impl(db)
109 } 109 }
110 110
@@ -114,23 +114,23 @@ impl Module {
114 } 114 }
115 115
116 /// Iterates over all child modules. 116 /// Iterates over all child modules.
117 pub fn children(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> { 117 pub fn children(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> {
118 self.children_impl(db) 118 self.children_impl(db)
119 } 119 }
120 120
121 /// Finds a parent module. 121 /// Finds a parent module.
122 pub fn parent(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 122 pub fn parent(&self, db: &impl HirDatabase) -> Option<Module> {
123 self.parent_impl(db) 123 self.parent_impl(db)
124 } 124 }
125 125
126 pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable<Vec<Module>> { 126 pub fn path_to_root(&self, db: &impl HirDatabase) -> Vec<Module> {
127 let mut res = vec![self.clone()]; 127 let mut res = vec![self.clone()];
128 let mut curr = self.clone(); 128 let mut curr = self.clone();
129 while let Some(next) = curr.parent(db)? { 129 while let Some(next) = curr.parent(db) {
130 res.push(next.clone()); 130 res.push(next.clone());
131 curr = next 131 curr = next
132 } 132 }
133 Ok(res) 133 res
134 } 134 }
135 135
136 /// Returns a `ModuleScope`: a set of items, visible in this module. 136 /// Returns a `ModuleScope`: a set of items, visible in this module.
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 127dcc570..8668d6c8a 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -66,21 +66,21 @@ impl Module {
66 Some((file_id, src)) 66 Some((file_id, src))
67 } 67 }
68 68
69 pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 69 pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Option<Crate> {
70 let root = self.crate_root(db)?; 70 let root = self.crate_root(db);
71 let loc = root.def_id.loc(db); 71 let loc = root.def_id.loc(db);
72 let file_id = loc.source_item_id.file_id.as_original_file(); 72 let file_id = loc.source_item_id.file_id.as_original_file();
73 73
74 let crate_graph = db.crate_graph(); 74 let crate_graph = db.crate_graph();
75 let crate_id = ctry!(crate_graph.crate_id_for_crate_root(file_id)); 75 let crate_id = crate_graph.crate_id_for_crate_root(file_id)?;
76 Ok(Some(Crate::new(crate_id))) 76 Some(Crate::new(crate_id))
77 } 77 }
78 78
79 pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable<Module> { 79 pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module {
80 let loc = self.def_id.loc(db); 80 let loc = self.def_id.loc(db);
81 let module_tree = db.module_tree(loc.source_root_id); 81 let module_tree = db.module_tree(loc.source_root_id);
82 let module_id = loc.module_id.crate_root(&module_tree); 82 let module_id = loc.module_id.crate_root(&module_tree);
83 Ok(Module::from_module_id(db, loc.source_root_id, module_id)) 83 Module::from_module_id(db, loc.source_root_id, module_id)
84 } 84 }
85 85
86 /// Finds a child module with the specified name. 86 /// Finds a child module with the specified name.
@@ -92,7 +92,7 @@ impl Module {
92 } 92 }
93 93
94 /// Iterates over all child modules. 94 /// Iterates over all child modules.
95 pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> { 95 pub fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> {
96 // FIXME this should be implementable without collecting into a vec, but 96 // FIXME this should be implementable without collecting into a vec, but
97 // it's kind of hard since the iterator needs to keep a reference to the 97 // it's kind of hard since the iterator needs to keep a reference to the
98 // module tree. 98 // module tree.
@@ -103,18 +103,14 @@ impl Module {
103 .children(&module_tree) 103 .children(&module_tree)
104 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) 104 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
105 .collect::<Vec<_>>(); 105 .collect::<Vec<_>>();
106 Ok(children.into_iter()) 106 children.into_iter()
107 } 107 }
108 108
109 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 109 pub fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> {
110 let loc = self.def_id.loc(db); 110 let loc = self.def_id.loc(db);
111 let module_tree = db.module_tree(loc.source_root_id); 111 let module_tree = db.module_tree(loc.source_root_id);
112 let parent_id = ctry!(loc.module_id.parent(&module_tree)); 112 let parent_id = loc.module_id.parent(&module_tree)?;
113 Ok(Some(Module::from_module_id( 113 Some(Module::from_module_id(db, loc.source_root_id, parent_id))
114 db,
115 loc.source_root_id,
116 parent_id,
117 )))
118 } 114 }
119 115
120 /// Returns a `ModuleScope`: a set of items, visible in this module. 116 /// Returns a `ModuleScope`: a set of items, visible in this module.
@@ -132,10 +128,10 @@ impl Module {
132 ) -> Cancelable<PerNs<DefId>> { 128 ) -> Cancelable<PerNs<DefId>> {
133 let mut curr_per_ns = PerNs::types( 129 let mut curr_per_ns = PerNs::types(
134 match path.kind { 130 match path.kind {
135 PathKind::Crate => self.crate_root(db)?, 131 PathKind::Crate => self.crate_root(db),
136 PathKind::Self_ | PathKind::Plain => self.clone(), 132 PathKind::Self_ | PathKind::Plain => self.clone(),
137 PathKind::Super => { 133 PathKind::Super => {
138 if let Some(p) = self.parent(db)? { 134 if let Some(p) = self.parent(db) {
139 p 135 p
140 } else { 136 } else {
141 return Ok(PerNs::none()); 137 return Ok(PerNs::none());
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index d7cc9b4ca..7b572061a 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -217,7 +217,7 @@ impl DefId {
217 217
218 /// Returns the containing crate. 218 /// Returns the containing crate.
219 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 219 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
220 Ok(self.module(db)?.krate(db)?) 220 Ok(self.module(db)?.krate(db))
221 } 221 }
222 222
223 /// Returns the containing impl block, if this is an impl item. 223 /// Returns the containing impl block, if this is an impl item.
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 7c3839388..f0da2ee2b 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -75,7 +75,7 @@ impl CrateImplBlocks {
75 } 75 }
76 } 76 }
77 77
78 for child in module.children(db)? { 78 for child in module.children(db) {
79 self.collect_recursive(db, child)?; 79 self.collect_recursive(db, child)?;
80 } 80 }
81 81
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index 76cb312dd..3ef11dfa1 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -99,16 +99,16 @@ impl db::RootDatabase {
99 99
100impl db::RootDatabase { 100impl db::RootDatabase {
101 /// Returns `Vec` for the same reason as `parent_module` 101 /// Returns `Vec` for the same reason as `parent_module`
102 pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 102 pub(crate) fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
103 let module = match source_binder::module_from_file_id(self, file_id) { 103 let module = match source_binder::module_from_file_id(self, file_id) {
104 Some(it) => it, 104 Some(it) => it,
105 None => return Ok(Vec::new()), 105 None => return Vec::new(),
106 }; 106 };
107 let krate = match module.krate(self)? { 107 let krate = match module.krate(self) {
108 Some(it) => it, 108 Some(it) => it,
109 None => return Ok(Vec::new()), 109 None => return Vec::new(),
110 }; 110 };
111 Ok(vec![krate.crate_id()]) 111 vec![krate.crate_id()]
112 } 112 }
113 pub(crate) fn find_all_refs( 113 pub(crate) fn find_all_refs(
114 &self, 114 &self,
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index e0b8410d1..0f690fc84 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -419,7 +419,7 @@ impl Analysis {
419 419
420 /// Returns crates this file belongs too. 420 /// Returns crates this file belongs too.
421 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 421 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
422 self.with_db(|db| db.crate_for(file_id))? 422 self.with_db(|db| db.crate_for(file_id))
423 } 423 }
424 424
425 /// Returns the root file of the given crate. 425 /// Returns the root file of the given crate.
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index c0d4bda94..a3207fdd2 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -80,7 +80,6 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt
80 // FIXME: thread cancellation instead of `.ok`ing 80 // FIXME: thread cancellation instead of `.ok`ing
81 let path = module 81 let path = module
82 .path_to_root(db) 82 .path_to_root(db)
83 .ok()?
84 .into_iter() 83 .into_iter()
85 .rev() 84 .rev()
86 .filter_map(|it| it.name(db)) 85 .filter_map(|it| it.name(db))