From 805ab71a5ce8ce7af30557dabc20728b0205c68a Mon Sep 17 00:00:00 2001 From: Lukas Scheller Date: Sun, 26 May 2024 17:55:14 +0200 Subject: [PATCH] Fix: token span for record elements --- vhdl_lang/src/analysis/types.rs | 2 +- vhdl_lang/src/syntax/type_declaration.rs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/vhdl_lang/src/analysis/types.rs b/vhdl_lang/src/analysis/types.rs index 8e7976ec..b8573f22 100644 --- a/vhdl_lang/src/analysis/types.rs +++ b/vhdl_lang/src/analysis/types.rs @@ -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); diff --git a/vhdl_lang/src/syntax/type_declaration.rs b/vhdl_lang/src/syntax/type_declaration.rs index 0ce39536..ae277bd8 100644 --- a/vhdl_lang/src/syntax/type_declaration.rs +++ b/vhdl_lang/src/syntax/type_declaration.rs @@ -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 @@ -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)?; } } @@ -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 { @@ -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 {