summaryrefslogtreecommitdiff
path: root/src/ide/analyze.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-01-28 23:36:27 +0100
committerLaurenz <laurmaedje@gmail.com>2023-01-28 23:38:03 +0100
commit1e97d5c8cbeb96d35e5a34a8340c4ec1860fa1b6 (patch)
treeaa4a341af10dc0729132a42cdb1cacb1e1d21518 /src/ide/analyze.rs
parent76048a8ef45ac5892235f2e69cb7cb6c35a037e4 (diff)
Better analysis for literals
Diffstat (limited to 'src/ide/analyze.rs')
-rw-r--r--src/ide/analyze.rs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/ide/analyze.rs b/src/ide/analyze.rs
index 65d9ded8..12576e53 100644
--- a/src/ide/analyze.rs
+++ b/src/ide/analyze.rs
@@ -7,6 +7,22 @@ use crate::World;
/// Try to determine a set of possible values for an expression.
pub fn analyze(world: &(dyn World + 'static), node: &LinkedNode) -> Vec<Value> {
match node.cast::<ast::Expr>() {
+ Some(ast::Expr::None(_)) => vec![Value::None],
+ Some(ast::Expr::Auto(_)) => vec![Value::Auto],
+ Some(ast::Expr::Bool(v)) => vec![Value::Bool(v.get())],
+ Some(ast::Expr::Int(v)) => vec![Value::Int(v.get())],
+ Some(ast::Expr::Float(v)) => vec![Value::Float(v.get())],
+ Some(ast::Expr::Numeric(v)) => vec![Value::numeric(v.get())],
+ Some(ast::Expr::Str(v)) => vec![Value::Str(v.get().into())],
+
+ Some(ast::Expr::FieldAccess(access)) => {
+ let Some(child) = node.children().next() else { return vec![] };
+ analyze(world, &child)
+ .into_iter()
+ .filter_map(|target| target.field(&access.field()).ok())
+ .collect()
+ }
+
Some(ast::Expr::Ident(_) | ast::Expr::MathIdent(_) | ast::Expr::FuncCall(_)) => {
if let Some(parent) = node.parent() {
if parent.kind() == SyntaxKind::FieldAccess && node.index() > 0 {
@@ -19,22 +35,9 @@ pub fn analyze(world: &(dyn World + 'static), node: &LinkedNode) -> Vec<Value> {
let route = Route::default();
let mut tracer = Tracer::new(Some(span));
eval(world.track(), route.track(), tracer.track_mut(), source).ok();
- return tracer.finish();
- }
-
- Some(ast::Expr::Str(s)) => return vec![Value::Str(s.get().into())],
-
- Some(ast::Expr::FieldAccess(access)) => {
- if let Some(child) = node.children().next() {
- return analyze(world, &child)
- .into_iter()
- .filter_map(|target| target.field(&access.field()).ok())
- .collect();
- }
+ tracer.finish()
}
- _ => {}
+ _ => vec![],
}
-
- vec![]
}