diff options
author | Sergey Parilin <[email protected]> | 2019-05-15 13:35:47 +0100 |
---|---|---|
committer | Sergey Parilin <[email protected]> | 2019-05-15 13:35:47 +0100 |
commit | 993abedd77cf23ce2281b6c8e60cab49ab4fa97e (patch) | |
tree | b8693ce808a9ca2e7eaae5013644a1082fc7bb17 /crates/ra_assists/src | |
parent | d77175ce28da45960a89811f273b6c614d7a9413 (diff) |
apply T! macro where it is possible
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r-- | crates/ra_assists/src/add_explicit_type.rs | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/ast_editor.rs | 14 | ||||
-rw-r--r-- | crates/ra_assists/src/auto_import.rs | 7 | ||||
-rw-r--r-- | crates/ra_assists/src/change_visibility.rs | 5 | ||||
-rw-r--r-- | crates/ra_assists/src/flip_comma.rs | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/remove_dbg.rs | 8 | ||||
-rw-r--r-- | crates/ra_assists/src/split_import.rs | 5 |
7 files changed, 24 insertions, 23 deletions
diff --git a/crates/ra_assists/src/add_explicit_type.rs b/crates/ra_assists/src/add_explicit_type.rs index cb0ac9885..f3ed74b7f 100644 --- a/crates/ra_assists/src/add_explicit_type.rs +++ b/crates/ra_assists/src/add_explicit_type.rs | |||
@@ -3,7 +3,7 @@ use hir::{ | |||
3 | db::HirDatabase, | 3 | db::HirDatabase, |
4 | }; | 4 | }; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | SyntaxKind, | 6 | T, |
7 | ast::{LetStmt, PatKind, NameOwner, AstNode} | 7 | ast::{LetStmt, PatKind, NameOwner, AstNode} |
8 | }; | 8 | }; |
9 | 9 | ||
@@ -24,7 +24,7 @@ pub(crate) fn add_explicit_type(mut ctx: AssistCtx<impl HirDatabase>) -> Option< | |||
24 | let name = pat.name()?; | 24 | let name = pat.name()?; |
25 | let name_range = name.syntax().range(); | 25 | let name_range = name.syntax().range(); |
26 | // Assist not applicable if the type has already been specified | 26 | // Assist not applicable if the type has already been specified |
27 | if stmt.syntax().children_with_tokens().any(|child| child.kind() == SyntaxKind::COLON) { | 27 | if stmt.syntax().children_with_tokens().any(|child| child.kind() == T![:]) { |
28 | return None; | 28 | return None; |
29 | } | 29 | } |
30 | // Infer type | 30 | // Infer type |
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index aa7aeaabb..9afcac01a 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs | |||
@@ -2,7 +2,7 @@ use std::{iter, ops::RangeInclusive}; | |||
2 | 2 | ||
3 | use arrayvec::ArrayVec; | 3 | use arrayvec::ArrayVec; |
4 | use ra_text_edit::TextEditBuilder; | 4 | use ra_text_edit::TextEditBuilder; |
5 | use ra_syntax::{AstNode, TreeArc, ast, SyntaxKind::*, SyntaxElement, SourceFile, InsertPosition, Direction}; | 5 | use ra_syntax::{AstNode, TreeArc, ast, SyntaxKind::*, SyntaxElement, SourceFile, InsertPosition, Direction, T}; |
6 | use ra_fmt::leading_indent; | 6 | use ra_fmt::leading_indent; |
7 | use hir::Name; | 7 | use hir::Name; |
8 | 8 | ||
@@ -49,7 +49,7 @@ impl<N: AstNode> AstEditor<N> { | |||
49 | 49 | ||
50 | fn do_make_multiline(&mut self) { | 50 | fn do_make_multiline(&mut self) { |
51 | let l_curly = | 51 | let l_curly = |
52 | match self.ast().syntax().children_with_tokens().find(|it| it.kind() == L_CURLY) { | 52 | match self.ast().syntax().children_with_tokens().find(|it| it.kind() == T!['{']) { |
53 | Some(it) => it, | 53 | Some(it) => it, |
54 | None => return, | 54 | None => return, |
55 | }; | 55 | }; |
@@ -124,7 +124,7 @@ impl AstEditor<ast::NamedFieldList> { | |||
124 | if let Some(comma) = $anchor | 124 | if let Some(comma) = $anchor |
125 | .syntax() | 125 | .syntax() |
126 | .siblings_with_tokens(Direction::Next) | 126 | .siblings_with_tokens(Direction::Next) |
127 | .find(|it| it.kind() == COMMA) | 127 | .find(|it| it.kind() == T![,]) |
128 | { | 128 | { |
129 | InsertPosition::After(comma) | 129 | InsertPosition::After(comma) |
130 | } else { | 130 | } else { |
@@ -154,7 +154,7 @@ impl AstEditor<ast::NamedFieldList> { | |||
154 | } | 154 | } |
155 | 155 | ||
156 | fn l_curly(&self) -> Option<SyntaxElement> { | 156 | fn l_curly(&self) -> Option<SyntaxElement> { |
157 | self.ast().syntax().children_with_tokens().find(|it| it.kind() == L_CURLY) | 157 | self.ast().syntax().children_with_tokens().find(|it| it.kind() == T!['{']) |
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
@@ -188,7 +188,7 @@ impl AstEditor<ast::ItemList> { | |||
188 | } | 188 | } |
189 | 189 | ||
190 | fn l_curly(&self) -> Option<SyntaxElement> { | 190 | fn l_curly(&self) -> Option<SyntaxElement> { |
191 | self.ast().syntax().children_with_tokens().find(|it| it.kind() == L_CURLY) | 191 | self.ast().syntax().children_with_tokens().find(|it| it.kind() == T!['{']) |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
@@ -290,7 +290,7 @@ fn ast_node_from_file_text<N: AstNode>(text: &str) -> TreeArc<N> { | |||
290 | 290 | ||
291 | mod tokens { | 291 | mod tokens { |
292 | use once_cell::sync::Lazy; | 292 | use once_cell::sync::Lazy; |
293 | use ra_syntax::{AstNode, SourceFile, TreeArc, SyntaxToken, SyntaxKind::*}; | 293 | use ra_syntax::{AstNode, SourceFile, TreeArc, SyntaxToken, SyntaxKind::*, T}; |
294 | 294 | ||
295 | static SOURCE_FILE: Lazy<TreeArc<SourceFile>> = Lazy::new(|| SourceFile::parse(",\n; ;")); | 295 | static SOURCE_FILE: Lazy<TreeArc<SourceFile>> = Lazy::new(|| SourceFile::parse(",\n; ;")); |
296 | 296 | ||
@@ -299,7 +299,7 @@ mod tokens { | |||
299 | .syntax() | 299 | .syntax() |
300 | .descendants_with_tokens() | 300 | .descendants_with_tokens() |
301 | .filter_map(|it| it.as_token()) | 301 | .filter_map(|it| it.as_token()) |
302 | .find(|it| it.kind() == COMMA) | 302 | .find(|it| it.kind() == T![,]) |
303 | .unwrap() | 303 | .unwrap() |
304 | } | 304 | } |
305 | 305 | ||
diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs index 7c856c19b..1566cf179 100644 --- a/crates/ra_assists/src/auto_import.rs +++ b/crates/ra_assists/src/auto_import.rs | |||
@@ -2,8 +2,9 @@ use ra_text_edit::TextEditBuilder; | |||
2 | use hir::{ self, db::HirDatabase}; | 2 | use hir::{ self, db::HirDatabase}; |
3 | 3 | ||
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | T, | ||
5 | ast::{ self, NameOwner }, AstNode, SyntaxNode, Direction, TextRange, SmolStr, | 6 | ast::{ self, NameOwner }, AstNode, SyntaxNode, Direction, TextRange, SmolStr, |
6 | SyntaxKind::{ PATH, PATH_SEGMENT, COLONCOLON, COMMA } | 7 | SyntaxKind::{ PATH, PATH_SEGMENT } |
7 | }; | 8 | }; |
8 | use crate::{ | 9 | use crate::{ |
9 | AssistId, | 10 | AssistId, |
@@ -23,7 +24,7 @@ fn collect_path_segments_raw<'a>( | |||
23 | children.next().map(|n| (n, n.kind())), | 24 | children.next().map(|n| (n, n.kind())), |
24 | ); | 25 | ); |
25 | match (first, second, third) { | 26 | match (first, second, third) { |
26 | (Some((subpath, PATH)), Some((_, COLONCOLON)), Some((segment, PATH_SEGMENT))) => { | 27 | (Some((subpath, PATH)), Some((_, T![::])), Some((segment, PATH_SEGMENT))) => { |
27 | path = ast::Path::cast(subpath.as_node()?)?; | 28 | path = ast::Path::cast(subpath.as_node()?)?; |
28 | segments.push(ast::PathSegment::cast(segment.as_node()?)?); | 29 | segments.push(ast::PathSegment::cast(segment.as_node()?)?); |
29 | } | 30 | } |
@@ -421,7 +422,7 @@ fn make_assist_add_in_tree_list( | |||
421 | let last = tree_list.use_trees().last(); | 422 | let last = tree_list.use_trees().last(); |
422 | if let Some(last) = last { | 423 | if let Some(last) = last { |
423 | let mut buf = String::new(); | 424 | let mut buf = String::new(); |
424 | let comma = last.syntax().siblings(Direction::Next).find(|n| n.kind() == COMMA); | 425 | let comma = last.syntax().siblings(Direction::Next).find(|n| n.kind() == T![,]); |
425 | let offset = if let Some(comma) = comma { | 426 | let offset = if let Some(comma) = comma { |
426 | comma.range().end() | 427 | comma.range().end() |
427 | } else { | 428 | } else { |
diff --git a/crates/ra_assists/src/change_visibility.rs b/crates/ra_assists/src/change_visibility.rs index c63470726..620f534b5 100644 --- a/crates/ra_assists/src/change_visibility.rs +++ b/crates/ra_assists/src/change_visibility.rs | |||
@@ -1,8 +1,9 @@ | |||
1 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | T, | ||
3 | AstNode, SyntaxNode, TextUnit, | 4 | AstNode, SyntaxNode, TextUnit, |
4 | ast::{self, VisibilityOwner, NameOwner}, | 5 | ast::{self, VisibilityOwner, NameOwner}, |
5 | SyntaxKind::{VISIBILITY, FN_KW, MOD_KW, STRUCT_KW, ENUM_KW, TRAIT_KW, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF, IDENT, WHITESPACE, COMMENT, ATTR}, | 6 | SyntaxKind::{VISIBILITY, FN_DEF, MODULE, STRUCT_DEF, ENUM_DEF, TRAIT_DEF, IDENT, WHITESPACE, COMMENT, ATTR}, |
6 | }; | 7 | }; |
7 | 8 | ||
8 | use crate::{AssistCtx, Assist, AssistId}; | 9 | use crate::{AssistCtx, Assist, AssistId}; |
@@ -16,7 +17,7 @@ pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi | |||
16 | 17 | ||
17 | fn add_vis(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 18 | fn add_vis(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
18 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { | 19 | let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { |
19 | FN_KW | MOD_KW | STRUCT_KW | ENUM_KW | TRAIT_KW => true, | 20 | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, |
20 | _ => false, | 21 | _ => false, |
21 | }); | 22 | }); |
22 | 23 | ||
diff --git a/crates/ra_assists/src/flip_comma.rs b/crates/ra_assists/src/flip_comma.rs index a9b108111..7626ffad3 100644 --- a/crates/ra_assists/src/flip_comma.rs +++ b/crates/ra_assists/src/flip_comma.rs | |||
@@ -1,14 +1,14 @@ | |||
1 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | T, | ||
3 | Direction, | 4 | Direction, |
4 | SyntaxKind::COMMA, | ||
5 | algo::non_trivia_sibling, | 5 | algo::non_trivia_sibling, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{AssistCtx, Assist, AssistId}; | 8 | use crate::{AssistCtx, Assist, AssistId}; |
9 | 9 | ||
10 | pub(crate) fn flip_comma(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 10 | pub(crate) fn flip_comma(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
11 | let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == COMMA)?; | 11 | let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == T![,])?; |
12 | let prev = non_trivia_sibling(comma.into(), Direction::Prev)?; | 12 | let prev = non_trivia_sibling(comma.into(), Direction::Prev)?; |
13 | let next = non_trivia_sibling(comma.into(), Direction::Next)?; | 13 | let next = non_trivia_sibling(comma.into(), Direction::Next)?; |
14 | ctx.add_action(AssistId("flip_comma"), "flip comma", |edit| { | 14 | ctx.add_action(AssistId("flip_comma"), "flip comma", |edit| { |
diff --git a/crates/ra_assists/src/remove_dbg.rs b/crates/ra_assists/src/remove_dbg.rs index ae9958f11..6e900f8ef 100644 --- a/crates/ra_assists/src/remove_dbg.rs +++ b/crates/ra_assists/src/remove_dbg.rs | |||
@@ -2,9 +2,7 @@ use hir::db::HirDatabase; | |||
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, AstNode}, | 3 | ast::{self, AstNode}, |
4 | TextUnit, | 4 | TextUnit, |
5 | SyntaxKind::{ | 5 | T |
6 | L_PAREN, R_PAREN, L_CURLY, R_CURLY, L_BRACK, R_BRACK, EXCL | ||
7 | }, | ||
8 | }; | 6 | }; |
9 | use crate::{AssistCtx, Assist, AssistId}; | 7 | use crate::{AssistCtx, Assist, AssistId}; |
10 | 8 | ||
@@ -64,7 +62,7 @@ fn is_valid_macrocall(macro_call: &ast::MacroCall, macro_name: &str) -> Option<b | |||
64 | // Make sure it is actually a dbg-macro call, dbg followed by ! | 62 | // Make sure it is actually a dbg-macro call, dbg followed by ! |
65 | let excl = path.syntax().next_sibling_or_token()?; | 63 | let excl = path.syntax().next_sibling_or_token()?; |
66 | 64 | ||
67 | if name_ref.text() != macro_name || excl.kind() != EXCL { | 65 | if name_ref.text() != macro_name || excl.kind() != T![!] { |
68 | return None; | 66 | return None; |
69 | } | 67 | } |
70 | 68 | ||
@@ -73,7 +71,7 @@ fn is_valid_macrocall(macro_call: &ast::MacroCall, macro_name: &str) -> Option<b | |||
73 | let last_child = node.last_child_or_token()?; | 71 | let last_child = node.last_child_or_token()?; |
74 | 72 | ||
75 | match (first_child.kind(), last_child.kind()) { | 73 | match (first_child.kind(), last_child.kind()) { |
76 | (L_PAREN, R_PAREN) | (L_BRACK, R_BRACK) | (L_CURLY, R_CURLY) => Some(true), | 74 | (T!['('], T![')']) | (T!['['], T![']']) | (T!['{'], T!['}']) => Some(true), |
77 | _ => Some(false), | 75 | _ => Some(false), |
78 | } | 76 | } |
79 | } | 77 | } |
diff --git a/crates/ra_assists/src/split_import.rs b/crates/ra_assists/src/split_import.rs index 57e0efaf2..881c5ecdc 100644 --- a/crates/ra_assists/src/split_import.rs +++ b/crates/ra_assists/src/split_import.rs | |||
@@ -2,14 +2,15 @@ use std::iter::successors; | |||
2 | 2 | ||
3 | use hir::db::HirDatabase; | 3 | use hir::db::HirDatabase; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | TextUnit, AstNode, SyntaxKind::COLONCOLON, | 5 | T, |
6 | TextUnit, AstNode, | ||
6 | ast, | 7 | ast, |
7 | }; | 8 | }; |
8 | 9 | ||
9 | use crate::{AssistCtx, Assist, AssistId}; | 10 | use crate::{AssistCtx, Assist, AssistId}; |
10 | 11 | ||
11 | pub(crate) fn split_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 12 | pub(crate) fn split_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
12 | let colon_colon = ctx.token_at_offset().find(|leaf| leaf.kind() == COLONCOLON)?; | 13 | let colon_colon = ctx.token_at_offset().find(|leaf| leaf.kind() == T![::])?; |
13 | let path = ast::Path::cast(colon_colon.parent())?; | 14 | let path = ast::Path::cast(colon_colon.parent())?; |
14 | let top_path = successors(Some(path), |it| it.parent_path()).last()?; | 15 | let top_path = successors(Some(path), |it| it.parent_path()).last()?; |
15 | 16 | ||