diff options
Diffstat (limited to 'crates/ra_assists/src/utils.rs')
-rw-r--r-- | crates/ra_assists/src/utils.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 0038a9764..02de902d6 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -7,13 +7,15 @@ use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type}; | |||
7 | use ra_ide_db::RootDatabase; | 7 | use ra_ide_db::RootDatabase; |
8 | use ra_syntax::{ | 8 | use ra_syntax::{ |
9 | ast::{self, make, NameOwner}, | 9 | ast::{self, make, NameOwner}, |
10 | AstNode, SyntaxNode, T, | 10 | AstNode, |
11 | SyntaxKind::*, | ||
12 | SyntaxNode, TextSize, T, | ||
11 | }; | 13 | }; |
12 | use rustc_hash::FxHashSet; | 14 | use rustc_hash::FxHashSet; |
13 | 15 | ||
14 | use crate::assist_config::SnippetCap; | 16 | use crate::assist_config::SnippetCap; |
15 | 17 | ||
16 | pub(crate) use insert_use::insert_use_statement; | 18 | pub(crate) use insert_use::{find_insert_use_container, insert_use_statement}; |
17 | 19 | ||
18 | #[derive(Clone, Copy, Debug)] | 20 | #[derive(Clone, Copy, Debug)] |
19 | pub(crate) enum Cursor<'a> { | 21 | pub(crate) enum Cursor<'a> { |
@@ -120,6 +122,13 @@ pub(crate) fn resolve_target_trait( | |||
120 | } | 122 | } |
121 | } | 123 | } |
122 | 124 | ||
125 | pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize { | ||
126 | node.children_with_tokens() | ||
127 | .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) | ||
128 | .map(|it| it.text_range().start()) | ||
129 | .unwrap_or_else(|| node.text_range().start()) | ||
130 | } | ||
131 | |||
123 | pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr { | 132 | pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr { |
124 | if let Some(expr) = invert_special_case(&expr) { | 133 | if let Some(expr) = invert_special_case(&expr) { |
125 | return expr; | 134 | return expr; |
@@ -198,8 +207,7 @@ pub(crate) struct FamousDefs<'a, 'b>(pub(crate) &'a Semantics<'b, RootDatabase>, | |||
198 | #[allow(non_snake_case)] | 207 | #[allow(non_snake_case)] |
199 | impl FamousDefs<'_, '_> { | 208 | impl FamousDefs<'_, '_> { |
200 | #[cfg(test)] | 209 | #[cfg(test)] |
201 | pub(crate) const FIXTURE: &'static str = r#" | 210 | pub(crate) const FIXTURE: &'static str = r#"//- /libcore.rs crate:core |
202 | //- /libcore.rs crate:core | ||
203 | pub mod convert { | 211 | pub mod convert { |
204 | pub trait From<T> { | 212 | pub trait From<T> { |
205 | fn from(T) -> Self; | 213 | fn from(T) -> Self; |