diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/extend_selection.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/join_lines.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide_api/src/matching_brace.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/syntax_highlighting.rs | 4 |
5 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index e23d178b0..9a0eb2c14 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -4,7 +4,7 @@ use itertools::Itertools; | |||
4 | use hir::{source_binder, diagnostics::{Diagnostic as _, DiagnosticSink}}; | 4 | use hir::{source_binder, diagnostics::{Diagnostic as _, DiagnosticSink}}; |
5 | use ra_db::SourceDatabase; | 5 | use ra_db::SourceDatabase; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | Location, SourceFile, SyntaxKind, TextRange, SyntaxNode, | 7 | T, Location, SourceFile, TextRange, SyntaxNode, |
8 | ast::{self, AstNode, NamedFieldList, NamedField}, | 8 | ast::{self, AstNode, NamedFieldList, NamedField}, |
9 | }; | 9 | }; |
10 | use ra_assists::ast_editor::{AstEditor, AstBuilder}; | 10 | use ra_assists::ast_editor::{AstEditor, AstBuilder}; |
@@ -130,9 +130,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( | |||
130 | single_use_tree: &ast::UseTree, | 130 | single_use_tree: &ast::UseTree, |
131 | ) -> Option<TextEdit> { | 131 | ) -> Option<TextEdit> { |
132 | let use_tree_list_node = single_use_tree.syntax().parent()?; | 132 | let use_tree_list_node = single_use_tree.syntax().parent()?; |
133 | if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() | 133 | if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() == T![self] { |
134 | == SyntaxKind::SELF_KW | ||
135 | { | ||
136 | let start = use_tree_list_node.prev_sibling_or_token()?.range().start(); | 134 | let start = use_tree_list_node.prev_sibling_or_token()?.range().start(); |
137 | let end = use_tree_list_node.range().end(); | 135 | let end = use_tree_list_node.range().end(); |
138 | let range = TextRange::from_to(start, end); | 136 | let range = TextRange::from_to(start, end); |
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 163fa8c3c..4553faad0 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs | |||
@@ -157,7 +157,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> { | |||
157 | }) | 157 | }) |
158 | .next() | 158 | .next() |
159 | .and_then(|it| it.as_token()) | 159 | .and_then(|it| it.as_token()) |
160 | .filter(|node| node.kind() == COMMA) | 160 | .filter(|node| node.kind() == T![,]) |
161 | } | 161 | } |
162 | 162 | ||
163 | if let Some(comma_node) = nearby_comma(node, Direction::Prev) { | 163 | if let Some(comma_node) = nearby_comma(node, Direction::Prev) { |
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs index 598717311..4ca005466 100644 --- a/crates/ra_ide_api/src/join_lines.rs +++ b/crates/ra_ide_api/src/join_lines.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | T, | ||
3 | SourceFile, TextRange, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken, | 4 | SourceFile, TextRange, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken, |
4 | SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK}, | 5 | SyntaxKind::{self, WHITESPACE}, |
5 | algo::{find_covering_element, non_trivia_sibling}, | 6 | algo::{find_covering_element, non_trivia_sibling}, |
6 | ast::{self, AstNode, AstToken}, | 7 | ast::{self, AstNode, AstToken}, |
7 | Direction, | 8 | Direction, |
@@ -89,7 +90,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: SyntaxToken, offset: TextUn | |||
89 | if is_trailing_comma(prev.kind(), next.kind()) { | 90 | if is_trailing_comma(prev.kind(), next.kind()) { |
90 | // Removes: trailing comma, newline (incl. surrounding whitespace) | 91 | // Removes: trailing comma, newline (incl. surrounding whitespace) |
91 | edit.delete(TextRange::from_to(prev.range().start(), token.range().end())); | 92 | edit.delete(TextRange::from_to(prev.range().start(), token.range().end())); |
92 | } else if prev.kind() == COMMA && next.kind() == R_CURLY { | 93 | } else if prev.kind() == T![,] && next.kind() == T!['}'] { |
93 | // Removes: comma, newline (incl. surrounding whitespace) | 94 | // Removes: comma, newline (incl. surrounding whitespace) |
94 | let space = if let Some(left) = prev.prev_sibling_or_token() { | 95 | let space = if let Some(left) = prev.prev_sibling_or_token() { |
95 | compute_ws(left.kind(), next.kind()) | 96 | compute_ws(left.kind(), next.kind()) |
@@ -116,7 +117,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: SyntaxToken, offset: TextUn | |||
116 | 117 | ||
117 | fn has_comma_after(node: &SyntaxNode) -> bool { | 118 | fn has_comma_after(node: &SyntaxNode) -> bool { |
118 | match non_trivia_sibling(node.into(), Direction::Next) { | 119 | match non_trivia_sibling(node.into(), Direction::Next) { |
119 | Some(n) => n.kind() == COMMA, | 120 | Some(n) => n.kind() == T![,], |
120 | _ => false, | 121 | _ => false, |
121 | } | 122 | } |
122 | } | 123 | } |
@@ -150,7 +151,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, token: SyntaxToken) -> Optio | |||
150 | 151 | ||
151 | fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { | 152 | fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { |
152 | match (left, right) { | 153 | match (left, right) { |
153 | (COMMA, R_PAREN) | (COMMA, R_BRACK) => true, | 154 | (T![,], T![')']) | (T![,], T![']']) => true, |
154 | _ => false, | 155 | _ => false, |
155 | } | 156 | } |
156 | } | 157 | } |
diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs index bebd16a69..eaa4b620c 100644 --- a/crates/ra_ide_api/src/matching_brace.rs +++ b/crates/ra_ide_api/src/matching_brace.rs | |||
@@ -1,13 +1,14 @@ | |||
1 | use ra_syntax::{ | 1 | use ra_syntax::{ |
2 | SourceFile, TextUnit, | 2 | SourceFile, TextUnit, |
3 | algo::find_token_at_offset, | 3 | algo::find_token_at_offset, |
4 | SyntaxKind::{self, *}, | 4 | SyntaxKind::{self}, |
5 | ast::AstNode, | 5 | ast::AstNode, |
6 | T | ||
6 | }; | 7 | }; |
7 | 8 | ||
8 | pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { | 9 | pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { |
9 | const BRACES: &[SyntaxKind] = | 10 | const BRACES: &[SyntaxKind] = |
10 | &[L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE]; | 11 | &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]]; |
11 | let (brace_node, brace_idx) = find_token_at_offset(file.syntax(), offset) | 12 | let (brace_node, brace_idx) = find_token_at_offset(file.syntax(), offset) |
12 | .filter_map(|node| { | 13 | .filter_map(|node| { |
13 | let idx = BRACES.iter().position(|&brace| brace == node.kind())?; | 14 | let idx = BRACES.iter().position(|&brace| brace == node.kind())?; |
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index d9a28d2b5..a03b13839 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | 2 | ||
3 | use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement}; | 3 | use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement, T}; |
4 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
5 | 5 | ||
6 | use crate::{FileId, db::RootDatabase}; | 6 | use crate::{FileId, db::RootDatabase}; |
@@ -40,7 +40,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
40 | let mut range_end = name_ref.syntax().range().end(); | 40 | let mut range_end = name_ref.syntax().range().end(); |
41 | for sibling in path.syntax().siblings_with_tokens(Direction::Next) { | 41 | for sibling in path.syntax().siblings_with_tokens(Direction::Next) { |
42 | match sibling.kind() { | 42 | match sibling.kind() { |
43 | EXCL | IDENT => range_end = sibling.range().end(), | 43 | T![!] | IDENT => range_end = sibling.range().end(), |
44 | _ => (), | 44 | _ => (), |
45 | } | 45 | } |
46 | } | 46 | } |