From bd9f1f7eb78843ddd91d259a04e988b0681a5db4 Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Wed, 6 May 2020 17:17:35 +0300 Subject: Fix rename of enum variant visible from module --- crates/ra_ide/src/references/rename.rs | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 0398d53bc..2cbb82c1a 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -712,6 +712,68 @@ mod tests { "###); } + #[test] + fn test_enum_variant_from_module_1() { + test_rename( + r#" + mod foo { + pub enum Foo { + Bar<|>, + } + } + + fn func(f: foo::Foo) { + match f { + foo::Foo::Bar => {} + } + } + "#, + "Baz", + r#" + mod foo { + pub enum Foo { + Baz, + } + } + + fn func(f: foo::Foo) { + match f { + foo::Foo::Baz => {} + } + } + "#, + ); + } + + #[test] + fn test_enum_variant_from_module_2() { + test_rename( + r#" + mod foo { + pub struct Foo { + pub bar<|>: uint, + } + } + + fn foo(f: foo::Foo) { + let _ = f.bar; + } + "#, + "baz", + r#" + mod foo { + pub struct Foo { + pub baz: uint, + } + } + + fn foo(f: foo::Foo) { + let _ = f.baz; + } + "#, + ); + } + fn test_rename(text: &str, new_name: &str, expected: &str) { let (analysis, position) = single_file_with_position(text); let source_change = analysis.rename(position, new_name).unwrap(); -- cgit v1.2.3 From 43cedecf68a6686b61fbd244b76c592726d1f211 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 14:29:01 +0200 Subject: Fix panic in FunctionSignature --- crates/ra_ide/src/display/function_signature.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index db3907fe6..f16d42276 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -1,5 +1,7 @@ //! FIXME: write short doc here +// FIXME: this modules relies on strings and AST way too much, and it should be +// rewritten (matklad 2020-05-07) use std::{ convert::From, fmt::{self, Display}, @@ -202,7 +204,11 @@ impl From<&'_ ast::FnDef> for FunctionSignature { res.extend(param_list.params().map(|param| param.syntax().text().to_string())); res_types.extend(param_list.params().map(|param| { - param.syntax().text().to_string().split(':').nth(1).unwrap()[1..].to_string() + let param_text = param.syntax().text().to_string(); + match param_text.split(':').nth(1) { + Some(it) => it[1..].to_string(), + None => param_text, + } })); } (has_self_param, res, res_types) -- cgit v1.2.3 From c6b81bc013b5278b917d109b723405e0df413323 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 17:09:59 +0200 Subject: Rename AssitLabel -> Assist --- crates/ra_ide/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 737f87109..0e15f1ccd 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -475,9 +475,9 @@ impl Analysis { ra_assists::resolved_assists(db, frange) .into_iter() .map(|assist| Assist { - id: assist.label.id, - label: assist.label.label, - group_label: assist.label.group.map(|it| it.0), + id: assist.assist.id, + label: assist.assist.label, + group_label: assist.assist.group.map(|it| it.0), source_change: assist.source_change, }) .collect() -- cgit v1.2.3 From 28fcff125a73ab2fc4aeaa100fc472af5178db20 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 17:29:23 +0200 Subject: Nicer API --- crates/ra_ide/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 0e15f1ccd..915199bd8 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -472,7 +472,7 @@ impl Analysis { /// position. pub fn assists(&self, frange: FileRange) -> Cancelable> { self.with_db(|db| { - ra_assists::resolved_assists(db, frange) + ra_assists::Assist::resolved(db, frange) .into_iter() .map(|assist| Assist { id: assist.assist.id, -- cgit v1.2.3 From 9405116d51b2d078557873fafbf3d91f19d332a7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 10 May 2020 16:27:31 +0800 Subject: Hot fix panic for function_signature --- crates/ra_ide/src/display/function_signature.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index f16d42276..3d3147254 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -84,8 +84,8 @@ impl FunctionSignature { let ty = field.signature_ty(db); let raw_param = format!("{}", ty.display(db)); - if let Some(param_type) = raw_param.split(':').nth(1) { - parameter_types.push(param_type[1..].to_string()); + if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { + parameter_types.push(param_type.to_string()); } else { // useful when you have tuple struct parameter_types.push(raw_param.clone()); @@ -129,8 +129,9 @@ impl FunctionSignature { for field in variant.fields(db).into_iter() { let ty = field.signature_ty(db); let raw_param = format!("{}", ty.display(db)); - if let Some(param_type) = raw_param.split(':').nth(1) { - parameter_types.push(param_type[1..].to_string()); + dbg!(&raw_param); + if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { + parameter_types.push(param_type.to_string()); } else { // The unwrap_or_else is useful when you have tuple parameter_types.push(raw_param); @@ -197,7 +198,12 @@ impl From<&'_ ast::FnDef> for FunctionSignature { let raw_param = self_param.syntax().text().to_string(); res_types.push( - raw_param.split(':').nth(1).unwrap_or_else(|| " Self")[1..].to_string(), + raw_param + .split(':') + .nth(1) + .and_then(|it| it.get(1..)) + .unwrap_or_else(|| "Self") + .to_string(), ); res.push(raw_param); } @@ -205,8 +211,8 @@ impl From<&'_ ast::FnDef> for FunctionSignature { res.extend(param_list.params().map(|param| param.syntax().text().to_string())); res_types.extend(param_list.params().map(|param| { let param_text = param.syntax().text().to_string(); - match param_text.split(':').nth(1) { - Some(it) => it[1..].to_string(), + match param_text.split(':').nth(1).and_then(|it| it.get(1..)) { + Some(it) => it.to_string(), None => param_text, } })); -- cgit v1.2.3 From a3375c1a88848195a7fd83d29acdab4029ca1459 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 10 May 2020 18:03:44 +0800 Subject: Remove dbg --- crates/ra_ide/src/display/function_signature.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 3d3147254..9572debd8 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -129,7 +129,6 @@ impl FunctionSignature { for field in variant.fields(db).into_iter() { let ty = field.signature_ty(db); let raw_param = format!("{}", ty.display(db)); - dbg!(&raw_param); if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { parameter_types.push(param_type.to_string()); } else { -- cgit v1.2.3