aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/navigation_target.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 15:50:47 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 15:50:47 +0000
commit7c977a7dcd2bac3b6148f2428bcb586c6354d775 (patch)
tree6ea2db9840f91aa39b65680ace9d3079a140a12c /crates/ra_ide_api/src/navigation_target.rs
parent05149d353299b54476410daeda6551e1261128ef (diff)
parentf1367e0370d5de5cba13c853c7df5f0c5a0edf59 (diff)
Merge #552
552: remove Cancelable from navigation target r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/navigation_target.rs')
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs48
1 files changed, 18 insertions, 30 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 7562b9a1f..21c15c0c0 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -1,4 +1,4 @@
1use ra_db::{FileId, Cancelable}; 1use ra_db::FileId;
2use ra_syntax::{ 2use ra_syntax::{
3 SyntaxNode, AstNode, SmolStr, TextRange, ast, 3 SyntaxNode, AstNode, SmolStr, TextRange, ast,
4 SyntaxKind::{self, NAME}, 4 SyntaxKind::{self, NAME},
@@ -69,84 +69,72 @@ impl NavigationTarget {
69 } 69 }
70 } 70 }
71 71
72 pub(crate) fn from_module( 72 pub(crate) fn from_module(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
73 db: &RootDatabase,
74 module: hir::Module,
75 ) -> Cancelable<NavigationTarget> {
76 let (file_id, source) = module.definition_source(db); 73 let (file_id, source) = module.definition_source(db);
77 let name = module 74 let name = module
78 .name(db) 75 .name(db)
79 .map(|it| it.to_string().into()) 76 .map(|it| it.to_string().into())
80 .unwrap_or_default(); 77 .unwrap_or_default();
81 let res = match source { 78 match source {
82 ModuleSource::SourceFile(node) => { 79 ModuleSource::SourceFile(node) => {
83 NavigationTarget::from_syntax(file_id, name, None, node.syntax()) 80 NavigationTarget::from_syntax(file_id, name, None, node.syntax())
84 } 81 }
85 ModuleSource::Module(node) => { 82 ModuleSource::Module(node) => {
86 NavigationTarget::from_syntax(file_id, name, None, node.syntax()) 83 NavigationTarget::from_syntax(file_id, name, None, node.syntax())
87 } 84 }
88 }; 85 }
89 Ok(res)
90 } 86 }
91 87
92 pub(crate) fn from_module_to_decl( 88 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
93 db: &RootDatabase,
94 module: hir::Module,
95 ) -> Cancelable<NavigationTarget> {
96 let name = module 89 let name = module
97 .name(db) 90 .name(db)
98 .map(|it| it.to_string().into()) 91 .map(|it| it.to_string().into())
99 .unwrap_or_default(); 92 .unwrap_or_default();
100 if let Some((file_id, source)) = module.declaration_source(db) { 93 if let Some((file_id, source)) = module.declaration_source(db) {
101 return Ok(NavigationTarget::from_syntax( 94 return NavigationTarget::from_syntax(file_id, name, None, source.syntax());
102 file_id,
103 name,
104 None,
105 source.syntax(),
106 ));
107 } 95 }
108 NavigationTarget::from_module(db, module) 96 NavigationTarget::from_module(db, module)
109 } 97 }
110 98
111 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget 99 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget
112 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> { 100 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Option<NavigationTarget> {
113 let res = match def { 101 let res = match def {
114 Def::Struct(s) => { 102 Def::Struct(s) => {
115 let (file_id, node) = s.source(db)?; 103 let (file_id, node) = s.source(db);
116 NavigationTarget::from_named(file_id.original_file(db), &*node) 104 NavigationTarget::from_named(file_id.original_file(db), &*node)
117 } 105 }
118 Def::Enum(e) => { 106 Def::Enum(e) => {
119 let (file_id, node) = e.source(db)?; 107 let (file_id, node) = e.source(db);
120 NavigationTarget::from_named(file_id.original_file(db), &*node) 108 NavigationTarget::from_named(file_id.original_file(db), &*node)
121 } 109 }
122 Def::EnumVariant(ev) => { 110 Def::EnumVariant(ev) => {
123 let (file_id, node) = ev.source(db)?; 111 let (file_id, node) = ev.source(db);
124 NavigationTarget::from_named(file_id.original_file(db), &*node) 112 NavigationTarget::from_named(file_id.original_file(db), &*node)
125 } 113 }
126 Def::Function(f) => { 114 Def::Function(f) => {
127 let (file_id, node) = f.source(db)?; 115 let (file_id, node) = f.source(db);
128 NavigationTarget::from_named(file_id.original_file(db), &*node) 116 NavigationTarget::from_named(file_id.original_file(db), &*node)
129 } 117 }
130 Def::Trait(f) => { 118 Def::Trait(f) => {
131 let (file_id, node) = f.source(db)?; 119 let (file_id, node) = f.source(db);
132 NavigationTarget::from_named(file_id.original_file(db), &*node) 120 NavigationTarget::from_named(file_id.original_file(db), &*node)
133 } 121 }
134 Def::Type(f) => { 122 Def::Type(f) => {
135 let (file_id, node) = f.source(db)?; 123 let (file_id, node) = f.source(db);
136 NavigationTarget::from_named(file_id.original_file(db), &*node) 124 NavigationTarget::from_named(file_id.original_file(db), &*node)
137 } 125 }
138 Def::Static(f) => { 126 Def::Static(f) => {
139 let (file_id, node) = f.source(db)?; 127 let (file_id, node) = f.source(db);
140 NavigationTarget::from_named(file_id.original_file(db), &*node) 128 NavigationTarget::from_named(file_id.original_file(db), &*node)
141 } 129 }
142 Def::Const(f) => { 130 Def::Const(f) => {
143 let (file_id, node) = f.source(db)?; 131 let (file_id, node) = f.source(db);
144 NavigationTarget::from_named(file_id.original_file(db), &*node) 132 NavigationTarget::from_named(file_id.original_file(db), &*node)
145 } 133 }
146 Def::Module(m) => NavigationTarget::from_module(db, m)?, 134 Def::Module(m) => NavigationTarget::from_module(db, m),
147 Def::Item => return Ok(None), 135 Def::Item => return None,
148 }; 136 };
149 Ok(Some(res)) 137 Some(res)
150 } 138 }
151 139
152 #[cfg(test)] 140 #[cfg(test)]