Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e8457bb

Browse files
Escape { and } as well
These are used in placeholder snippets, which may occur elsewhere in the insert text.
1 parent 1d8ed34 commit e8457bb

File tree

1 file changed

+77
-75
lines changed

1 file changed

+77
-75
lines changed

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

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,10 @@ fn merge_text_and_snippet_edits(
10011001
let mut new_text = current_indel.insert;
10021002

10031003
// find which snippet bits need to be escaped
1004-
let escape_places =
1005-
new_text.rmatch_indices(['\\', '$']).map(|(insert, _)| insert).collect_vec();
1004+
let escape_places = new_text
1005+
.rmatch_indices(['\\', '$', '{', '}'])
1006+
.map(|(insert, _)| insert)
1007+
.collect_vec();
10061008
let mut escape_places = escape_places.into_iter().peekable();
10071009
let mut escape_prior_bits = |new_text: &mut String, up_to: usize| {
10081010
for before in escape_places.peeking_take_while(|insert| *insert >= up_to) {
@@ -2173,7 +2175,7 @@ fn bar(_: usize) {}
21732175
character: 0,
21742176
},
21752177
},
2176-
new_text: "\\$${1:ab{}\\$c\\\\d}ef",
2178+
new_text: "\\$${1:ab\\{\\}\\$c\\\\d}ef",
21772179
insert_text_format: Some(
21782180
Snippet,
21792181
),
@@ -2242,41 +2244,41 @@ struct ProcMacro {
22422244
edit,
22432245
snippets,
22442246
expect![[r#"
2245-
[
2246-
SnippetTextEdit {
2247-
range: Range {
2248-
start: Position {
2249-
line: 1,
2250-
character: 4,
2251-
},
2252-
end: Position {
2253-
line: 1,
2254-
character: 13,
2255-
},
2256-
},
2257-
new_text: "let",
2258-
insert_text_format: None,
2259-
annotation_id: None,
2260-
},
2261-
SnippetTextEdit {
2262-
range: Range {
2263-
start: Position {
2264-
line: 1,
2265-
character: 14,
2266-
},
2267-
end: Position {
2268-
line: 3,
2269-
character: 5,
2270-
},
2271-
},
2272-
new_text: "0ドルdisabled = false;\n ProcMacro {\n disabled,\n }",
2273-
insert_text_format: Some(
2274-
Snippet,
2275-
),
2276-
annotation_id: None,
2277-
},
2278-
]
2279-
"#]],
2247+
[
2248+
SnippetTextEdit {
2249+
range: Range {
2250+
start: Position {
2251+
line: 1,
2252+
character: 4,
2253+
},
2254+
end: Position {
2255+
line: 1,
2256+
character: 13,
2257+
},
2258+
},
2259+
new_text: "let",
2260+
insert_text_format: None,
2261+
annotation_id: None,
2262+
},
2263+
SnippetTextEdit {
2264+
range: Range {
2265+
start: Position {
2266+
line: 1,
2267+
character: 14,
2268+
},
2269+
end: Position {
2270+
line: 3,
2271+
character: 5,
2272+
},
2273+
},
2274+
new_text: "0ドルdisabled = false;\n ProcMacro \\{\n disabled,\n \\}",
2275+
insert_text_format: Some(
2276+
Snippet,
2277+
),
2278+
annotation_id: None,
2279+
},
2280+
]
2281+
"#]],
22802282
);
22812283
}
22822284

@@ -2306,41 +2308,41 @@ struct P {
23062308
edit,
23072309
snippets,
23082310
expect![[r#"
2309-
[
2310-
SnippetTextEdit {
2311-
range: Range {
2312-
start: Position {
2313-
line: 1,
2314-
character: 4,
2315-
},
2316-
end: Position {
2317-
line: 1,
2318-
character: 5,
2319-
},
2320-
},
2321-
new_text: "let",
2322-
insert_text_format: None,
2323-
annotation_id: None,
2324-
},
2325-
SnippetTextEdit {
2326-
range: Range {
2327-
start: Position {
2328-
line: 1,
2329-
character: 6,
2330-
},
2331-
end: Position {
2332-
line: 3,
2333-
character: 5,
2334-
},
2335-
},
2336-
new_text: "0ドルdisabled = false;\n ProcMacro {\n disabled,\n }",
2337-
insert_text_format: Some(
2338-
Snippet,
2339-
),
2340-
annotation_id: None,
2341-
},
2342-
]
2343-
"#]],
2311+
[
2312+
SnippetTextEdit {
2313+
range: Range {
2314+
start: Position {
2315+
line: 1,
2316+
character: 4,
2317+
},
2318+
end: Position {
2319+
line: 1,
2320+
character: 5,
2321+
},
2322+
},
2323+
new_text: "let",
2324+
insert_text_format: None,
2325+
annotation_id: None,
2326+
},
2327+
SnippetTextEdit {
2328+
range: Range {
2329+
start: Position {
2330+
line: 1,
2331+
character: 6,
2332+
},
2333+
end: Position {
2334+
line: 3,
2335+
character: 5,
2336+
},
2337+
},
2338+
new_text: "0ドルdisabled = false;\n ProcMacro \\{\n disabled,\n \\}",
2339+
insert_text_format: Some(
2340+
Snippet,
2341+
),
2342+
annotation_id: None,
2343+
},
2344+
]
2345+
"#]],
23442346
);
23452347
}
23462348

@@ -2398,7 +2400,7 @@ struct ProcMacro {
23982400
character: 5,
23992401
},
24002402
},
2401-
new_text: "${0:disabled} = false;\n ProcMacro {\n disabled,\n }",
2403+
new_text: "${0:disabled} = false;\n ProcMacro \\{\n disabled,\n \\}",
24022404
insert_text_format: Some(
24032405
Snippet,
24042406
),
@@ -2463,7 +2465,7 @@ struct P {
24632465
character: 5,
24642466
},
24652467
},
2466-
new_text: "${0:disabled} = false;\n ProcMacro {\n disabled,\n }",
2468+
new_text: "${0:disabled} = false;\n ProcMacro \\{\n disabled,\n \\}",
24672469
insert_text_format: Some(
24682470
Snippet,
24692471
),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /