aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/imp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/imp.rs')
-rw-r--r--crates/ra_ide_api/src/imp.rs49
1 files changed, 17 insertions, 32 deletions
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index 391df2695..a21cae624 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -110,14 +110,11 @@ impl db::RootDatabase {
110 }; 110 };
111 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(&self, position: FilePosition) -> Vec<(FileId, TextRange)> {
114 &self,
115 position: FilePosition,
116 ) -> Cancelable<Vec<(FileId, TextRange)>> {
117 let file = self.source_file(position.file_id); 114 let file = self.source_file(position.file_id);
118 // Find the binding associated with the offset 115 // Find the binding associated with the offset
119 let (binding, descr) = match find_binding(self, &file, position)? { 116 let (binding, descr) = match find_binding(self, &file, position) {
120 None => return Ok(Vec::new()), 117 None => return Vec::new(),
121 Some(it) => it, 118 Some(it) => it,
122 }; 119 };
123 120
@@ -134,36 +131,30 @@ impl db::RootDatabase {
134 .map(|ref_desc| (position.file_id, ref_desc.range)), 131 .map(|ref_desc| (position.file_id, ref_desc.range)),
135 ); 132 );
136 133
137 return Ok(ret); 134 return ret;
138 135
139 fn find_binding<'a>( 136 fn find_binding<'a>(
140 db: &db::RootDatabase, 137 db: &db::RootDatabase,
141 source_file: &'a SourceFile, 138 source_file: &'a SourceFile,
142 position: FilePosition, 139 position: FilePosition,
143 ) -> Cancelable<Option<(&'a ast::BindPat, hir::Function)>> { 140 ) -> Option<(&'a ast::BindPat, hir::Function)> {
144 let syntax = source_file.syntax(); 141 let syntax = source_file.syntax();
145 if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { 142 if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) {
146 let descr = ctry!(source_binder::function_from_child_node( 143 let descr = source_binder::function_from_child_node(
147 db, 144 db,
148 position.file_id, 145 position.file_id,
149 binding.syntax(), 146 binding.syntax(),
150 )); 147 )?;
151 return Ok(Some((binding, descr))); 148 return Some((binding, descr));
152 }; 149 };
153 let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset)); 150 let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?;
154 let descr = ctry!(source_binder::function_from_child_node( 151 let descr =
155 db, 152 source_binder::function_from_child_node(db, position.file_id, name_ref.syntax())?;
156 position.file_id,
157 name_ref.syntax(),
158 ));
159 let scope = descr.scopes(db); 153 let scope = descr.scopes(db);
160 let resolved = ctry!(scope.resolve_local_name(name_ref)); 154 let resolved = scope.resolve_local_name(name_ref)?;
161 let resolved = resolved.ptr().resolve(source_file); 155 let resolved = resolved.ptr().resolve(source_file);
162 let binding = ctry!(find_node_at_offset::<ast::BindPat>( 156 let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?;
163 syntax, 157 Some((binding, descr))
164 resolved.range().end()
165 ));
166 Ok(Some((binding, descr)))
167 } 158 }
168 } 159 }
169 160
@@ -239,13 +230,8 @@ impl db::RootDatabase {
239 .collect() 230 .collect()
240 } 231 }
241 232
242 pub(crate) fn rename( 233 pub(crate) fn rename(&self, position: FilePosition, new_name: &str) -> Vec<SourceFileEdit> {
243 &self, 234 self.find_all_refs(position)
244 position: FilePosition,
245 new_name: &str,
246 ) -> Cancelable<Vec<SourceFileEdit>> {
247 let res = self
248 .find_all_refs(position)?
249 .iter() 235 .iter()
250 .map(|(file_id, text_range)| SourceFileEdit { 236 .map(|(file_id, text_range)| SourceFileEdit {
251 file_id: *file_id, 237 file_id: *file_id,
@@ -255,8 +241,7 @@ impl db::RootDatabase {
255 builder.finish() 241 builder.finish()
256 }, 242 },
257 }) 243 })
258 .collect::<Vec<_>>(); 244 .collect::<Vec<_>>()
259 Ok(res)
260 } 245 }
261 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> { 246 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
262 let name = name_ref.text(); 247 let name = name_ref.text();