diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-27 16:09:35 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-27 16:09:35 +0100 |
| commit | a96141a3ea9d1b11ef4cdc924216d8979689e6f0 (patch) | |
| tree | 0192bdd4e63f3fb3c9172faae35bf8b08c8c957d /src/model | |
| parent | 2e039cb052fcb768027053cbf02ce396f6d7a6be (diff) | |
Autocomplete methods
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/eval.rs | 7 | ||||
| -rw-r--r-- | src/model/methods.rs | 33 | ||||
| -rw-r--r-- | src/model/mod.rs | 1 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/model/eval.rs b/src/model/eval.rs index d52b1272..3e1ccfa6 100644 --- a/src/model/eval.rs +++ b/src/model/eval.rs @@ -46,7 +46,12 @@ pub fn eval( let route = unsafe { Route::insert(route, id) }; let scopes = Scopes::new(Some(library)); let mut vm = Vm::new(world, route.track(), tracer, id, scopes, 0); - let result = source.ast()?.eval(&mut vm); + let root = match source.root().cast::<ast::Markup>() { + Some(markup) if vm.traced.is_some() => markup, + _ => source.ast()?, + }; + + let result = root.eval(&mut vm); // Handle control flow. if let Some(flow) = vm.flow { diff --git a/src/model/methods.rs b/src/model/methods.rs index 173b95fe..1671a5c4 100644 --- a/src/model/methods.rs +++ b/src/model/methods.rs @@ -210,3 +210,36 @@ pub fn is_accessor(method: &str) -> bool { fn missing_method(type_name: &str, method: &str) -> String { format!("type {type_name} has no method `{method}`") } + +/// List the available methods for a type. +pub fn methods_on(type_name: &str) -> &[&'static str] { + match type_name { + "color" => &["lighten", "darken", "negate"], + "string" => &[ + "len", + "at", + "contains", + "ends-with", + "find", + "first", + "last", + "match", + "matches", + "position", + "replace", + "slice", + "split", + "starts-with", + "trim", + ], + "array" => &[ + "all", "any", "at", "contains", "filter", "find", "first", "flatten", "fold", + "insert", "join", "last", "len", "map", "pop", "position", "push", "remove", + "rev", "slice", "sorted", + ], + "dictionary" => &["at", "insert", "keys", "len", "pairs", "remove", "values"], + "function" => &["where", "with"], + "arguments" => &["named", "pos"], + _ => &[], + } +} diff --git a/src/model/mod.rs b/src/model/mod.rs index d96a314c..32b0a003 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -38,6 +38,7 @@ pub use self::dict::*; pub use self::eval::*; pub use self::func::*; pub use self::library::*; +pub use self::methods::*; pub use self::module::*; pub use self::realize::*; pub use self::scope::*; |
