Skip to content

Commit ec0fb09

Browse files
flip optional to required and add deprecation attrs
1 parent 71c7176 commit ec0fb09

File tree

8 files changed

+68
-48
lines changed

8 files changed

+68
-48
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ tempfile = "3.23"
4848
pedantic = { level = "warn", priority = -1 }
4949
missing_errors_doc = "allow"
5050

51+
[workspace.lints.rust]
52+
# Allow deprecated warnings for legacy tagspecs (remove in v5.2.7)
53+
# NOTE: To see all deprecation warnings when removing legacy code in v5.2.7,
54+
# temporarily delete this `deprecated = "allow"` line
55+
deprecated = "allow"
56+
5157
[profile.dev.package]
5258
insta.opt-level = 3
5359
similar.opt-level = 3

crates/djls-conf/src/tagspecs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use serde::Deserialize;
44

5-
// DEPRECATION: Remove in v5.2.2 (after v5.2.0 and v5.2.1)
5+
// DEPRECATION: Remove in v5.2.7 (after v5.2.5 and v5.2.6)
66
pub mod legacy;
77

88
/// Root `TagSpec` document (v0.6.0)

crates/djls-conf/src/tagspecs/legacy.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use super::TagSpecDef;
1919
use super::TagTypeDef;
2020

2121
/// Legacy v0.4.0 tag specification (DEPRECATED)
22+
#[deprecated(since = "5.2.5", note = "Remove in v5.2.7")]
23+
#[allow(deprecated)]
2224
#[derive(Debug, Clone, Deserialize, PartialEq)]
2325
pub struct LegacyTagSpecDef {
2426
/// Tag name (e.g., "for", "if", "cache")
@@ -37,6 +39,8 @@ pub struct LegacyTagSpecDef {
3739
}
3840

3941
/// Legacy end tag specification
42+
#[deprecated(since = "5.2.5", note = "Remove in v5.2.7")]
43+
#[allow(deprecated)]
4044
#[derive(Debug, Clone, Deserialize, PartialEq)]
4145
pub struct LegacyEndTagDef {
4246
/// End tag name (e.g., "endfor", "endif")
@@ -50,6 +54,8 @@ pub struct LegacyEndTagDef {
5054
}
5155

5256
/// Legacy intermediate tag specification
57+
#[deprecated(since = "5.2.5", note = "Remove in v5.2.7")]
58+
#[allow(deprecated)]
5359
#[derive(Debug, Clone, Deserialize, PartialEq)]
5460
pub struct LegacyIntermediateTagDef {
5561
/// Intermediate tag name (e.g., "elif", "else")
@@ -60,6 +66,8 @@ pub struct LegacyIntermediateTagDef {
6066
}
6167

6268
/// Legacy tag argument specification
69+
#[deprecated(since = "5.2.5", note = "Remove in v5.2.7")]
70+
#[allow(deprecated)]
6371
#[derive(Debug, Clone, Deserialize, PartialEq)]
6472
pub struct LegacyTagArgDef {
6573
/// Argument name
@@ -73,6 +81,8 @@ pub struct LegacyTagArgDef {
7381
}
7482

7583
/// Legacy argument type specification
84+
#[deprecated(since = "5.2.5", note = "Remove in v5.2.7")]
85+
#[allow(deprecated)]
7686
#[derive(Debug, Clone, Deserialize, PartialEq)]
7787
#[serde(untagged)]
7888
pub enum LegacyArgTypeDef {
@@ -83,6 +93,7 @@ pub enum LegacyArgTypeDef {
8393
}
8494

8595
/// Legacy simple argument types
96+
#[deprecated(since = "5.2.5", note = "Remove in v5.2.7")]
8697
#[derive(Debug, Clone, Deserialize, PartialEq)]
8798
#[serde(rename_all = "lowercase")]
8899
pub enum LegacySimpleArgTypeDef {
@@ -101,6 +112,7 @@ fn default_true() -> bool {
101112
/// Convert a vector of legacy tagspecs to the new v0.6.0 hierarchical format
102113
///
103114
/// Groups tags by module and creates the appropriate library structure.
115+
#[deprecated(since = "5.2.5", note = "Remove in v5.2.7")]
104116
#[must_use]
105117
pub fn convert_legacy_tagspecs(legacy: Vec<LegacyTagSpecDef>) -> TagSpecDef {
106118
let mut modules: HashMap<String, Vec<TagDef>> = HashMap::new();
@@ -212,6 +224,8 @@ fn convert_legacy_arg(legacy: LegacyTagArgDef) -> TagArgDef {
212224

213225
#[cfg(test)]
214226
mod tests {
227+
#![allow(deprecated)]
228+
215229
use super::*;
216230

217231
#[test]

crates/djls-ide/src/snippets.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn generate_snippet_for_tag_with_end(tag_name: &str, spec: &TagSpec) -> Stri
9393

9494
// If this tag has a required end tag, include it in the snippet
9595
if let Some(end_tag) = &spec.end_tag {
96-
if !end_tag.optional {
96+
if end_tag.required {
9797
// Add closing %} for the opening tag, newline, cursor position, newline, then end tag
9898
snippet.push_str(" %}\n$0\n{% ");
9999
snippet.push_str(&end_tag.name);
@@ -197,7 +197,7 @@ mod tests {
197197
module: "django.template.loader_tags".into(),
198198
end_tag: Some(EndTag {
199199
name: "endblock".into(),
200-
optional: false,
200+
required: true,
201201
args: vec![TagArg::Var {
202202
name: "name".into(),
203203
required: false,
@@ -224,7 +224,7 @@ mod tests {
224224
module: "django.template.defaulttags".into(),
225225
end_tag: Some(EndTag {
226226
name: "endautoescape".into(),
227-
optional: false,
227+
required: true,
228228
args: Cow::Borrowed(&[]),
229229
}),
230230
intermediate_tags: Cow::Borrowed(&[]),

crates/djls-semantic/src/blocks/builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,19 +352,19 @@ impl<'db> BlockTreeBuilder<'db> {
352352

353353
fn finish(&mut self) {
354354
while let Some(frame) = self.stack.pop() {
355-
if self.index.is_end_optional(self.db, &frame.opener_name) {
356-
// No explicit closer: finalize last segment to end of input (best-effort)
357-
// We do not know the real end; leave as-is and extend container by opener span only.
358-
self.ops.push(TreeOp::ExtendBlockSpan {
359-
id: frame.container_body,
360-
span: frame.opener_span,
361-
});
362-
} else {
355+
if self.index.is_end_required(self.db, &frame.opener_name) {
363356
self.ops
364357
.push(TreeOp::AccumulateDiagnostic(ValidationError::UnclosedTag {
365358
tag: frame.opener_name,
366359
span: frame.opener_span,
367360
}));
361+
} else {
362+
// No explicit closer required: finalize last segment to end of input (best-effort)
363+
// We do not know the real end; leave as-is and extend container by opener span only.
364+
self.ops.push(TreeOp::ExtendBlockSpan {
365+
id: frame.container_body,
366+
span: frame.opener_span,
367+
});
368368
}
369369
}
370370
}

crates/djls-semantic/src/blocks/grammar.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct TagIndex<'db> {
1919

2020
#[derive(Clone, Debug, PartialEq, Eq)]
2121
pub struct EndMeta {
22-
optional: bool,
22+
required: bool,
2323
match_args: Vec<MatchArgSpec>,
2424
}
2525

@@ -49,10 +49,10 @@ impl<'db> TagIndex<'db> {
4949
TagClass::Unknown
5050
}
5151

52-
pub fn is_end_optional(self, db: &'db dyn crate::Db, opener_name: &str) -> bool {
52+
pub fn is_end_required(self, db: &'db dyn crate::Db, opener_name: &str) -> bool {
5353
self.openers(db)
5454
.get(opener_name)
55-
.is_some_and(|meta| meta.optional)
55+
.is_some_and(|meta| meta.required)
5656
}
5757

5858
pub fn validate_close(
@@ -133,7 +133,7 @@ impl<'db> TagIndex<'db> {
133133
.collect();
134134

135135
let meta = EndMeta {
136-
optional: end_tag.optional,
136+
required: end_tag.required,
137137
match_args,
138138
};
139139

crates/djls-semantic/src/templatetags/builtins.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
2222
module: B(DEFAULTTAGS_MOD),
2323
end_tag: Some(EndTag {
2424
name: B("endautoescape"),
25-
optional: false,
25+
required: true,
2626
args: B(&[]),
2727
}),
2828
intermediate_tags: B(&[]),
@@ -39,7 +39,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
3939
module: B(DEFAULTTAGS_MOD),
4040
end_tag: Some(EndTag {
4141
name: B("endcomment"),
42-
optional: false,
42+
required: true,
4343
args: B(&[]),
4444
}),
4545
intermediate_tags: B(&[]),
@@ -99,7 +99,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
9999
module: B(DEFAULTTAGS_MOD),
100100
end_tag: Some(EndTag {
101101
name: B("endfilter"),
102-
optional: false,
102+
required: true,
103103
args: B(&[]),
104104
}),
105105
intermediate_tags: B(&[]),
@@ -141,7 +141,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
141141
module: B(DEFAULTTAGS_MOD),
142142
end_tag: Some(EndTag {
143143
name: B("endfor"),
144-
optional: false,
144+
required: true,
145145
args: B(&[]),
146146
}),
147147
intermediate_tags: B(&[IntermediateTag {
@@ -174,7 +174,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
174174
module: B(DEFAULTTAGS_MOD),
175175
end_tag: Some(EndTag {
176176
name: B("endif"),
177-
optional: false,
177+
required: true,
178178
args: B(&[]),
179179
}),
180180
intermediate_tags: B(&[
@@ -202,7 +202,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
202202
module: B(DEFAULTTAGS_MOD),
203203
end_tag: Some(EndTag {
204204
name: B("endifchanged"),
205-
optional: false,
205+
required: true,
206206
args: B(&[]),
207207
}),
208208
intermediate_tags: B(&[IntermediateTag {
@@ -312,7 +312,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
312312
module: B(DEFAULTTAGS_MOD),
313313
end_tag: Some(EndTag {
314314
name: B("endspaceless"),
315-
optional: false,
315+
required: true,
316316
args: B(&[]),
317317
}),
318318
intermediate_tags: B(&[]),
@@ -373,7 +373,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
373373
module: B(DEFAULTTAGS_MOD),
374374
end_tag: Some(EndTag {
375375
name: B("endverbatim"),
376-
optional: false,
376+
required: true,
377377
args: B(&[]),
378378
}),
379379
intermediate_tags: B(&[]),
@@ -419,7 +419,7 @@ static DEFAULTTAGS_PAIRS: &[(&str, &TagSpec)] = &[
419419
module: B(DEFAULTTAGS_MOD),
420420
end_tag: Some(EndTag {
421421
name: B("endwith"),
422-
optional: false,
422+
required: true,
423423
args: B(&[]),
424424
}),
425425
intermediate_tags: B(&[]),
@@ -439,7 +439,7 @@ static LOADER_TAGS_PAIRS: &[(&str, &TagSpec)] = &[
439439
module: B(MOD_LOADER_TAGS),
440440
end_tag: Some(EndTag {
441441
name: B("endblock"),
442-
optional: false,
442+
required: true,
443443
args: B(&[TagArg::Var {
444444
name: B("name"),
445445
required: false,
@@ -499,7 +499,7 @@ static CACHE_PAIRS: &[(&str, &TagSpec)] = &[(
499499
module: B(CACHE_MOD),
500500
end_tag: Some(EndTag {
501501
name: B("endcache"),
502-
optional: false,
502+
required: true,
503503
args: B(&[]),
504504
}),
505505
intermediate_tags: B(&[]),
@@ -528,7 +528,7 @@ static I18N_PAIRS: &[(&str, &TagSpec)] = &[
528528
module: B(I18N_MOD),
529529
end_tag: Some(EndTag {
530530
name: B("endblocktrans"),
531-
optional: false,
531+
required: true,
532532
args: B(&[]),
533533
}),
534534
intermediate_tags: B(BLOCKTRANS_INTERMEDIATE_TAGS),
@@ -541,7 +541,7 @@ static I18N_PAIRS: &[(&str, &TagSpec)] = &[
541541
module: B(I18N_MOD),
542542
end_tag: Some(EndTag {
543543
name: B("endblocktranslate"),
544-
optional: false,
544+
required: true,
545545
args: B(&[]),
546546
}),
547547
intermediate_tags: B(BLOCKTRANS_INTERMEDIATE_TAGS),
@@ -621,7 +621,7 @@ static L10N_PAIRS: &[(&str, &TagSpec)] = &[(
621621
module: B(L10N_MOD),
622622
end_tag: Some(EndTag {
623623
name: B("endlocalize"),
624-
optional: false,
624+
required: true,
625625
args: B(&[]),
626626
}),
627627
intermediate_tags: B(&[]),
@@ -660,7 +660,7 @@ static TZ_PAIRS: &[(&str, &TagSpec)] = &[
660660
module: B(TZ_MOD),
661661
end_tag: Some(EndTag {
662662
name: B("endlocaltime"),
663-
optional: false,
663+
required: true,
664664
args: B(&[]),
665665
}),
666666
intermediate_tags: B(&[]),
@@ -677,7 +677,7 @@ static TZ_PAIRS: &[(&str, &TagSpec)] = &[
677677
module: B(TZ_MOD),
678678
end_tag: Some(EndTag {
679679
name: B("endtimezone"),
680-
optional: false,
680+
required: true,
681681
args: B(&[]),
682682
}),
683683
intermediate_tags: B(&[]),

0 commit comments

Comments
 (0)