diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-27 12:05:00 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-27 12:05:12 +0100 |
| commit | 43ef60c09cc48f6b7c6dd752ab7af7c0d6071bc5 (patch) | |
| tree | 525320e583fc53e9474fd4b4d4944cdf8117d406 /src/ide/analyze.rs | |
| parent | c56299c6bde121807c3febbef0766ff2fe2b32f2 (diff) | |
Tracing-based expression tooltips
Diffstat (limited to 'src/ide/analyze.rs')
| -rw-r--r-- | src/ide/analyze.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ide/analyze.rs b/src/ide/analyze.rs new file mode 100644 index 00000000..d8925cfc --- /dev/null +++ b/src/ide/analyze.rs @@ -0,0 +1,38 @@ +use comemo::Track; + +use crate::model::{eval, Route, Tracer, Value}; +use crate::syntax::{ast, LinkedNode, SyntaxKind}; +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::Ident(_) | ast::Expr::MathIdent(_)) => { + if let Some(parent) = node.parent() { + if parent.kind() == SyntaxKind::FieldAccess && node.index() > 0 { + return analyze(world, parent); + } + } + + let span = node.span(); + let source = world.source(span.source()); + 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::FieldAccess(access)) => { + if let Some(child) = node.children().next() { + return analyze(world, &child) + .into_iter() + .filter_map(|target| target.field(&access.field()).ok()) + .collect(); + } + } + + _ => {} + } + + vec![] +} |
