aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/inline_local_variable.rs30
-rw-r--r--crates/ra_assists/src/lib.rs12
-rw-r--r--crates/ra_assists/src/marks.rs2
3 files changed, 34 insertions, 10 deletions
diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs
index 53a72309b..98e5112df 100644
--- a/crates/ra_assists/src/handlers/inline_local_variable.rs
+++ b/crates/ra_assists/src/handlers/inline_local_variable.rs
@@ -2,9 +2,9 @@ use ra_syntax::{
2 ast::{self, AstNode, AstToken}, 2 ast::{self, AstNode, AstToken},
3 TextRange, 3 TextRange,
4}; 4};
5use test_utils::tested_by;
5 6
6use crate::assist_ctx::ActionBuilder; 7use crate::{assist_ctx::ActionBuilder, Assist, AssistCtx, AssistId};
7use crate::{Assist, AssistCtx, AssistId};
8 8
9// Assist: inline_local_variable 9// Assist: inline_local_variable
10// 10//
@@ -29,6 +29,11 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> {
29 _ => return None, 29 _ => return None,
30 }; 30 };
31 if bind_pat.is_mutable() { 31 if bind_pat.is_mutable() {
32 tested_by!(test_not_inline_mut_variable);
33 return None;
34 }
35 if !bind_pat.syntax().text_range().contains_inclusive(ctx.frange.range.start()) {
36 tested_by!(not_applicable_outside_of_bind_pat);
32 return None; 37 return None;
33 } 38 }
34 let initializer_expr = let_stmt.initializer()?; 39 let initializer_expr = let_stmt.initializer()?;
@@ -111,6 +116,8 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> {
111 116
112#[cfg(test)] 117#[cfg(test)]
113mod tests { 118mod tests {
119 use test_utils::covers;
120
114 use crate::helpers::{check_assist, check_assist_not_applicable}; 121 use crate::helpers::{check_assist, check_assist_not_applicable};
115 122
116 use super::*; 123 use super::*;
@@ -317,9 +324,10 @@ fn foo() {
317 324
318 #[test] 325 #[test]
319 fn test_not_inline_mut_variable() { 326 fn test_not_inline_mut_variable() {
327 covers!(test_not_inline_mut_variable);
320 check_assist_not_applicable( 328 check_assist_not_applicable(
321 inline_local_variable, 329 inline_local_variable,
322 " 330 r"
323fn foo() { 331fn foo() {
324 let mut a<|> = 1 + 1; 332 let mut a<|> = 1 + 1;
325 a + 1; 333 a + 1;
@@ -651,11 +659,25 @@ fn foo() {
651 fn test_not_applicable_if_variable_unused() { 659 fn test_not_applicable_if_variable_unused() {
652 check_assist_not_applicable( 660 check_assist_not_applicable(
653 inline_local_variable, 661 inline_local_variable,
654 " 662 r"
655fn foo() { 663fn foo() {
656 let <|>a = 0; 664 let <|>a = 0;
657} 665}
658 ", 666 ",
659 ) 667 )
660 } 668 }
669
670 #[test]
671 fn not_applicable_outside_of_bind_pat() {
672 covers!(not_applicable_outside_of_bind_pat);
673 check_assist_not_applicable(
674 inline_local_variable,
675 r"
676fn main() {
677 let x = <|>1 + 2;
678 x * 4;
679}
680",
681 )
682 }
661} 683}
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index deeada2de..6d81a6396 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -178,19 +178,19 @@ mod helpers {
178 (db, file_id) 178 (db, file_id)
179 } 179 }
180 180
181 pub(crate) fn check_assist(assist: AssistHandler, before: &str, after: &str) { 181 pub(crate) fn check_assist(assist: AssistHandler, ra_fixture: &str, after: &str) {
182 check(assist, before, ExpectedResult::After(after)); 182 check(assist, ra_fixture, ExpectedResult::After(after));
183 } 183 }
184 184
185 // FIXME: instead of having a separate function here, maybe use 185 // FIXME: instead of having a separate function here, maybe use
186 // `extract_ranges` and mark the target as `<target> </target>` in the 186 // `extract_ranges` and mark the target as `<target> </target>` in the
187 // fixuture? 187 // fixuture?
188 pub(crate) fn check_assist_target(assist: AssistHandler, before: &str, target: &str) { 188 pub(crate) fn check_assist_target(assist: AssistHandler, ra_fixture: &str, target: &str) {
189 check(assist, before, ExpectedResult::Target(target)); 189 check(assist, ra_fixture, ExpectedResult::Target(target));
190 } 190 }
191 191
192 pub(crate) fn check_assist_not_applicable(assist: AssistHandler, before: &str) { 192 pub(crate) fn check_assist_not_applicable(assist: AssistHandler, ra_fixture: &str) {
193 check(assist, before, ExpectedResult::NotApplicable); 193 check(assist, ra_fixture, ExpectedResult::NotApplicable);
194 } 194 }
195 195
196 enum ExpectedResult<'a> { 196 enum ExpectedResult<'a> {
diff --git a/crates/ra_assists/src/marks.rs b/crates/ra_assists/src/marks.rs
index c20e4db9e..cef3df4e5 100644
--- a/crates/ra_assists/src/marks.rs
+++ b/crates/ra_assists/src/marks.rs
@@ -4,4 +4,6 @@ test_utils::marks!(
4 introduce_var_in_comment_is_not_applicable 4 introduce_var_in_comment_is_not_applicable
5 test_introduce_var_expr_stmt 5 test_introduce_var_expr_stmt
6 test_introduce_var_last_expr 6 test_introduce_var_last_expr
7 not_applicable_outside_of_bind_pat
8 test_not_inline_mut_variable
7); 9);