KCL stdlib 'map' function (#4054)

I had to revert https://github.com/KittyCAD/modeling-app/pull/4031 because it broke syntax highlighting. This is the same PR, but updated to fix syntax highlighting.

Highlighting broke because the KCL LSP could not determine how to autocomplete the `map` function. The first argument of `map` is `[KclValue]` and the LSP doesn't know any good suggestions for "any KCL value", so it error'd out. I am using the value `[0..9]` for this case now. Tested that syntax highlighting works again.
This commit is contained in:
Adam Chalmers
2024-10-01 08:50:23 -05:00
committed by GitHub
parent 9ca49c6366
commit 2a3693651a
37 changed files with 12424 additions and 33 deletions

View File

@ -81,6 +81,8 @@ impl StdLibFnArg {
} else if self.type_ == "TagIdentifier" && self.required {
// TODO: actually use the ast to populate this.
return Ok(Some((index, format!("${{{}:{}}}", index, "myTag"))));
} else if self.type_ == "[KclValue]" && self.required {
return Ok(Some((index, "[0..9]".to_owned())));
}
get_autocomplete_snippet_from_schema(&self.schema.schema.clone().into(), index)
}
@ -903,6 +905,12 @@ mod tests {
);
}
#[test]
fn get_autocomplete_snippet_map() {
let map_fn: Box<dyn StdLibFn> = Box::new(crate::std::array::Map);
let _snippet = map_fn.to_autocomplete_snippet().unwrap();
}
#[test]
fn get_autocomplete_snippet_pattern_linear_2d() {
let pattern_fn: Box<dyn StdLibFn> = Box::new(crate::std::patterns::PatternLinear2D);