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.rs95
1 files changed, 5 insertions, 90 deletions
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index 3f0de8b5b..b52a3f4d5 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -1,10 +1,7 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use hir::{ 3use hir::{
4 self, Problem, source_binder::{ 4 self, Problem, source_binder
5 self,
6 module_from_declaration
7 }, ModuleSource,
8}; 5};
9use ra_db::{ 6use ra_db::{
10 FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase, 7 FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase,
@@ -22,6 +19,7 @@ use crate::{
22 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, 19 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
23 Query, RootChange, SourceChange, SourceFileEdit, 20 Query, RootChange, SourceChange, SourceFileEdit,
24 symbol_index::{FileSymbol, LibrarySymbolsQuery}, 21 symbol_index::{FileSymbol, LibrarySymbolsQuery},
22 rename::rename
25}; 23};
26 24
27impl db::RootDatabase { 25impl db::RootDatabase {
@@ -234,94 +232,11 @@ impl db::RootDatabase {
234 .collect() 232 .collect()
235 } 233 }
236 234
237<<<<<<< HEAD 235 pub(crate) fn rename(&self, position: FilePosition, new_name: &str) -> Option<SourceChange> {
238 pub(crate) fn rename(&self, position: FilePosition, new_name: &str) -> Vec<SourceFileEdit> { 236 rename(self, position, new_name)
239 self.find_all_refs(position)
240 .iter()
241 .map(|(file_id, text_range)| SourceFileEdit {
242 file_id: *file_id,
243=======
244 pub(crate) fn rename(
245 &self,
246 position: FilePosition,
247 new_name: &str,
248 ) -> Cancelable<Option<SourceChange>> {
249 let mut source_file_edits = Vec::new();
250 let mut file_system_edits = Vec::new();
251
252 let source_file = self.source_file(position.file_id);
253 let syntax = source_file.syntax();
254 // We are rename a mod
255 if let (Some(ast_module), Some(name)) = (
256 find_node_at_offset::<ast::Module>(syntax, position.offset),
257 find_node_at_offset::<ast::Name>(syntax, position.offset),
258 ) {
259 if let Some(module) = module_from_declaration(self, position.file_id, &ast_module)? {
260 let (file_id, module_source) = module.definition_source(self)?;
261 match module_source {
262 ModuleSource::SourceFile(..) => {
263 let move_file = FileSystemEdit::MoveFile {
264 src: file_id,
265 dst_source_root: self.file_source_root(position.file_id),
266 dst_path: self
267 .file_relative_path(file_id)
268 .with_file_name(new_name)
269 .with_extension("rs"),
270 };
271 file_system_edits.push(move_file);
272 }
273 ModuleSource::Module(..) => {}
274 }
275 }
276
277 let edit = SourceFileEdit {
278 file_id: position.file_id,
279>>>>>>> rename mod
280 edit: {
281 let mut builder = ra_text_edit::TextEditBuilder::default();
282 builder.replace(name.syntax().range(), new_name.into());
283 builder.finish()
284 },
285<<<<<<< HEAD
286 })
287 .collect::<Vec<_>>()
288 } 237 }
289 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
290=======
291 };
292 source_file_edits.push(edit);
293 }
294 // rename references
295 else {
296 let edit = self
297 .find_all_refs(position)?
298 .iter()
299 .map(|(file_id, text_range)| SourceFileEdit {
300 file_id: *file_id,
301 edit: {
302 let mut builder = ra_text_edit::TextEditBuilder::default();
303 builder.replace(*text_range, new_name.into());
304 builder.finish()
305 },
306 })
307 .collect::<Vec<_>>();
308 if edit.is_empty() {
309 return Ok(None);
310 }
311 238
312 source_file_edits = edit; 239 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
313 }
314
315 return Ok(Some(SourceChange {
316 label: "rename".to_string(),
317 source_file_edits,
318 file_system_edits,
319 cursor_position: None,
320 }));
321 }
322
323 pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Cancelable<Vec<FileSymbol>> {
324>>>>>>> rename mod
325 let name = name_ref.text(); 240 let name = name_ref.text();
326 let mut query = Query::new(name.to_string()); 241 let mut query = Query::new(name.to_string());
327 query.exact(); 242 query.exact();