From fdf1ebb8db26a8dfbe7a511b02f23d0f87c868ac Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 6 Jan 2025 22:39:16 -0600 Subject: [PATCH] add tag span --- crates/djls-template-ast/src/parser.rs | 4 +++- ...__parser__tests__django__parse_complex_if_elif.snap | 4 ++-- ..._parser__tests__django__parse_django_for_block.snap | 2 +- ...__parser__tests__django__parse_django_if_block.snap | 2 +- ...st__parser__tests__django__parse_mixed_content.snap | 10 +++++----- ...st__parser__tests__django__parse_nested_for_if.snap | 4 ++-- ...t__parser__tests__errors__parse_error_recovery.snap | 4 ++-- ...rser__tests__errors__parse_unclosed_django_for.snap | 2 +- ...arser__tests__errors__parse_unclosed_django_if.snap | 2 +- ...ast__parser__tests__full_templates__parse_full.snap | 4 ++-- 10 files changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/djls-template-ast/src/parser.rs b/crates/djls-template-ast/src/parser.rs index b57da81..427ba93 100644 --- a/crates/djls-template-ast/src/parser.rs +++ b/crates/djls-template-ast/src/parser.rs @@ -93,13 +93,15 @@ impl Parser { .map(String::from) .collect(); let tag_name = bits.first().ok_or(ParserError::EmptyTag)?.clone(); + let span = Span::from(token); + let tag_span = Span::new(*span.start(), tag_name.len() as u32); let tag = Tag { name: tag_name.clone(), bits: bits.clone(), span, - tag_span: span, + tag_span, assignment: None, }; diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_complex_if_elif.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_complex_if_elif.snap index 087e14a..c28b497 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_complex_if_elif.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_complex_if_elif.snap @@ -17,7 +17,7 @@ nodes: length: 8 tag_span: start: 3 - length: 8 + length: 2 assignment: ~ nodes: - Text: @@ -39,7 +39,7 @@ nodes: length: 10 tag_span: start: 25 - length: 10 + length: 4 assignment: ~ nodes: - Text: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_for_block.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_for_block.snap index ec84f55..288db4f 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_for_block.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_for_block.snap @@ -17,7 +17,7 @@ nodes: length: 17 tag_span: start: 3 - length: 17 + length: 3 assignment: ~ nodes: - Variable: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_if_block.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_if_block.snap index 25c0d11..abb2362 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_if_block.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_django_if_block.snap @@ -15,7 +15,7 @@ nodes: length: 24 tag_span: start: 3 - length: 24 + length: 2 assignment: ~ nodes: - Text: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_mixed_content.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_mixed_content.snap index e204d56..4e5884c 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_mixed_content.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_mixed_content.snap @@ -20,7 +20,7 @@ nodes: length: 24 tag_span: start: 12 - length: 24 + length: 2 assignment: ~ nodes: - Variable: @@ -56,7 +56,7 @@ nodes: length: 24 tag_span: start: 89 - length: 24 + length: 3 assignment: ~ nodes: - Block: @@ -71,7 +71,7 @@ nodes: length: 16 tag_span: start: 128 - length: 16 + length: 2 assignment: ~ nodes: - Text: @@ -113,7 +113,7 @@ nodes: length: 19 tag_span: start: 196 - length: 19 + length: 2 assignment: ~ nodes: - Text: @@ -146,7 +146,7 @@ nodes: length: 15 tag_span: start: 243 - length: 15 + length: 2 assignment: ~ nodes: - Text: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_nested_for_if.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_nested_for_if.snap index efa282b..9ae4785 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_nested_for_if.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__django__parse_nested_for_if.snap @@ -17,7 +17,7 @@ nodes: length: 17 tag_span: start: 3 - length: 17 + length: 3 assignment: ~ nodes: - Block: @@ -32,7 +32,7 @@ nodes: length: 14 tag_span: start: 26 - length: 14 + length: 2 assignment: ~ nodes: - Variable: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_error_recovery.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_error_recovery.snap index 111ebcf..fbbfb1a 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_error_recovery.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_error_recovery.snap @@ -25,7 +25,7 @@ nodes: length: 24 tag_span: start: 51 - length: 24 + length: 2 assignment: ~ nodes: - Comment: @@ -75,7 +75,7 @@ nodes: length: 17 tag_span: start: 255 - length: 17 + length: 3 assignment: ~ nodes: - Text: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_for.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_for.snap index 780b33b..b88f824 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_for.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_for.snap @@ -17,7 +17,7 @@ nodes: length: 17 tag_span: start: 3 - length: 17 + length: 3 assignment: ~ nodes: - Variable: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_if.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_if.snap index 1703ae3..0f2ba36 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_if.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__errors__parse_unclosed_django_if.snap @@ -15,7 +15,7 @@ nodes: length: 24 tag_span: start: 3 - length: 24 + length: 2 assignment: ~ nodes: - Text: diff --git a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__full_templates__parse_full.snap b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__full_templates__parse_full.snap index ab9470d..8d705c4 100644 --- a/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__full_templates__parse_full.snap +++ b/crates/djls-template-ast/src/snapshots/djls_template_ast__parser__tests__full_templates__parse_full.snap @@ -105,7 +105,7 @@ nodes: length: 24 tag_span: start: 466 - length: 24 + length: 2 assignment: ~ nodes: - Comment: @@ -154,7 +154,7 @@ nodes: length: 16 tag_span: start: 624 - length: 16 + length: 2 assignment: ~ nodes: - Text: