]> git.lizzy.rs Git - rust.git/commitdiff
Properly parse path separators in format-like postfix
authorLukas Wirth <lukastw97@gmail.com>
Tue, 29 Dec 2020 11:54:48 +0000 (12:54 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Tue, 29 Dec 2020 12:10:35 +0000 (13:10 +0100)
crates/completion/src/completions/postfix/format_like.rs

index 88ba86acb685fb8bfe0c99c3795c51cd614ebe6d..3014fb13b129c89cd020b7afa014c63d50473f71 100644 (file)
@@ -108,7 +108,8 @@ pub(crate) fn parse(&mut self) -> Result<(), ()> {
         // "{MyStruct { val_a: 0, val_b: 1 }}".
         let mut inexpr_open_count = 0;
 
-        for chr in self.input.chars() {
+        let mut chars = self.input.chars().peekable();
+        while let Some(chr) = chars.next() {
             match (self.state, chr) {
                 (State::NotExpr, '{') => {
                     self.output.push(chr);
@@ -157,6 +158,11 @@ pub(crate) fn parse(&mut self) -> Result<(), ()> {
                         inexpr_open_count -= 1;
                     }
                 }
+                (State::Expr, ':') if chars.peek().copied() == Some(':') => {
+                    // path seperator
+                    current_expr.push_str("::");
+                    chars.next();
+                }
                 (State::Expr, ':') => {
                     if inexpr_open_count == 0 {
                         // We're outside of braces, thus assume that it's a specifier, like "{Some(value):?}"
@@ -249,6 +255,9 @@ fn format_str_parser() {
                 expect![["{:?}; SomeStruct { val_a: 0, val_b: 1 }"]],
             ),
             ("{     2 + 2        }", expect![["{}; 2 + 2"]]),
+            ("{strsim::jaro_winkle(a)}", expect![["{}; strsim::jaro_winkle(a)"]]),
+            ("{foo::bar::baz()}", expect![["{}; foo::bar::baz()"]]),
+            ("{foo::bar():?}", expect![["{:?}; foo::bar()"]]),
         ];
 
         for (input, output) in test_vector {