Skip to main content

luaur_analysis/methods/
scope_find_narrowest_scope_containing.rs

1use crate::records::scope::Scope;
2use luaur_ast::records::location::Location;
3
4impl Scope {
5    pub fn find_narrowest_scope_containing(&mut self, location: Location) -> *mut Scope {
6        let mut best_scope = self as *mut Scope;
7
8        loop {
9            let mut did_narrow = false;
10            let children = unsafe { &(*best_scope).children };
11
12            for &scope in children {
13                if unsafe { (*scope).location.encloses(&location) } {
14                    best_scope = scope;
15                    did_narrow = true;
16                    break;
17                }
18            }
19
20            if !did_narrow || unsafe { (*best_scope).children.is_empty() } {
21                break;
22            }
23        }
24
25        best_scope
26    }
27}