Skip to content

Commit e4a3cc3

Browse files
committed
Add better snippet bits test
1 parent e9efb56 commit e4a3cc3

File tree

1 file changed

+54
-34
lines changed

1 file changed

+54
-34
lines changed

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

+54-34
Original file line numberDiff line numberDiff line change
@@ -2145,51 +2145,71 @@ fn bar(_: usize) {}
21452145
fn snippet_rendering_escape_snippet_bits() {
21462146
// only needed for snippet formats
21472147
let mut edit = TextEdit::builder();
2148-
edit.insert(0.into(), r"abc\def$".to_owned());
2149-
edit.insert(8.into(), r"ghi\jkl$".to_owned());
2148+
edit.insert(0.into(), r"$ab{}$c\def".to_owned());
2149+
edit.insert(8.into(), r"ghi\jk<-check_insert_here$".to_owned());
2150+
edit.insert(10.into(), r"a\\b\\c{}$".to_owned());
21502151
let edit = edit.finish();
2151-
let snippets =
2152-
SnippetEdit::new(vec![Snippet::Placeholder(TextRange::new(0.into(), 3.into()))]);
2152+
let snippets = SnippetEdit::new(vec![
2153+
Snippet::Placeholder(TextRange::new(1.into(), 9.into())),
2154+
Snippet::Tabstop(25.into()),
2155+
]);
21532156

21542157
check_rendered_snippets(
21552158
edit,
21562159
snippets,
21572160
expect![[r#"
2158-
[
2159-
SnippetTextEdit {
2160-
range: Range {
2161-
start: Position {
2162-
line: 0,
2163-
character: 0,
2164-
},
2165-
end: Position {
2166-
line: 0,
2167-
character: 0,
2161+
[
2162+
SnippetTextEdit {
2163+
range: Range {
2164+
start: Position {
2165+
line: 0,
2166+
character: 0,
2167+
},
2168+
end: Position {
2169+
line: 0,
2170+
character: 0,
2171+
},
21682172
},
2173+
new_text: "\\$${1:ab{}\\$c\\\\d}ef",
2174+
insert_text_format: Some(
2175+
Snippet,
2176+
),
2177+
annotation_id: None,
21692178
},
2170-
new_text: "${0:abc}\\\\def\\$",
2171-
insert_text_format: Some(
2172-
Snippet,
2173-
),
2174-
annotation_id: None,
2175-
},
2176-
SnippetTextEdit {
2177-
range: Range {
2178-
start: Position {
2179-
line: 0,
2180-
character: 8,
2179+
SnippetTextEdit {
2180+
range: Range {
2181+
start: Position {
2182+
line: 0,
2183+
character: 8,
2184+
},
2185+
end: Position {
2186+
line: 0,
2187+
character: 8,
2188+
},
21812189
},
2182-
end: Position {
2183-
line: 0,
2184-
character: 8,
2190+
new_text: "ghi\\\\jk$0<-check_insert_here\\$",
2191+
insert_text_format: Some(
2192+
Snippet,
2193+
),
2194+
annotation_id: None,
2195+
},
2196+
SnippetTextEdit {
2197+
range: Range {
2198+
start: Position {
2199+
line: 0,
2200+
character: 10,
2201+
},
2202+
end: Position {
2203+
line: 0,
2204+
character: 10,
2205+
},
21852206
},
2207+
new_text: "a\\\\b\\\\c{}$",
2208+
insert_text_format: None,
2209+
annotation_id: None,
21862210
},
2187-
new_text: "ghi\\jkl$",
2188-
insert_text_format: None,
2189-
annotation_id: None,
2190-
},
2191-
]
2192-
"#]],
2211+
]
2212+
"#]],
21932213
);
21942214
}
21952215

0 commit comments

Comments
 (0)