Skip to content

Commit e9efb56

Browse files
committed
Add dos line ending test
1 parent b9b0d29 commit e9efb56

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

crates/rust-analyzer/src/lsp/to_proto.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -1705,9 +1705,10 @@ fn bar(_: usize) {}
17051705
expect: Expect,
17061706
) {
17071707
let source = stdx::trim_indent(ra_fixture);
1708+
let endings = if source.contains('\r') { LineEndings::Dos } else { LineEndings::Unix };
17081709
let line_index = LineIndex {
17091710
index: Arc::new(ide::LineIndex::new(&source)),
1710-
endings: LineEndings::Unix,
1711+
endings,
17111712
encoding: PositionEncoding::Utf8,
17121713
};
17131714

@@ -2609,6 +2610,43 @@ struct ProcMacro {
26092610
);
26102611
}
26112612

2613+
#[test]
2614+
fn snippet_rendering_handle_dos_line_endings() {
2615+
// unix -> dos conversion should be handled after placing snippets
2616+
let mut edit = TextEdit::builder();
2617+
edit.insert(6.into(), "\n\n->".to_owned());
2618+
2619+
let edit = edit.finish();
2620+
let snippets = SnippetEdit::new(vec![Snippet::Tabstop(10.into())]);
2621+
2622+
check_rendered_snippets_in_source(
2623+
"yeah\r\n<-tabstop here",
2624+
edit,
2625+
snippets,
2626+
expect![[r#"
2627+
[
2628+
SnippetTextEdit {
2629+
range: Range {
2630+
start: Position {
2631+
line: 1,
2632+
character: 0,
2633+
},
2634+
end: Position {
2635+
line: 1,
2636+
character: 0,
2637+
},
2638+
},
2639+
new_text: "\r\n\r\n->$0",
2640+
insert_text_format: Some(
2641+
Snippet,
2642+
),
2643+
annotation_id: None,
2644+
},
2645+
]
2646+
"#]],
2647+
)
2648+
}
2649+
26122650
// `Url` is not able to parse windows paths on unix machines.
26132651
#[test]
26142652
#[cfg(target_os = "windows")]

0 commit comments

Comments
 (0)