Unnamed repository; edit this file 'description' to name the repository.
fix: strange behavior onEnter deleting $bar solved
by reusing the function escape_snippet_bits used in postfix.rs, the issue seems to be gone completely. made one test cases, using $bar as per the issue #22596 by kpreid. tried making a $0 test case but although it was working on the IDE, the test case always failed. a possible improvement would be moving escape_snippet_bits to place where both postfix.rs and on_enter.rs can see it, but im not sure where I would do that...
José 5 weeks ago
parent 5be5e89 · commit 9b1bffd
-rw-r--r--crates/ide/src/typing/on_enter.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/crates/ide/src/typing/on_enter.rs b/crates/ide/src/typing/on_enter.rs
index 7d04594a5b..4811dd69e0 100644
--- a/crates/ide/src/typing/on_enter.rs
+++ b/crates/ide/src/typing/on_enter.rs
@@ -108,12 +108,19 @@ fn on_enter_in_comment(
Some(edit)
}
+// for lack of a better place to put this function
+fn escape_snippet_bits(text: &mut String) {
+ stdx::replace(text, '\\', "\\\\");
+ stdx::replace(text, '$', "\\$");
+}
+
fn on_enter_in_braces(l_curly: SyntaxToken, position: FilePosition) -> Option<TextEdit> {
if l_curly.text_range().end() != position.offset {
return None;
}
- let (r_curly, content) = brace_contents_on_same_line(&l_curly)?;
+ let (r_curly, mut content) = brace_contents_on_same_line(&l_curly)?;
+ escape_snippet_bits(&mut content);
let indent = IndentLevel::from_token(&l_curly);
Some(TextEdit::replace(
TextRange::new(position.offset, r_curly.text_range().start()),
@@ -683,4 +690,22 @@ use path::{$0
"#,
);
}
+
+ #[test]
+ fn escapes_dollar_sign_in_brace_contents() {
+ do_check(
+ r#"
+fn f() {
+ const {$0$bar};
+}
+"#,
+ r#"
+fn f() {
+ const {
+ $0\$bar
+ };
+}
+"#,
+ );
+ }
}