diff --git a/src/analyze.rs b/src/analyze.rs index 183cb12..161b119 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -481,7 +481,7 @@ impl Backend { let attr = String::from_utf8_lossy(attr); self.index.models.populate_field_names(model, &[])?; let attr = interner().get(attr.as_ref())?; - let relation = self.index.models.normalize_field_relation(attr.into(), model.into())?; + let relation = self.index.models.resolve_related_field(attr.into(), model.into())?; Some(Type::Model(interner().resolve(&relation).into())) } pub fn has_attribute(&self, type_: &Type, attr: &[u8], scope: &Scope) -> bool { diff --git a/src/index.rs b/src/index.rs index c957f67..09c2646 100644 --- a/src/index.rs +++ b/src/index.rs @@ -611,6 +611,7 @@ pub fn index_models(contents: &[u8]) -> miette::Result> { (false, None) => Some(Model { range, byte_range, + // if _name is not defined and _inherit = [A, B, C], A is considered the inherit base by default type_: ModelType::Inherit(inherits), }), (true, None) => None, diff --git a/src/main.rs b/src/main.rs index eb18717..32462d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -598,7 +598,7 @@ impl LanguageServer for Backend { drop(entry); if let Some(field_entry) = field_entry { let type_ = interner().resolve(&field_entry.type_); - completion.detail = match self.index.models.normalize_field_relation(field.into(), model) { + completion.detail = match self.index.models.resolve_related_field(field.into(), model) { None => Some(format!("{type_}(…)")), Some(relation) => { let relation = interner().resolve(&relation); diff --git a/src/model.rs b/src/model.rs index 10a1549..2223011 100644 --- a/src/model.rs +++ b/src/model.rs @@ -180,7 +180,7 @@ impl ModelIndex { if replace { for inherit in inherits { let Some(inherit) = interner.get(inherit) else { continue }; - if let Some(mut entry) = self.try_get_mut(&inherit.into()).expect(format_loc!("deadlock")) { + if let Some(mut entry) = self.get_mut(&inherit.into()) { entry.descendants.retain(|loc| loc.0.path != path) } } @@ -397,15 +397,15 @@ impl ModelIndex { ) -> Result<(), ResolveMappedError> { while let Some((lhs, rhs)) = needle.split_once('.') { trace!("(resolved_mapped) `{needle}` model=`{}`", interner().resolve(model)); - let mut normalized = interner() + let mut resolved = interner() .get(lhs) - .and_then(|key| self.normalize_field_relation(key.into(), *model)); - if let Some(normalized) = &normalized { + .and_then(|key| self.resolve_related_field(key.into(), *model)); + if let Some(normalized) = &resolved { trace!("(resolved_mapped) prenormalized: {}", interner().resolve(normalized)); } // lhs: foo // rhs: ba - if normalized.is_none() { + if resolved.is_none() { let Some(fields) = self.populate_field_names((*model).into(), &[]) else { debug!( "tried to resolve before fields are populated for `{}`", @@ -416,15 +416,15 @@ impl ModelIndex { let field = interner().get(lhs); let field = field.and_then(|field| fields.fields.as_ref()?.get(&field.into())); match field.as_ref().map(|f| &f.kind) { - Some(FieldKind::Relational(rel)) => normalized = Some(*rel), + Some(FieldKind::Relational(rel)) => resolved = Some(*rel), None | Some(FieldKind::Value) => return Err(ResolveMappedError::NonRelational), Some(FieldKind::Related(..)) => { drop(fields); - normalized = self.normalize_field_relation(interner().get(lhs).unwrap().into(), *model); + resolved = self.resolve_related_field(interner().get(lhs).unwrap().into(), *model); } } } - let Some(rel) = normalized else { + let Some(rel) = resolved else { warn!("unresolved field `{}`.`{lhs}`", interner().resolve(model)); *needle = lhs; if let Some(range) = range.as_mut() { @@ -444,9 +444,9 @@ impl ModelIndex { } Ok(()) } - /// Turns related fields ([`FieldKind::Related`]) into concrete fields, and return the field's type itself. + /// Turns related fields ([`FieldKind::Related`]) into concrete fields, and return the field's type itself if successful. #[must_use = "normalized relation might not have been updated back to the central index"] - pub fn normalize_field_relation(&self, field: Symbol, model: Spur) -> Option { + pub fn resolve_related_field(&self, field: Symbol, model: Spur) -> Option { // Why populate? // If we came from a long chain of relations, we might encounter a field on a model // that hasn't been populated yet. This is because we only populate fields when they're @@ -469,7 +469,7 @@ impl ModelIndex { if self.resolve_mapped(&mut field_model, &mut related, None).is_ok() { // resolved_mapped took us to the final field, now we need to resolve it to a model let related_key = interner().get(related)?; - let field_model = self.normalize_field_relation(related_key.into(), field_model)?; + let field_model = self.resolve_related_field(related_key.into(), field_model)?; kind = FieldKind::Relational(field_model); let mut model_entry = self.try_get_mut(&model.into()).expect(format_loc!("deadlock"))?;