diff --git a/crates/rue-lsp/src/cache.rs b/crates/rue-lsp/src/cache.rs index 2927af8c..635a96b0 100644 --- a/crates/rue-lsp/src/cache.rs +++ b/crates/rue-lsp/src/cache.rs @@ -44,6 +44,7 @@ pub struct TypeHoverInfo { pub struct StructHoverInfo { pub name: String, pub fields: Vec, + pub nil_terminated: bool, } #[derive(Debug, Clone)] @@ -194,7 +195,7 @@ impl Cache { match self.ctx.ty(semantic) { Type::Struct(_) => { - for field in self.struct_fields(scopes, semantic).unwrap() { + for field in self.struct_fields(scopes, semantic).unwrap().0 { fields.insert(field.name, field.type_name); } } @@ -462,10 +463,11 @@ impl Cache { SyntaxItemKind::TypeDeclaration(ty) | SyntaxItemKind::TypeReference(ty) => { let fields = self.struct_fields(scopes, ty); - if let Some(fields) = fields { + if let Some((fields, nil_terminated)) = fields { infos.push(HoverInfo::Struct(StructHoverInfo { name: self.type_name(scopes, ty), fields, + nil_terminated, })); } else { infos.push(HoverInfo::Type(TypeHoverInfo { @@ -786,7 +788,11 @@ impl Cache { } } - fn struct_fields(&mut self, scopes: &Scopes, ty: TypeId) -> Option> { + fn struct_fields( + &mut self, + scopes: &Scopes, + ty: TypeId, + ) -> Option<(Vec, bool)> { let semantic = rue_types::unwrap_semantic(self.ctx.types_mut(), ty, true); let mut fields = Vec::new(); @@ -829,7 +835,7 @@ impl Cache { }); } - Some(fields) + Some((fields, ty.nil_terminated)) } } diff --git a/crates/rue-lsp/src/main.rs b/crates/rue-lsp/src/main.rs index 5746ced8..690d6844 100644 --- a/crates/rue-lsp/src/main.rs +++ b/crates/rue-lsp/src/main.rs @@ -252,7 +252,16 @@ impl Backend { info.name, info.fields .iter() - .map(|field| format!(" {}: {},", field.name, field.type_name)) + .enumerate() + .map(|(i, field)| { + let spread = + if !info.nil_terminated && i == info.fields.len() - 1 { + "..." + } else { + "" + }; + format!(" {spread}{}: {},", field.name, field.type_name) + }) .collect::>() .join("\n") ),