Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions crates/rue-lsp/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct TypeHoverInfo {
pub struct StructHoverInfo {
pub name: String,
pub fields: Vec<FieldHoverInfo>,
pub nil_terminated: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -194,7 +195,7 @@ impl Cache<Compiler> {

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);
}
}
Expand Down Expand Up @@ -462,10 +463,11 @@ impl Cache<Compiler> {
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 {
Expand Down Expand Up @@ -786,7 +788,11 @@ impl Cache<Compiler> {
}
}

fn struct_fields(&mut self, scopes: &Scopes, ty: TypeId) -> Option<Vec<FieldHoverInfo>> {
fn struct_fields(
&mut self,
scopes: &Scopes,
ty: TypeId,
) -> Option<(Vec<FieldHoverInfo>, bool)> {
let semantic = rue_types::unwrap_semantic(self.ctx.types_mut(), ty, true);

let mut fields = Vec::new();
Expand Down Expand Up @@ -829,7 +835,7 @@ impl Cache<Compiler> {
});
}

Some(fields)
Some((fields, ty.nil_terminated))
}
}

Expand Down
11 changes: 10 additions & 1 deletion crates/rue-lsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<String>>()
.join("\n")
),
Expand Down
Loading