Skip to main content

luaur_analysis/methods/
nearest_statement_finder_visit.rs

1use crate::records::nearest_statement_finder::NearestStatementFinder;
2use luaur_ast::records::ast_stat_block::AstStatBlock;
3use luaur_ast::records::location::Location;
4use luaur_ast::records::position::Position;
5
6impl NearestStatementFinder {
7    pub fn visit(&mut self, block: *mut AstStatBlock) -> bool {
8        let block_ref = unsafe { &*block };
9        let block_location: Location = block_ref.base.base.location;
10
11        if block_location.contains(self.cursor) {
12            self.parent = block;
13
14            let body = block_ref.body;
15            for i in 0..body.size {
16                let stat = unsafe { *body.data.add(i) };
17                let stat_ref = unsafe { &*stat };
18                let stat_location = stat_ref.base.location;
19
20                if stat_location.begin <= self.cursor {
21                    self.nearest = stat;
22                }
23            }
24
25            true
26        } else {
27            false
28        }
29    }
30}