diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-20 15:38:16 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-20 15:38:16 +0100 |
commit | 2e0b7b0159ed922693db48f3f94ed95b1827494a (patch) | |
tree | ede61469d8f4e180f0cfa7cbe00d889737d45551 /crates/ra_syntax/src/algo.rs | |
parent | 90f837829d4f2c1054751de2de695ba1c0b8ae5c (diff) | |
parent | 8a04372fec5f26a0650395a1e420fea062b3a7ab (diff) |
Merge #4057
4057: Fix panic in split_imports assist r=matklad a=matklad
The fix is admittedly quit literally just papering over.
Long-term, I see two more principled approaches:
* we switch to a fully tree-based impl, without parse . to_string
step; with this approach, there shouldn't be any panics. The results
might be nonsensical, but so was the original input.
* we preserve the invariant that re-parsing constructed node is an
identity, and make all the `make_xxx` method return an `Option`.
closes #4044
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/algo.rs')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index ea41bf85d..06df8495c 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -10,8 +10,8 @@ use ra_text_edit::TextEditBuilder; | |||
10 | use rustc_hash::FxHashMap; | 10 | use rustc_hash::FxHashMap; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken, | 13 | AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr, |
14 | TextRange, TextUnit, | 14 | SyntaxToken, TextRange, TextUnit, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | /// Returns ancestors of the node at the offset, sorted by length. This should | 17 | /// Returns ancestors of the node at the offset, sorted by length. This should |
@@ -90,6 +90,10 @@ pub fn neighbor<T: AstNode>(me: &T, direction: Direction) -> Option<T> { | |||
90 | me.syntax().siblings(direction).skip(1).find_map(T::cast) | 90 | me.syntax().siblings(direction).skip(1).find_map(T::cast) |
91 | } | 91 | } |
92 | 92 | ||
93 | pub fn has_errors(node: &SyntaxNode) -> bool { | ||
94 | node.children().any(|it| it.kind() == SyntaxKind::ERROR) | ||
95 | } | ||
96 | |||
93 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 97 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
94 | pub enum InsertPosition<T> { | 98 | pub enum InsertPosition<T> { |
95 | First, | 99 | First, |