@@ -18,23 +18,22 @@ use crate::completion::{
18
18
complete_postfix:: postfix_snippet, completion_config:: SnippetCap ,
19
19
completion_context:: CompletionContext , completion_item:: Completions ,
20
20
} ;
21
- use syntax:: ast;
21
+ use syntax:: ast:: { self , AstToken } ;
22
22
23
23
pub ( super ) fn add_format_like_completions (
24
24
acc : & mut Completions ,
25
25
ctx : & CompletionContext ,
26
26
dot_receiver : & ast:: Expr ,
27
27
cap : SnippetCap ,
28
- receiver_text : & str ,
28
+ receiver_text : & ast :: String ,
29
29
) {
30
- if ! is_string_literal ( receiver_text) {
30
+ let input = match string_literal_contents ( receiver_text) {
31
31
// It's not a string literal, do not parse input.
32
- return ;
33
- }
34
-
35
- let input = & receiver_text[ 1 ..receiver_text. len ( ) - 1 ] ;
32
+ Some ( input) => input,
33
+ None => return ,
34
+ } ;
36
35
37
- let mut parser = FormatStrParser :: new ( input. to_owned ( ) ) ;
36
+ let mut parser = FormatStrParser :: new ( input) ;
38
37
39
38
if parser. parse ( ) . is_ok ( ) {
40
39
for kind in PostfixKind :: all_suggestions ( ) {
@@ -47,11 +46,13 @@ pub(super) fn add_format_like_completions(
47
46
}
48
47
49
48
/// Checks whether provided item is a string literal.
50
- fn is_string_literal ( item : & str ) -> bool {
51
- if item. len ( ) < 2 {
52
- return false ;
49
+ fn string_literal_contents ( item : & ast:: String ) -> Option < String > {
50
+ let item = item. text ( ) ;
51
+ if item. len ( ) >= 2 && item. starts_with ( "\" " ) && item. ends_with ( "\" " ) {
52
+ return Some ( item[ 1 ..item. len ( ) - 1 ] . to_owned ( ) ) ;
53
53
}
54
- item. starts_with ( "\" " ) && item. ends_with ( "\" " )
54
+
55
+ None
55
56
}
56
57
57
58
/// Parser for a format-like string. It is more allowing in terms of string contents,
0 commit comments