@@ -4,17 +4,18 @@ use super::specs::SimpleArgType;
44use super :: specs:: TagSpec ;
55
66/// Generate an LSP snippet pattern from an array of arguments
7+ #[ must_use]
78pub fn generate_snippet_from_args ( args : & [ Arg ] ) -> String {
89 let mut parts = Vec :: new ( ) ;
910 let mut placeholder_index = 1 ;
10-
11+
1112 for arg in args {
1213 // Skip optional args if we haven't seen any required args after them
1314 // This prevents generating snippets like: "{% for %}" when everything is optional
1415 if !arg. required && parts. is_empty ( ) {
1516 continue ;
1617 }
17-
18+
1819 let snippet_part = match & arg. arg_type {
1920 ArgType :: Simple ( simple_type) => match simple_type {
2021 SimpleArgType :: Literal => {
@@ -60,23 +61,24 @@ pub fn generate_snippet_from_args(args: &[Arg]) -> String {
6061 result
6162 }
6263 } ;
63-
64+
6465 parts. push ( snippet_part) ;
6566 }
66-
67+
6768 parts. join ( " " )
6869}
6970
7071/// Generate a complete LSP snippet for a tag including the tag name
72+ #[ must_use]
7173pub fn generate_snippet_for_tag ( tag_name : & str , spec : & TagSpec ) -> String {
7274 let args_snippet = generate_snippet_from_args ( & spec. args ) ;
73-
75+
7476 if args_snippet. is_empty ( ) {
7577 // Tag with no arguments
7678 tag_name. to_string ( )
7779 } else {
7880 // Tag with arguments
79- format ! ( "{} {}" , tag_name , args_snippet )
81+ format ! ( "{tag_name } {args_snippet}" )
8082 }
8183}
8284
@@ -110,61 +112,57 @@ mod tests {
110112 arg_type: ArgType :: Simple ( SimpleArgType :: Literal ) ,
111113 } ,
112114 ] ;
113-
115+
114116 let snippet = generate_snippet_from_args ( & args) ;
115117 assert_eq ! ( snippet, "${1:item} in ${2:items} ${3:reversed}" ) ;
116118 }
117-
119+
118120 #[ test]
119121 fn test_snippet_for_if_tag ( ) {
120- let args = vec ! [
121- Arg {
122- name: "condition" . to_string( ) ,
123- required: true ,
124- arg_type: ArgType :: Simple ( SimpleArgType :: Expression ) ,
125- } ,
126- ] ;
127-
122+ let args = vec ! [ Arg {
123+ name: "condition" . to_string( ) ,
124+ required: true ,
125+ arg_type: ArgType :: Simple ( SimpleArgType :: Expression ) ,
126+ } ] ;
127+
128128 let snippet = generate_snippet_from_args ( & args) ;
129129 assert_eq ! ( snippet, "${1:condition}" ) ;
130130 }
131-
131+
132132 #[ test]
133133 fn test_snippet_for_autoescape_tag ( ) {
134- let args = vec ! [
135- Arg {
136- name : "mode" . to_string ( ) ,
137- required : true ,
138- arg_type : ArgType :: Choice { choice: vec![ "on" . to_string( ) , "off" . to_string( ) ] } ,
134+ let args = vec ! [ Arg {
135+ name : "mode" . to_string ( ) ,
136+ required : true ,
137+ arg_type : ArgType :: Choice {
138+ choice: vec![ "on" . to_string( ) , "off" . to_string( ) ] ,
139139 } ,
140- ] ;
141-
140+ } ] ;
141+
142142 let snippet = generate_snippet_from_args ( & args) ;
143143 assert_eq ! ( snippet, "${1|on,off|}" ) ;
144144 }
145-
145+
146146 #[ test]
147147 fn test_snippet_for_extends_tag ( ) {
148- let args = vec ! [
149- Arg {
150- name: "template" . to_string( ) ,
151- required: true ,
152- arg_type: ArgType :: Simple ( SimpleArgType :: String ) ,
153- } ,
154- ] ;
155-
148+ let args = vec ! [ Arg {
149+ name: "template" . to_string( ) ,
150+ required: true ,
151+ arg_type: ArgType :: Simple ( SimpleArgType :: String ) ,
152+ } ] ;
153+
156154 let snippet = generate_snippet_from_args ( & args) ;
157155 assert_eq ! ( snippet, "\" ${1:template}\" " ) ;
158156 }
159-
157+
160158 #[ test]
161159 fn test_snippet_for_csrf_token_tag ( ) {
162160 let args = vec ! [ ] ;
163-
161+
164162 let snippet = generate_snippet_from_args ( & args) ;
165163 assert_eq ! ( snippet, "" ) ;
166164 }
167-
165+
168166 #[ test]
169167 fn test_snippet_for_url_tag ( ) {
170168 let args = vec ! [
@@ -189,8 +187,8 @@ mod tests {
189187 arg_type: ArgType :: Simple ( SimpleArgType :: Variable ) ,
190188 } ,
191189 ] ;
192-
190+
193191 let snippet = generate_snippet_from_args ( & args) ;
194192 assert_eq ! ( snippet, "\" ${1:view_name}\" ${2:args} ${3:as} ${4:varname}" ) ;
195193 }
196- }
194+ }
0 commit comments