Skip to content

Commit

Permalink
Fix: token span for record elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Schottkyc137 committed May 26, 2024
1 parent a9f624f commit 805ab71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion vhdl_lang/src/analysis/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
&mut elem_decl.ident,
type_ent.into(),
AnyEntKind::ElementDeclaration(subtype),
src_span,
elem_decl.span,
Some(self.source()),
);
region.add(elem, diagnostics);
Expand Down
18 changes: 10 additions & 8 deletions vhdl_lang/src/syntax/type_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::ast::*;
use crate::ast::{AbstractLiteral, Range};
use crate::named_entity::Reference;
use crate::syntax::names::parse_type_mark;
use crate::HasTokenSpan;
use vhdl_lang::syntax::parser::ParsingContext;

/// LRM 5.2.2 Enumeration types
Expand Down Expand Up @@ -81,18 +80,19 @@ fn parse_record_type_definition(
return Ok((TypeDefinition::Record(elem_decls), end_ident));
};

let start_token = ctx.stream.get_current_token_id();

let idents = parse_identifier_list(ctx)?;
ctx.stream.expect_kind(Colon)?;
let subtype = parse_subtype_indication(ctx)?;
let end_token = ctx.stream.expect_kind(SemiColon)?;
for ident in idents {
let ident_span = ident.token.span();
elem_decls.push(ElementDeclaration {
ident: ident.into(),
subtype: subtype.clone(),
span: ident_span,
span: TokenSpan::new(start_token, end_token),
});
}
ctx.stream.expect_kind(SemiColon)?;
}
}

Expand Down Expand Up @@ -531,7 +531,7 @@ end record;",
let elem_decl = ElementDeclaration {
ident: code.s1("element").decl_ident(),
subtype: code.s1("boolean").subtype_indication(),
span: code.s1("element").token_span(),
span: code.s1("element : boolean;").token_span(),
};

let type_decl = TypeDeclaration {
Expand Down Expand Up @@ -560,19 +560,21 @@ end foo;",
let elem_decl0a = ElementDeclaration {
ident: code.s1("element").decl_ident(),
subtype: code.s1("boolean").subtype_indication(),
span: code.s1("element").token_span(),
span: code.s1("element, field : boolean;").token_span(),
};

let elem_decl0b = ElementDeclaration {
ident: code.s1("field").decl_ident(),
subtype: code.s1("boolean").subtype_indication(),
span: code.s1("field").token_span(),
span: code.s1("element, field : boolean;").token_span(),
};

let elem_decl1 = ElementDeclaration {
ident: code.s1("other_element").decl_ident(),
subtype: code.s1("std_logic_vector(0 to 1)").subtype_indication(),
span: code.s1("other_element").token_span(),
span: code
.s1("other_element : std_logic_vector(0 to 1);")
.token_span(),
};

let type_decl = TypeDeclaration {
Expand Down

0 comments on commit 805ab71

Please sign in to comment.