diff options
Diffstat (limited to 'crates/assists/src/utils.rs')
-rw-r--r-- | crates/assists/src/utils.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index d41084b59..9ea96eb73 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -4,7 +4,7 @@ pub(crate) mod import_assets; | |||
4 | use std::ops; | 4 | use std::ops; |
5 | 5 | ||
6 | use hir::HasSource; | 6 | use hir::HasSource; |
7 | use ide_db::RootDatabase; | 7 | use ide_db::{helpers::SnippetCap, RootDatabase}; |
8 | use itertools::Itertools; | 8 | use itertools::Itertools; |
9 | use syntax::{ | 9 | use syntax::{ |
10 | ast::edit::AstNodeEdit, | 10 | ast::edit::AstNodeEdit, |
@@ -16,10 +16,7 @@ use syntax::{ | |||
16 | SyntaxNode, TextSize, T, | 16 | SyntaxNode, TextSize, T, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}; |
20 | assist_config::SnippetCap, | ||
21 | ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, | ||
22 | }; | ||
23 | 20 | ||
24 | pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { | 21 | pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { |
25 | extract_trivial_expression(&block) | 22 | extract_trivial_expression(&block) |
@@ -37,7 +34,7 @@ pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> { | |||
37 | non_trivial_children.next().is_some() | 34 | non_trivial_children.next().is_some() |
38 | }; | 35 | }; |
39 | 36 | ||
40 | if let Some(expr) = block.expr() { | 37 | if let Some(expr) = block.tail_expr() { |
41 | if has_anything_else(expr.syntax()) { | 38 | if has_anything_else(expr.syntax()) { |
42 | return None; | 39 | return None; |
43 | } | 40 | } |
@@ -94,14 +91,18 @@ pub fn filter_assoc_items( | |||
94 | ast::AssocItem::MacroCall(_) => None, | 91 | ast::AssocItem::MacroCall(_) => None, |
95 | } | 92 | } |
96 | .is_some() | 93 | .is_some() |
97 | }; | 94 | } |
98 | 95 | ||
99 | items | 96 | items |
100 | .iter() | 97 | .iter() |
101 | .map(|i| match i { | 98 | // Note: This throws away items with no source. |
102 | hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(db).value), | 99 | .filter_map(|i| { |
103 | hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(db).value), | 100 | let item = match i { |
104 | hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(db).value), | 101 | hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(db)?.value), |
102 | hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(db)?.value), | ||
103 | hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(db)?.value), | ||
104 | }; | ||
105 | Some(item) | ||
105 | }) | 106 | }) |
106 | .filter(has_def_name) | 107 | .filter(has_def_name) |
107 | .filter(|it| match it { | 108 | .filter(|it| match it { |