aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorDJMcNab <[email protected]>2018-12-30 18:14:55 +0000
committerDJMcNab <[email protected]>2018-12-30 18:14:55 +0000
commitc402b007a3272efada7924fce4eecf698b98968b (patch)
treeeea606837139333d511468d5127d2c20d806930f /crates/ra_analysis/src
parent0f95d8523e0646aac8fb69c61f7b0d7a8efe42bb (diff)
Move renames into ra_analysis
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/imp.rs26
-rw-r--r--crates/ra_analysis/src/lib.rs7
2 files changed, 31 insertions, 2 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index bff2e00c9..5ed374c79 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -288,7 +288,11 @@ impl AnalysisImpl {
288 Some(it) => it, 288 Some(it) => it,
289 }; 289 };
290 290
291 let mut ret = vec![(position.file_id, binding.syntax().range())]; 291 let mut ret = binding
292 .name()
293 .into_iter()
294 .map(|name| (position.file_id, name.syntax().range()))
295 .collect::<Vec<_>>();
292 ret.extend( 296 ret.extend(
293 descr 297 descr
294 .scopes(&*self.db) 298 .scopes(&*self.db)
@@ -505,7 +509,25 @@ impl AnalysisImpl {
505 let infer = function.infer(&*self.db)?; 509 let infer = function.infer(&*self.db)?;
506 Ok(infer.type_of_node(node).map(|t| t.to_string())) 510 Ok(infer.type_of_node(node).map(|t| t.to_string()))
507 } 511 }
508 512 pub fn rename(
513 &self,
514 position: FilePosition,
515 new_name: &str,
516 ) -> Cancelable<Vec<SourceFileEdit>> {
517 let res = self
518 .find_all_refs(position)?
519 .iter()
520 .map(|(file_id, text_range)| SourceFileEdit {
521 file_id: *file_id,
522 edit: {
523 let mut builder = ra_text_edit::TextEditBuilder::new();
524 builder.replace(*text_range, new_name.into());
525 builder.finish()
526 },
527 })
528 .collect::<Vec<_>>();
529 Ok(res)
530 }
509 fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileSymbol)>> { 531 fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileSymbol)>> {
510 let name = name_ref.text(); 532 let name = name_ref.text();
511 let mut query = Query::new(name.to_string()); 533 let mut query = Query::new(name.to_string());
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 9f5e9f358..e56168510 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -367,6 +367,13 @@ impl Analysis {
367 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { 367 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
368 self.imp.type_of(frange) 368 self.imp.type_of(frange)
369 } 369 }
370 pub fn rename(
371 &self,
372 position: FilePosition,
373 new_name: &str,
374 ) -> Cancelable<Vec<SourceFileEdit>> {
375 self.imp.rename(position, new_name)
376 }
370} 377}
371 378
372pub struct LibraryData { 379pub struct LibraryData {