about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-20 20:11:03 +0000
committerbors <bors@rust-lang.org>2024-02-20 20:11:03 +0000
commit543d7e98dbcc0668528dbf3f5b32d752882baa33 (patch)
tree3eb5b55c7a88c07fe8eb0540f312ce9ed400046b
parent4760d856bc8e97747364054a456c96252f134875 (diff)
parent07421c13d48918984bd51fad2cde529ebf23c5ae (diff)
downloadrust-543d7e98dbcc0668528dbf3f5b32d752882baa33.tar.gz
rust-543d7e98dbcc0668528dbf3f5b32d752882baa33.zip
Auto merge of #16618 - DropDemBits:structured-snippet-fix-escape-left-curly, r=Veykril
fix: Don't add `\` before `{`

Fixes #16607 for `{`. The `}` case is already fixed by #16475.

The [LSP snippet grammar](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax) only specifies that `$`, `}`, and `\` can be escaped with backslashes, but not `{`.
-rw-r--r--crates/rust-analyzer/src/lsp/to_proto.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs
index 4101d476cd3..481ebfefd4e 100644
--- a/crates/rust-analyzer/src/lsp/to_proto.rs
+++ b/crates/rust-analyzer/src/lsp/to_proto.rs
@@ -1002,10 +1002,8 @@ fn merge_text_and_snippet_edits(
             let mut new_text = current_indel.insert;
 
             // find which snippet bits need to be escaped
-            let escape_places = new_text
-                .rmatch_indices(['\\', '$', '{', '}'])
-                .map(|(insert, _)| insert)
-                .collect_vec();
+            let escape_places =
+                new_text.rmatch_indices(['\\', '$', '}']).map(|(insert, _)| insert).collect_vec();
             let mut escape_places = escape_places.into_iter().peekable();
             let mut escape_prior_bits = |new_text: &mut String, up_to: usize| {
                 for before in escape_places.peeking_take_while(|insert| *insert >= up_to) {
@@ -2176,7 +2174,7 @@ fn bar(_: usize) {}
                                 character: 0,
                             },
                         },
-                        new_text: "\\$${1:ab\\{\\}\\$c\\\\d}ef",
+                        new_text: "\\$${1:ab{\\}\\$c\\\\d}ef",
                         insert_text_format: Some(
                             Snippet,
                         ),
@@ -2272,7 +2270,7 @@ struct ProcMacro {
                                 character: 5,
                             },
                         },
-                        new_text: "$0disabled = false;\n    ProcMacro \\{\n        disabled,\n    \\}",
+                        new_text: "$0disabled = false;\n    ProcMacro {\n        disabled,\n    \\}",
                         insert_text_format: Some(
                             Snippet,
                         ),
@@ -2336,7 +2334,7 @@ struct P {
                                 character: 5,
                             },
                         },
-                        new_text: "$0disabled = false;\n    ProcMacro \\{\n        disabled,\n    \\}",
+                        new_text: "$0disabled = false;\n    ProcMacro {\n        disabled,\n    \\}",
                         insert_text_format: Some(
                             Snippet,
                         ),
@@ -2401,7 +2399,7 @@ struct ProcMacro {
                                 character: 5,
                             },
                         },
-                        new_text: "${0:disabled} = false;\n    ProcMacro \\{\n        disabled,\n    \\}",
+                        new_text: "${0:disabled} = false;\n    ProcMacro {\n        disabled,\n    \\}",
                         insert_text_format: Some(
                             Snippet,
                         ),
@@ -2466,7 +2464,7 @@ struct P {
                                 character: 5,
                             },
                         },
-                        new_text: "${0:disabled} = false;\n    ProcMacro \\{\n        disabled,\n    \\}",
+                        new_text: "${0:disabled} = false;\n    ProcMacro {\n        disabled,\n    \\}",
                         insert_text_format: Some(
                             Snippet,
                         ),