aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/display/short_label.rs5
-rw-r--r--crates/ra_ide_api/src/extend_selection.rs10
-rw-r--r--crates/ra_ide_api/src/folding_ranges.rs18
-rw-r--r--crates/ra_ide_api/src/join_lines.rs6
-rw-r--r--crates/ra_ide_api/src/syntax_tree.rs6
5 files changed, 22 insertions, 23 deletions
diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs
index be499e485..825a033ee 100644
--- a/crates/ra_ide_api/src/display/short_label.rs
+++ b/crates/ra_ide_api/src/display/short_label.rs
@@ -1,5 +1,4 @@
1use std::fmt::Write; 1use format_buf::format;
2
3use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 2use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner};
4 3
5pub(crate) trait ShortLabel { 4pub(crate) trait ShortLabel {
@@ -73,7 +72,7 @@ where
73 let mut buf = short_label_from_node(node, prefix)?; 72 let mut buf = short_label_from_node(node, prefix)?;
74 73
75 if let Some(type_ref) = node.ascribed_type() { 74 if let Some(type_ref) = node.ascribed_type() {
76 write!(buf, ": {}", type_ref.syntax()).unwrap(); 75 format!(buf, ": {}", type_ref.syntax());
77 } 76 }
78 77
79 Some(buf) 78 Some(buf)
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs
index 140820df6..f78c562af 100644
--- a/crates/ra_ide_api/src/extend_selection.rs
+++ b/crates/ra_ide_api/src/extend_selection.rs
@@ -2,7 +2,7 @@ use ra_db::SourceDatabase;
2use ra_syntax::{ 2use ra_syntax::{
3 algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, 3 algo::{find_covering_element, find_token_at_offset, TokenAtOffset},
4 ast::{self, AstNode, AstToken}, 4 ast::{self, AstNode, AstToken},
5 Direction, SyntaxElement, 5 Direction, NodeOrToken,
6 SyntaxKind::*, 6 SyntaxKind::*,
7 SyntaxNode, SyntaxToken, TextRange, TextUnit, T, 7 SyntaxNode, SyntaxToken, TextRange, TextUnit, T,
8}; 8};
@@ -53,7 +53,7 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange
53 return Some(leaf_range); 53 return Some(leaf_range);
54 }; 54 };
55 let node = match find_covering_element(root, range) { 55 let node = match find_covering_element(root, range) {
56 SyntaxElement::Token(token) => { 56 NodeOrToken::Token(token) => {
57 if token.text_range() != range { 57 if token.text_range() != range {
58 return Some(token.text_range()); 58 return Some(token.text_range());
59 } 59 }
@@ -64,7 +64,7 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange
64 } 64 }
65 token.parent() 65 token.parent()
66 } 66 }
67 SyntaxElement::Node(node) => node, 67 NodeOrToken::Node(node) => node,
68 }; 68 };
69 if node.text_range() != range { 69 if node.text_range() != range {
70 return Some(node.text_range()); 70 return Some(node.text_range());
@@ -153,8 +153,8 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
153 node.siblings_with_tokens(dir) 153 node.siblings_with_tokens(dir)
154 .skip(1) 154 .skip(1)
155 .skip_while(|node| match node { 155 .skip_while(|node| match node {
156 SyntaxElement::Node(_) => false, 156 NodeOrToken::Node(_) => false,
157 SyntaxElement::Token(it) => is_single_line_ws(it), 157 NodeOrToken::Token(it) => is_single_line_ws(it),
158 }) 158 })
159 .next() 159 .next()
160 .and_then(|it| it.into_token()) 160 .and_then(|it| it.into_token())
diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs
index 571d1c595..e60ae8cf6 100644
--- a/crates/ra_ide_api/src/folding_ranges.rs
+++ b/crates/ra_ide_api/src/folding_ranges.rs
@@ -2,7 +2,7 @@ use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 ast::{self, AstNode, AstToken, VisibilityOwner}, 4 ast::{self, AstNode, AstToken, VisibilityOwner},
5 Direction, SourceFile, SyntaxElement, 5 Direction, NodeOrToken, SourceFile,
6 SyntaxKind::{self, *}, 6 SyntaxKind::{self, *},
7 SyntaxNode, TextRange, 7 SyntaxNode, TextRange,
8}; 8};
@@ -31,8 +31,8 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
31 // Fold items that span multiple lines 31 // Fold items that span multiple lines
32 if let Some(kind) = fold_kind(element.kind()) { 32 if let Some(kind) = fold_kind(element.kind()) {
33 let is_multiline = match &element { 33 let is_multiline = match &element {
34 SyntaxElement::Node(node) => node.text().contains_char('\n'), 34 NodeOrToken::Node(node) => node.text().contains_char('\n'),
35 SyntaxElement::Token(token) => token.text().contains('\n'), 35 NodeOrToken::Token(token) => token.text().contains('\n'),
36 }; 36 };
37 if is_multiline { 37 if is_multiline {
38 res.push(Fold { range: element.text_range(), kind }); 38 res.push(Fold { range: element.text_range(), kind });
@@ -41,7 +41,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
41 } 41 }
42 42
43 match element { 43 match element {
44 SyntaxElement::Token(token) => { 44 NodeOrToken::Token(token) => {
45 // Fold groups of comments 45 // Fold groups of comments
46 if let Some(comment) = ast::Comment::cast(token) { 46 if let Some(comment) = ast::Comment::cast(token) {
47 if !visited_comments.contains(&comment) { 47 if !visited_comments.contains(&comment) {
@@ -53,7 +53,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
53 } 53 }
54 } 54 }
55 } 55 }
56 SyntaxElement::Node(node) => { 56 NodeOrToken::Node(node) => {
57 // Fold groups of imports 57 // Fold groups of imports
58 if node.kind() == USE_ITEM && !visited_imports.contains(&node) { 58 if node.kind() == USE_ITEM && !visited_imports.contains(&node) {
59 if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) { 59 if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) {
@@ -108,7 +108,7 @@ fn contiguous_range_for_group_unless(
108 let mut last = first.clone(); 108 let mut last = first.clone();
109 for element in first.siblings_with_tokens(Direction::Next) { 109 for element in first.siblings_with_tokens(Direction::Next) {
110 let node = match element { 110 let node = match element {
111 SyntaxElement::Token(token) => { 111 NodeOrToken::Token(token) => {
112 if let Some(ws) = ast::Whitespace::cast(token) { 112 if let Some(ws) = ast::Whitespace::cast(token) {
113 if !ws.spans_multiple_lines() { 113 if !ws.spans_multiple_lines() {
114 // Ignore whitespace without blank lines 114 // Ignore whitespace without blank lines
@@ -119,7 +119,7 @@ fn contiguous_range_for_group_unless(
119 // group ends here 119 // group ends here
120 break; 120 break;
121 } 121 }
122 SyntaxElement::Node(node) => node, 122 NodeOrToken::Node(node) => node,
123 }; 123 };
124 124
125 // Stop if we find a node that doesn't belong to the group 125 // Stop if we find a node that doesn't belong to the group
@@ -154,7 +154,7 @@ fn contiguous_range_for_comment(
154 let mut last = first.clone(); 154 let mut last = first.clone();
155 for element in first.syntax().siblings_with_tokens(Direction::Next) { 155 for element in first.syntax().siblings_with_tokens(Direction::Next) {
156 match element { 156 match element {
157 SyntaxElement::Token(token) => { 157 NodeOrToken::Token(token) => {
158 if let Some(ws) = ast::Whitespace::cast(token.clone()) { 158 if let Some(ws) = ast::Whitespace::cast(token.clone()) {
159 if !ws.spans_multiple_lines() { 159 if !ws.spans_multiple_lines() {
160 // Ignore whitespace without blank lines 160 // Ignore whitespace without blank lines
@@ -173,7 +173,7 @@ fn contiguous_range_for_comment(
173 // * A comment of a different flavor was reached 173 // * A comment of a different flavor was reached
174 break; 174 break;
175 } 175 }
176 SyntaxElement::Node(_) => break, 176 NodeOrToken::Node(_) => break,
177 }; 177 };
178 } 178 }
179 179
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs
index 7f25f2108..a2e4b6f3c 100644
--- a/crates/ra_ide_api/src/join_lines.rs
+++ b/crates/ra_ide_api/src/join_lines.rs
@@ -3,7 +3,7 @@ use ra_fmt::{compute_ws, extract_trivial_expression};
3use ra_syntax::{ 3use ra_syntax::{
4 algo::{find_covering_element, non_trivia_sibling}, 4 algo::{find_covering_element, non_trivia_sibling},
5 ast::{self, AstNode, AstToken}, 5 ast::{self, AstNode, AstToken},
6 Direction, SourceFile, SyntaxElement, 6 Direction, NodeOrToken, SourceFile,
7 SyntaxKind::{self, WHITESPACE}, 7 SyntaxKind::{self, WHITESPACE},
8 SyntaxNode, SyntaxToken, TextRange, TextUnit, T, 8 SyntaxNode, SyntaxToken, TextRange, TextUnit, T,
9}; 9};
@@ -23,8 +23,8 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
23 }; 23 };
24 24
25 let node = match find_covering_element(file.syntax(), range) { 25 let node = match find_covering_element(file.syntax(), range) {
26 SyntaxElement::Node(node) => node, 26 NodeOrToken::Node(node) => node,
27 SyntaxElement::Token(token) => token.parent(), 27 NodeOrToken::Token(token) => token.parent(),
28 }; 28 };
29 let mut edit = TextEditBuilder::default(); 29 let mut edit = TextEditBuilder::default();
30 for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) { 30 for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) {
diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs
index 76c50f6d6..a07e670fa 100644
--- a/crates/ra_ide_api/src/syntax_tree.rs
+++ b/crates/ra_ide_api/src/syntax_tree.rs
@@ -1,7 +1,7 @@
1use crate::db::RootDatabase; 1use crate::db::RootDatabase;
2use ra_db::SourceDatabase; 2use ra_db::SourceDatabase;
3use ra_syntax::{ 3use ra_syntax::{
4 algo, AstNode, SourceFile, SyntaxElement, 4 algo, AstNode, NodeOrToken, SourceFile,
5 SyntaxKind::{RAW_STRING, STRING}, 5 SyntaxKind::{RAW_STRING, STRING},
6 SyntaxToken, TextRange, 6 SyntaxToken, TextRange,
7}; 7};
@@ -16,8 +16,8 @@ pub(crate) fn syntax_tree(
16 let parse = db.parse(file_id); 16 let parse = db.parse(file_id);
17 if let Some(text_range) = text_range { 17 if let Some(text_range) = text_range {
18 let node = match algo::find_covering_element(parse.tree().syntax(), text_range) { 18 let node = match algo::find_covering_element(parse.tree().syntax(), text_range) {
19 SyntaxElement::Node(node) => node, 19 NodeOrToken::Node(node) => node,
20 SyntaxElement::Token(token) => { 20 NodeOrToken::Token(token) => {
21 if let Some(tree) = syntax_tree_for_string(&token, text_range) { 21 if let Some(tree) = syntax_tree_for_string(&token, text_range) {
22 return tree; 22 return tree;
23 } 23 }