Skip to content

Commit

Permalink
Bring back local var symbol scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Apr 23, 2024
1 parent d2334bc commit 7107a10
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions crates/analysis/src/jobs/scan_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ impl DeclarationVisitor for SymbolScannerVisitor<'_> {
}
}

fn exit_global_func_decl(&mut self, _: &GlobalFunctionDeclarationNode) {
fn exit_global_func_decl(&mut self, n: &GlobalFunctionDeclarationNode) {
if self.current_path.components().last().map(|comp| comp.category == SymbolCategory::Callable).unwrap_or(false) {
// n.definition().accept(self);
n.definition().accept(self);
self.current_path.pop();
self.current_ordinal = 0;
}
Expand Down Expand Up @@ -377,10 +377,10 @@ impl DeclarationVisitor for SymbolScannerVisitor<'_> {
}
}

fn exit_member_func_decl(&mut self, _: &MemberFunctionDeclarationNode) {
fn exit_member_func_decl(&mut self, n: &MemberFunctionDeclarationNode) {
// pop only if visit managed to create the symbol
if self.current_path.components().last().map(|comp| comp.category == SymbolCategory::Callable).unwrap_or(false) {
// n.definition().accept(self);
n.definition().accept(self);
self.current_path.pop();
self.current_ordinal = 0;
}
Expand All @@ -407,9 +407,9 @@ impl DeclarationVisitor for SymbolScannerVisitor<'_> {
}
}

fn exit_event_decl(&mut self, _: &EventDeclarationNode) {
fn exit_event_decl(&mut self, n: &EventDeclarationNode) {
if self.current_path.components().last().map(|comp| comp.category == SymbolCategory::Callable).unwrap_or(false) {
// n.definition().accept(self);
n.definition().accept(self);
self.current_path.pop();
self.current_ordinal = 0;
}
Expand Down Expand Up @@ -521,18 +521,20 @@ impl DeclarationVisitor for SymbolScannerVisitor<'_> {
}
}

// local variable symbols will be checked dynamically when analysing functions
// impl StatementVisitor for SymbolScannerVisitor<'_> {
// fn visit_local_var_decl_stmt(&mut self, n: &VarDeclarationNode) {
// let type_path = self.check_type_from_type_annot(n.var_type());
impl StatementVisitor for SymbolScannerVisitor<'_> {
fn visit_local_var_decl_stmt(&mut self, n: &VarDeclarationNode) {
let type_path = self.check_type_from_type_annot(n.var_type());

// for name_node in n.names() {
// if let Some(var_name) = name_node.value(&self.doc) {
// let path = DataSymbolPath::new(&self.current_path, &var_name);
// let mut sym = LocalVarSymbol::new(path);
// sym.type_path = type_path.clone();
// self.try_insert_with_duplicate_check(sym, name_node.range());
// }
// }
// }
// }
for name_node in n.names() {
if let Some(var_name) = name_node.value(&self.doc) {
let path = DataSymbolPath::new(&self.current_path, &var_name);
if self.check_contains(&path, SymbolType::LocalVar, name_node.range()) {
let mut sym = LocalVarSymbol::new(path, name_node.range());
sym.type_path = type_path.clone();

self.symtab.insert(sym);
}
}
}
}
}

0 comments on commit 7107a10

Please sign in to comment.