Fix context scope bug
This commit is contained in:
parent
3c2a70803e
commit
0edb42836d
@ -268,6 +268,32 @@ impl Context {
|
|||||||
&self,
|
&self,
|
||||||
identifier: &Identifier,
|
identifier: &Identifier,
|
||||||
position: usize,
|
position: usize,
|
||||||
|
) -> Result<bool, ContextError> {
|
||||||
|
let found = self.update_position_if_found(identifier, position)?;
|
||||||
|
|
||||||
|
if found {
|
||||||
|
Ok(true)
|
||||||
|
} else if let Some(parent) = &self.parent {
|
||||||
|
let found_in_ancestor = parent.update_last_position(identifier, position)?;
|
||||||
|
|
||||||
|
if !found_in_ancestor {
|
||||||
|
let mut associations = self.associations.write()?;
|
||||||
|
|
||||||
|
log::trace!("Updating {identifier}'s last position to {position:?}");
|
||||||
|
|
||||||
|
associations.insert(identifier.clone(), (ContextData::Reserved, position));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(false)
|
||||||
|
} else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_position_if_found(
|
||||||
|
&self,
|
||||||
|
identifier: &Identifier,
|
||||||
|
position: usize,
|
||||||
) -> Result<bool, ContextError> {
|
) -> Result<bool, ContextError> {
|
||||||
let mut associations = self.associations.write()?;
|
let mut associations = self.associations.write()?;
|
||||||
|
|
||||||
@ -278,21 +304,7 @@ impl Context {
|
|||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
let ancestor_contains = if let Some(parent) = &self.parent {
|
Ok(false)
|
||||||
parent.contains(identifier)?
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
if ancestor_contains {
|
|
||||||
Ok(true)
|
|
||||||
} else {
|
|
||||||
log::trace!("Reserving {identifier} at {position:?}");
|
|
||||||
|
|
||||||
associations.insert(identifier.clone(), (ContextData::Reserved, position));
|
|
||||||
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user