martinohmann / hcl-rs

HCL parsing and encoding libraries for rust with serde support
Apache License 2.0
121 stars 14 forks source link

hcl-edit: attribute key has no span information #294

Closed denfren closed 11 months ago

denfren commented 11 months ago
#[test]
fn parsed_body_attribute_has_span_information() {
    use hcl_edit::Span;

    let body = hcl_edit::parser::parse_body("foo = bar").unwrap();
    let first_attr = body.into_attributes().next().unwrap();
    assert!(first_attr.key.span().is_some());
}

Is this assertion correct? (it fails)

If this is confirmed and still open in about 2 weeks then i'll provide a PR with a fix attempt

martinohmann commented 11 months ago

Hi there!

Yes, your assumption is correct and this is indeed a bug. Since the attribute key is coming from the parser it should have span information attached.

martinohmann commented 11 months ago

FWIW, block identifiers are also affected. I did forget to propagate the span information when implementing detection for duplicate attribute keys in the parser.

Feel free to take a stab at fixing this if you like, it should be relatively straight forward (see the structure parser in src/parser/structure.rs).