mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Fix panic in split_imports assist
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
This commit is contained in:
parent
90f837829d
commit
8a04372fec
3 changed files with 17 additions and 4 deletions
|
@ -10,8 +10,8 @@ use ra_text_edit::TextEditBuilder;
|
|||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken,
|
||||
TextRange, TextUnit,
|
||||
AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr,
|
||||
SyntaxToken, TextRange, TextUnit,
|
||||
};
|
||||
|
||||
/// 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> {
|
|||
me.syntax().siblings(direction).skip(1).find_map(T::cast)
|
||||
}
|
||||
|
||||
pub fn has_errors(node: &SyntaxNode) -> bool {
|
||||
node.children().any(|it| it.kind() == SyntaxKind::ERROR)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum InsertPosition<T> {
|
||||
First,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue