264: check for empty range when extending in comment r=matklad a=vemoo

fix for #140 

Co-authored-by: Bernardo <berublan@gmail.com>
This commit is contained in:
bors[bot] 2018-12-08 17:43:15 +00:00
commit 5ad7547ce2

View File

@ -54,7 +54,12 @@ fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Optio
let from: TextUnit = (start_idx + 1).into();
let to: TextUnit = (cursor_position + end_idx).into();
Some(TextRange::from_to(from, to) + leaf.range().start())
let range = TextRange::from_to(from, to);
if range.is_empty() {
None
} else {
Some(range + leaf.range().start())
}
}
fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange {
@ -181,6 +186,20 @@ fn bar(){}
"#,
&["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"],
);
do_check(
r#"
// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
// pub enum Direction {
// <|> Next,
// Prev
// }
"#,
&[
"// Next,",
"// #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n// pub enum Direction {\n// Next,\n// Prev\n// }",
],
);
}
#[test]