aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/utils.rs')
-rw-r--r--crates/assists/src/utils.rs33
1 files changed, 14 insertions, 19 deletions
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs
index e15c982e7..daa7b64f7 100644
--- a/crates/assists/src/utils.rs
+++ b/crates/assists/src/utils.rs
@@ -8,10 +8,10 @@ use ide_db::RootDatabase;
8use itertools::Itertools; 8use itertools::Itertools;
9use rustc_hash::FxHashSet; 9use rustc_hash::FxHashSet;
10use syntax::{ 10use syntax::{
11 ast::{self, make, NameOwner}, 11 ast::{self, make, ArgListOwner, NameOwner},
12 AstNode, Direction, 12 AstNode, Direction,
13 SyntaxKind::*, 13 SyntaxKind::*,
14 SyntaxNode, SyntaxText, TextSize, T, 14 SyntaxNode, TextSize, T,
15}; 15};
16 16
17use crate::assist_config::SnippetCap; 17use crate::assist_config::SnippetCap;
@@ -180,23 +180,18 @@ fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
180 _ => None, 180 _ => None,
181 }, 181 },
182 ast::Expr::MethodCallExpr(mce) => { 182 ast::Expr::MethodCallExpr(mce) => {
183 const IS_SOME_TEXT: &str = "is_some"; 183 let receiver = mce.receiver()?;
184 const IS_NONE_TEXT: &str = "is_none"; 184 let method = mce.name_ref()?;
185 const IS_OK_TEXT: &str = "is_ok"; 185 let arg_list = mce.arg_list()?;
186 const IS_ERR_TEXT: &str = "is_err"; 186
187 187 let method = match method.text().as_str() {
188 let name = mce.name_ref()?; 188 "is_some" => "is_none",
189 let name_text = name.text(); 189 "is_none" => "is_some",
190 190 "is_ok" => "is_err",
191 let caller = || -> Option<SyntaxText> { Some(mce.receiver()?.syntax().text()) }; 191 "is_err" => "is_ok",
192 192 _ => return None,
193 match name_text { 193 };
194 x if x == IS_SOME_TEXT => make::expr_method_call(IS_NONE_TEXT, caller), 194 Some(make::expr_method_call(receiver, method, arg_list))
195 x if x == IS_NONE_TEXT => make::expr_method_call(IS_SOME_TEXT, caller),
196 x if x == IS_OK_TEXT => make::expr_method_call(IS_ERR_TEXT, caller),
197 x if x == IS_ERR_TEXT => make::expr_method_call(IS_OK_TEXT, caller),
198 _ => None,
199 }
200 } 195 }
201 ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(), 196 ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(),
202 // FIXME: 197 // FIXME: