Skip to content

Commit 805ab71

Browse files
committed
Fix: token span for record elements
1 parent a9f624f commit 805ab71

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

vhdl_lang/src/analysis/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
254254
&mut elem_decl.ident,
255255
type_ent.into(),
256256
AnyEntKind::ElementDeclaration(subtype),
257-
src_span,
257+
elem_decl.span,
258258
Some(self.source()),
259259
);
260260
region.add(elem, diagnostics);

vhdl_lang/src/syntax/type_declaration.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::ast::*;
1616
use crate::ast::{AbstractLiteral, Range};
1717
use crate::named_entity::Reference;
1818
use crate::syntax::names::parse_type_mark;
19-
use crate::HasTokenSpan;
2019
use vhdl_lang::syntax::parser::ParsingContext;
2120

2221
/// LRM 5.2.2 Enumeration types
@@ -81,18 +80,19 @@ fn parse_record_type_definition(
8180
return Ok((TypeDefinition::Record(elem_decls), end_ident));
8281
};
8382

83+
let start_token = ctx.stream.get_current_token_id();
84+
8485
let idents = parse_identifier_list(ctx)?;
8586
ctx.stream.expect_kind(Colon)?;
8687
let subtype = parse_subtype_indication(ctx)?;
88+
let end_token = ctx.stream.expect_kind(SemiColon)?;
8789
for ident in idents {
88-
let ident_span = ident.token.span();
8990
elem_decls.push(ElementDeclaration {
9091
ident: ident.into(),
9192
subtype: subtype.clone(),
92-
span: ident_span,
93+
span: TokenSpan::new(start_token, end_token),
9394
});
9495
}
95-
ctx.stream.expect_kind(SemiColon)?;
9696
}
9797
}
9898

@@ -531,7 +531,7 @@ end record;",
531531
let elem_decl = ElementDeclaration {
532532
ident: code.s1("element").decl_ident(),
533533
subtype: code.s1("boolean").subtype_indication(),
534-
span: code.s1("element").token_span(),
534+
span: code.s1("element : boolean;").token_span(),
535535
};
536536

537537
let type_decl = TypeDeclaration {
@@ -560,19 +560,21 @@ end foo;",
560560
let elem_decl0a = ElementDeclaration {
561561
ident: code.s1("element").decl_ident(),
562562
subtype: code.s1("boolean").subtype_indication(),
563-
span: code.s1("element").token_span(),
563+
span: code.s1("element, field : boolean;").token_span(),
564564
};
565565

566566
let elem_decl0b = ElementDeclaration {
567567
ident: code.s1("field").decl_ident(),
568568
subtype: code.s1("boolean").subtype_indication(),
569-
span: code.s1("field").token_span(),
569+
span: code.s1("element, field : boolean;").token_span(),
570570
};
571571

572572
let elem_decl1 = ElementDeclaration {
573573
ident: code.s1("other_element").decl_ident(),
574574
subtype: code.s1("std_logic_vector(0 to 1)").subtype_indication(),
575-
span: code.s1("other_element").token_span(),
575+
span: code
576+
.s1("other_element : std_logic_vector(0 to 1);")
577+
.token_span(),
576578
};
577579

578580
let type_decl = TypeDeclaration {

0 commit comments

Comments
 (0)