From 6ab6d1eaa036f8620542ad9c12764957e868b7e0 Mon Sep 17 00:00:00 2001 From: gfreezy Date: Thu, 17 Jan 2019 19:57:24 +0800 Subject: fix comments --- crates/ra_ide_api/src/imp.rs | 5 ---- crates/ra_ide_api/src/lib.rs | 2 +- crates/ra_ide_api/src/rename.rs | 4 +-- crates/ra_lsp_server/src/main_loop/handlers.rs | 34 +++----------------------- 4 files changed, 5 insertions(+), 40 deletions(-) diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs index b52a3f4d5..fa79908a1 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs @@ -19,7 +19,6 @@ use crate::{ CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, Query, RootChange, SourceChange, SourceFileEdit, symbol_index::{FileSymbol, LibrarySymbolsQuery}, - rename::rename }; impl db::RootDatabase { @@ -232,10 +231,6 @@ impl db::RootDatabase { .collect() } - pub(crate) fn rename(&self, position: FilePosition, new_name: &str) -> Option { - rename(self, position, new_name) - } - pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec { let name = name_ref.text(); let mut query = Query::new(name.to_string()); diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 1845bf443..33bef178a 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -466,7 +466,7 @@ impl Analysis { position: FilePosition, new_name: &str, ) -> Cancelable> { - self.with_db(|db| db.rename(position, new_name)) + self.with_db(|db| rename::rename(db, position, new_name)) } fn with_db T + std::panic::UnwindSafe, T>( diff --git a/crates/ra_ide_api/src/rename.rs b/crates/ra_ide_api/src/rename.rs index 9f8a00ae7..9ab6f2a77 100644 --- a/crates/ra_ide_api/src/rename.rs +++ b/crates/ra_ide_api/src/rename.rs @@ -40,9 +40,7 @@ fn find_name_and_module_at_offset( position: FilePosition, ) -> Option<(&ast::Name, &ast::Module)> { let ast_name = find_node_at_offset::(syntax, position.offset); - let ast_name_parent = ast_name - .and_then(|n| n.syntax().parent()) - .and_then(|p| ast::Module::cast(p)); + let ast_name_parent = ast::Module::cast(ast_name?.syntax().parent()?); if let (Some(ast_module), Some(name)) = (ast_name_parent, ast_name) { return Some((name, ast_module)); diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c010a6ddf..9cdca82c4 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -5,7 +5,7 @@ use lsp_types::{ FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, - WorkspaceEdit, DocumentChanges, TextDocumentEdit, DocumentChangeOperation, ResourceOp + WorkspaceEdit }; use ra_ide_api::{ FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, @@ -472,37 +472,9 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result>>(); - - let text_document_ops = source_change - .file_system_edits - .drain(..) - .into_iter() - .map(|e| e.try_conv_with(&world)) - .collect::>>(); - - let mut document_changes = Vec::new(); - document_changes.extend( - text_document_edits? - .into_iter() - .map(DocumentChangeOperation::Edit), - ); - document_changes.extend( - text_document_ops? - .into_iter() - .map(DocumentChangeOperation::Op), - ); + let source_change_req = change.unwrap().try_conv_with(&world)?; - Ok(Some(WorkspaceEdit { - changes: None, - document_changes: Some(DocumentChanges::Operations(document_changes)), - })) + Ok(Some(source_change_req.workspace_edit)) } pub fn handle_references( -- cgit v1.2.3