diff options
| author | DropDemBits <r3usrlnd@gmail.com> | 2024-02-15 23:16:27 -0500 |
|---|---|---|
| committer | DropDemBits <r3usrlnd@gmail.com> | 2024-02-16 00:28:01 -0500 |
| commit | e9efb568f6d8b81d672ab0cbae0bb7b08c7ec2eb (patch) | |
| tree | 21a01147e856420c0a3707f8a6612b8e33b452e5 | |
| parent | b9b0d29b8e69b02457cfabe20c4c69cdb45f3cc5 (diff) | |
| download | rust-e9efb568f6d8b81d672ab0cbae0bb7b08c7ec2eb.tar.gz rust-e9efb568f6d8b81d672ab0cbae0bb7b08c7ec2eb.zip | |
Add dos line ending test
| -rw-r--r-- | crates/rust-analyzer/src/lsp/to_proto.rs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs index 60281202f84..9cce55c66f8 100644 --- a/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/crates/rust-analyzer/src/lsp/to_proto.rs @@ -1705,9 +1705,10 @@ fn bar(_: usize) {} expect: Expect, ) { let source = stdx::trim_indent(ra_fixture); + let endings = if source.contains('\r') { LineEndings::Dos } else { LineEndings::Unix }; let line_index = LineIndex { index: Arc::new(ide::LineIndex::new(&source)), - endings: LineEndings::Unix, + endings, encoding: PositionEncoding::Utf8, }; @@ -2609,6 +2610,43 @@ struct ProcMacro { ); } + #[test] + fn snippet_rendering_handle_dos_line_endings() { + // unix -> dos conversion should be handled after placing snippets + let mut edit = TextEdit::builder(); + edit.insert(6.into(), "\n\n->".to_owned()); + + let edit = edit.finish(); + let snippets = SnippetEdit::new(vec![Snippet::Tabstop(10.into())]); + + check_rendered_snippets_in_source( + "yeah\r\n<-tabstop here", + edit, + snippets, + expect![[r#" + [ + SnippetTextEdit { + range: Range { + start: Position { + line: 1, + character: 0, + }, + end: Position { + line: 1, + character: 0, + }, + }, + new_text: "\r\n\r\n->$0", + insert_text_format: Some( + Snippet, + ), + annotation_id: None, + }, + ] + "#]], + ) + } + // `Url` is not able to parse windows paths on unix machines. #[test] #[cfg(target_os = "windows")] |
