From ddc25d87ca3ae8d355f3ead885e9bbd45844f698 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 29 Dec 2020 12:54:48 +0100 Subject: Properly parse path separators in format-like postfix --- crates/completion/src/completions/postfix/format_like.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/completion/src/completions/postfix/format_like.rs') diff --git a/crates/completion/src/completions/postfix/format_like.rs b/crates/completion/src/completions/postfix/format_like.rs index 88ba86acb..3014fb13b 100644 --- a/crates/completion/src/completions/postfix/format_like.rs +++ b/crates/completion/src/completions/postfix/format_like.rs @@ -108,7 +108,8 @@ impl FormatStrParser { // "{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 @@ impl FormatStrParser { 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 @@ mod tests { 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 { -- cgit v1.2.3