1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-06 16:18:08 +03:00

RecordBind -> RecordRef

This commit is contained in:
Oghenevwogaga Ebresafe 2022-10-12 11:03:18 +01:00
parent 0430d4ab5a
commit 37eba61e4b
4 changed files with 20 additions and 8 deletions

View File

@ -55,7 +55,7 @@ impl Building {
TermKind::Structure => unreachable!(),
TermKind::Usage(_) => unreachable!(),
TermKind::Record(_) => unreachable!(),
TermKind::RecordBind { .. } => unreachable!(),
TermKind::RecordRef { .. } => unreachable!(),
TermKind::Declaration(_, ref mut usages, _)
| TermKind::RecordField { ref mut usages, .. } => usages.push(usage),
};

View File

@ -20,7 +20,7 @@ impl ResolutionState for Resolved {}
/// 1. Declarations
/// 2. Usages
/// 3. Records, listing their fields
/// 4. Recrod Bind, a let or pattern binding, which binds a record.
/// 4. Recrod Ref, a variable usage of a let or pattern binding, which binds a record.
/// 5. wildcard (Structure) for any other kind of term.
/// Can be extended later to represent Contracts, Records, etc.
#[derive(Debug, Clone, PartialEq)]
@ -34,7 +34,7 @@ pub enum TermKind {
usages: Vec<ID>,
value: ValueState,
},
RecordBind {
RecordRef {
ident: Ident,
fields: Vec<Ident>,
},

View File

@ -123,7 +123,7 @@ impl Linearizer for AnalysisHost {
ty,
pos: ident.pos.clone(),
scope,
kind: TermKind::RecordBind {
kind: TermKind::RecordRef {
ident: ident.clone(),
fields,
},
@ -227,11 +227,11 @@ impl Linearizer for AnalysisHost {
}
for matched in destruct.to_owned().inner() {
let (ident, term) = matched.as_meta_field();
// register_record_completion(&ident, &term, &mut lin);
let id = id_gen.get_and_advance();
self.env.insert(ident.to_owned(), id);
// register record completion here
lin.push(LinearizationItem {
id,
// TODO: get type from pattern
@ -254,6 +254,8 @@ impl Linearizer for AnalysisHost {
}
}
Term::Let(ident, ..) | Term::Fun(ident, ..) => {
// register record completion here
let value_ptr = match term {
Term::Let(..) => {
self.let_binding = Some(id);

View File

@ -42,12 +42,22 @@ pub fn handle_completion(
let item = item.unwrap().to_owned();
// How can we get data for record completion based on the TermKind
// 1. Record: just list it's fields
// 2. RecordRef: list the field it contains if the item we're at corresponds with it's ID
// 3. Check the type of the term: If it's a record, list it's fields
// 4. Check the MetaValue for it's contract: if it's a record, list it's fields
// Can we seperate record completion from just normal completion?
let in_scope: Vec<_> = linearization
.get_in_scope(&item)
.iter()
.filter_map(|i| match i.kind {
TermKind::Declaration(ref ident, _, _) => Some((vec![ident.clone()], i.ty.clone())),
TermKind::RecordBind { ref fields, .. } => Some((fields.clone(), i.ty.clone())),
TermKind::RecordRef { ref fields, .. } if i.id == item.id => {
Some((fields.clone(), i.ty.clone()))
}
_ => None,
})
.map(|(idents, _)| {