From ea320141c6f87383880878b91182355c9ad7dc7b Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sat, 12 Sep 2020 17:14:17 +0300 Subject: Add postfix completion for format-like string literals --- crates/ide/src/completion/completion_context.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/ide/src/completion/completion_context.rs') diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs index 671b13328..842d1987c 100644 --- a/crates/ide/src/completion/completion_context.rs +++ b/crates/ide/src/completion/completion_context.rs @@ -74,6 +74,8 @@ pub(crate) struct CompletionContext<'a> { pub(super) is_pattern_call: bool, /// If this is a macro call, i.e. the () are already there. pub(super) is_macro_call: bool, + /// If this is a string literal, like "lorem ipsum". + pub(super) is_string_literal: bool, pub(super) is_path_type: bool, pub(super) has_type_args: bool, pub(super) attribute_under_caret: Option, @@ -156,6 +158,7 @@ impl<'a> CompletionContext<'a> { is_call: false, is_pattern_call: false, is_macro_call: false, + is_string_literal: false, is_path_type: false, has_type_args: false, dot_receiver_is_ambiguous_float_literal: false, @@ -469,7 +472,13 @@ impl<'a> CompletionContext<'a> { } } else { false - } + }; + + self.is_string_literal = if let Some(ast::Expr::Literal(l)) = &self.dot_receiver { + matches!(l.kind(), ast::LiteralKind::String { .. }) + } else { + false + }; } if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { // As above -- cgit v1.2.3