mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
function params and local variables working
Signed-off-by: faldor20 <eli.jambu@yahoo.com>
This commit is contained in:
parent
9b4230cfc3
commit
049c0e6358
3 changed files with 357 additions and 61 deletions
|
@ -1,6 +1,11 @@
|
|||
//! Traversals over the can ast.
|
||||
|
||||
use roc_module::{ident::Lowercase, symbol::Symbol};
|
||||
use std::process;
|
||||
|
||||
use roc_module::{
|
||||
ident::Lowercase,
|
||||
symbol::{Interns, Symbol},
|
||||
};
|
||||
use roc_region::all::{Loc, Position, Region};
|
||||
use roc_types::{subs::Variable, types::MemberImpl};
|
||||
|
||||
|
@ -13,7 +18,7 @@ use crate::{
|
|||
},
|
||||
pattern::{DestructType, Pattern, RecordDestruct, TupleDestruct},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum DeclarationInfo<'a> {
|
||||
Value {
|
||||
loc_symbol: Loc<Symbol>,
|
||||
|
@ -963,3 +968,74 @@ pub fn find_declaration(symbol: Symbol, decls: &'_ Declarations) -> Option<Found
|
|||
}
|
||||
}
|
||||
}
|
||||
struct CompletionVisitor<'a, U, T> {
|
||||
position: Position,
|
||||
found_decls: Vec<T>,
|
||||
state: &'a mut U,
|
||||
processor: fn(&mut U, FoundDeclaration) -> T,
|
||||
}
|
||||
|
||||
impl<T, U> Visitor for CompletionVisitor<'_, U, T> {
|
||||
fn should_visit(&mut self, region: Region) -> bool {
|
||||
region.contains_pos(self.position)
|
||||
}
|
||||
|
||||
// fn visit_expr(&mut self, expr: &Expr, region: Region, var: Variable) {
|
||||
// if region.contains_pos(self.position) {
|
||||
// // self.region_typ = Some((region, var));
|
||||
|
||||
// walk_expr(self, expr, var);
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn visit_pattern(&mut self, pat: &Pattern, region: Region, opt_var: Option<Variable>) {
|
||||
// if region.contains_pos(self.position) {
|
||||
// // if let Some(var) = opt_var {
|
||||
// // self.region_typ = Some((region, var));
|
||||
// // }
|
||||
|
||||
// walk_pattern(self, pat);
|
||||
// }
|
||||
// }
|
||||
fn visit_decl(&mut self, decl: DeclarationInfo<'_>) {
|
||||
match decl {
|
||||
DeclarationInfo::Value { .. }
|
||||
| DeclarationInfo::Function { .. }
|
||||
| DeclarationInfo::Destructure { .. } => {
|
||||
let res = (self.processor)(
|
||||
self.state,
|
||||
FoundDeclaration::Decl(unsafe { std::mem::transmute(decl.clone()) }),
|
||||
);
|
||||
self.found_decls.push(res);
|
||||
walk_decl(self, decl);
|
||||
}
|
||||
_ => {
|
||||
walk_decl(self, decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_def(&mut self, def: &Def) {
|
||||
let res = ((self.processor)(
|
||||
self.state,
|
||||
FoundDeclaration::Def(unsafe { std::mem::transmute(def) }),
|
||||
));
|
||||
self.found_decls.push(res);
|
||||
walk_def(self, def);
|
||||
}
|
||||
}
|
||||
pub fn get_completions<'a, U, T>(
|
||||
position: Position,
|
||||
decls: &'a Declarations,
|
||||
state: &mut U,
|
||||
processor: fn(&mut U, FoundDeclaration) -> T,
|
||||
) -> Vec<T> {
|
||||
let mut visitor = CompletionVisitor {
|
||||
position,
|
||||
found_decls: Vec::new(),
|
||||
state,
|
||||
processor,
|
||||
};
|
||||
visitor.visit_decls(decls);
|
||||
visitor.found_decls
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue