diff options
Diffstat (limited to 'crates/ra_ide/src/references')
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 8735ec53c..c8d80fcf7 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -7,7 +7,8 @@ use ra_ide_db::{ | |||
7 | RootDatabase, | 7 | RootDatabase, |
8 | }; | 8 | }; |
9 | use ra_syntax::{ | 9 | use ra_syntax::{ |
10 | algo::find_node_at_offset, ast, ast::NameOwner, ast::TypeAscriptionOwner, | 10 | algo::find_node_at_offset, |
11 | ast::{self, NameOwner}, | ||
11 | lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, | 12 | lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, |
12 | }; | 13 | }; |
13 | use ra_text_edit::TextEdit; | 14 | use ra_text_edit::TextEdit; |
@@ -149,14 +150,14 @@ fn rename_to_self( | |||
149 | let source_file = sema.parse(position.file_id); | 150 | let source_file = sema.parse(position.file_id); |
150 | let syn = source_file.syntax(); | 151 | let syn = source_file.syntax(); |
151 | 152 | ||
152 | let fn_def = find_node_at_offset::<ast::FnDef>(syn, position.offset)?; | 153 | let fn_def = find_node_at_offset::<ast::Fn>(syn, position.offset)?; |
153 | let params = fn_def.param_list()?; | 154 | let params = fn_def.param_list()?; |
154 | if params.self_param().is_some() { | 155 | if params.self_param().is_some() { |
155 | return None; // method already has self param | 156 | return None; // method already has self param |
156 | } | 157 | } |
157 | let first_param = params.params().next()?; | 158 | let first_param = params.params().next()?; |
158 | let mutable = match first_param.ascribed_type() { | 159 | let mutable = match first_param.ty() { |
159 | Some(ast::TypeRef::ReferenceType(rt)) => rt.mut_token().is_some(), | 160 | Some(ast::Type::RefType(rt)) => rt.mut_token().is_some(), |
160 | _ => return None, // not renaming other types | 161 | _ => return None, // not renaming other types |
161 | }; | 162 | }; |
162 | 163 | ||
@@ -192,15 +193,14 @@ fn text_edit_from_self_param( | |||
192 | self_param: &ast::SelfParam, | 193 | self_param: &ast::SelfParam, |
193 | new_name: &str, | 194 | new_name: &str, |
194 | ) -> Option<TextEdit> { | 195 | ) -> Option<TextEdit> { |
195 | fn target_type_name(impl_def: &ast::ImplDef) -> Option<String> { | 196 | fn target_type_name(impl_def: &ast::Impl) -> Option<String> { |
196 | if let Some(ast::TypeRef::PathType(p)) = impl_def.target_type() { | 197 | if let Some(ast::Type::PathType(p)) = impl_def.self_ty() { |
197 | return Some(p.path()?.segment()?.name_ref()?.text().to_string()); | 198 | return Some(p.path()?.segment()?.name_ref()?.text().to_string()); |
198 | } | 199 | } |
199 | None | 200 | None |
200 | } | 201 | } |
201 | 202 | ||
202 | let impl_def = | 203 | let impl_def = find_node_at_offset::<ast::Impl>(syn, self_param.syntax().text_range().start())?; |
203 | find_node_at_offset::<ast::ImplDef>(syn, self_param.syntax().text_range().start())?; | ||
204 | let type_name = target_type_name(&impl_def)?; | 204 | let type_name = target_type_name(&impl_def)?; |
205 | 205 | ||
206 | let mut replacement_text = String::from(new_name); | 206 | let mut replacement_text = String::from(new_name); |
@@ -221,7 +221,7 @@ fn rename_self_to_param( | |||
221 | let syn = source_file.syntax(); | 221 | let syn = source_file.syntax(); |
222 | 222 | ||
223 | let text = sema.db.file_text(position.file_id); | 223 | let text = sema.db.file_text(position.file_id); |
224 | let fn_def = find_node_at_offset::<ast::FnDef>(syn, position.offset)?; | 224 | let fn_def = find_node_at_offset::<ast::Fn>(syn, position.offset)?; |
225 | let search_range = fn_def.syntax().text_range(); | 225 | let search_range = fn_def.syntax().text_range(); |
226 | 226 | ||
227 | let mut edits: Vec<SourceFileEdit> = vec![]; | 227 | let mut edits: Vec<SourceFileEdit> = vec![]; |