2024-03-13 12:56:46 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test_examples_show {
|
2024-05-15 10:17:29 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_mock_example_show0() {
|
2024-11-07 11:23:41 -05:00
|
|
|
let program =
|
2024-12-06 13:57:31 +13:00
|
|
|
crate::Program::parse_no_errs("This is another code block.\nyes sirrr.\nshow").unwrap();
|
2024-05-15 10:17:29 -07:00
|
|
|
let ctx = crate::executor::ExecutorContext {
|
|
|
|
engine: std::sync::Arc::new(Box::new(
|
|
|
|
crate::engine::conn_mock::EngineConnection::new()
|
|
|
|
.await
|
|
|
|
.unwrap(),
|
|
|
|
)),
|
|
|
|
fs: std::sync::Arc::new(crate::fs::FileManager::new()),
|
|
|
|
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
|
|
|
|
settings: Default::default(),
|
2024-10-01 12:45:01 -07:00
|
|
|
context_type: crate::executor::ContextType::Mock,
|
2024-05-15 10:17:29 -07:00
|
|
|
};
|
2024-11-20 15:19:25 +13:00
|
|
|
ctx.run(&program, &mut crate::ExecState::default())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-05-15 10:17:29 -07:00
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
|
2024-08-12 13:06:30 -07:00
|
|
|
async fn kcl_test_example_show0() {
|
2024-07-31 09:54:46 -05:00
|
|
|
let code = "This is another code block.\nyes sirrr.\nshow";
|
|
|
|
let result =
|
|
|
|
crate::test_server::execute_and_snapshot(code, crate::settings::types::UnitLength::Mm)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-26 21:28:50 -07:00
|
|
|
twenty_twenty::assert_image(
|
|
|
|
&format!("tests/outputs/{}.png", "serial_test_example_show0"),
|
2024-07-31 09:54:46 -05:00
|
|
|
&result,
|
2024-07-15 17:41:41 -05:00
|
|
|
0.99,
|
2024-03-26 21:28:50 -07:00
|
|
|
);
|
2024-03-13 12:56:46 -07:00
|
|
|
}
|
|
|
|
|
2024-05-15 10:17:29 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
|
|
async fn test_mock_example_show1() {
|
2024-12-06 13:57:31 +13:00
|
|
|
let program =
|
|
|
|
crate::Program::parse_no_errs("This is code.\nIt does other shit.\nshow").unwrap();
|
2024-05-15 10:17:29 -07:00
|
|
|
let ctx = crate::executor::ExecutorContext {
|
|
|
|
engine: std::sync::Arc::new(Box::new(
|
|
|
|
crate::engine::conn_mock::EngineConnection::new()
|
|
|
|
.await
|
|
|
|
.unwrap(),
|
|
|
|
)),
|
|
|
|
fs: std::sync::Arc::new(crate::fs::FileManager::new()),
|
|
|
|
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
|
|
|
|
settings: Default::default(),
|
2024-10-01 12:45:01 -07:00
|
|
|
context_type: crate::executor::ContextType::Mock,
|
2024-05-15 10:17:29 -07:00
|
|
|
};
|
2024-11-20 15:19:25 +13:00
|
|
|
ctx.run(&program, &mut crate::ExecState::default())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-05-15 10:17:29 -07:00
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
|
2024-08-12 13:06:30 -07:00
|
|
|
async fn kcl_test_example_show1() {
|
2024-07-31 09:54:46 -05:00
|
|
|
let code = "This is code.\nIt does other shit.\nshow";
|
|
|
|
let result =
|
|
|
|
crate::test_server::execute_and_snapshot(code, crate::settings::types::UnitLength::Mm)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-26 21:28:50 -07:00
|
|
|
twenty_twenty::assert_image(
|
|
|
|
&format!("tests/outputs/{}.png", "serial_test_example_show1"),
|
2024-07-31 09:54:46 -05:00
|
|
|
&result,
|
2024-07-15 17:41:41 -05:00
|
|
|
0.99,
|
2024-03-26 21:28:50 -07:00
|
|
|
);
|
2024-03-13 12:56:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
#[allow(non_camel_case_types, missing_docs)]
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = "Std lib function: show\nThis is some function.\nIt does shit."]
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, schemars :: JsonSchema, ts_rs :: TS)]
|
|
|
|
#[ts(export)]
|
|
|
|
pub(crate) struct Show {}
|
|
|
|
|
|
|
|
#[allow(non_upper_case_globals, missing_docs)]
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = "Std lib function: show\nThis is some function.\nIt does shit."]
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
pub(crate) const Show: Show = Show {};
|
|
|
|
fn boxed_show(
|
2024-09-16 15:10:33 -04:00
|
|
|
exec_state: &mut crate::executor::ExecState,
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
args: crate::std::Args,
|
|
|
|
) -> std::pin::Pin<
|
|
|
|
Box<
|
|
|
|
dyn std::future::Future<
|
2024-08-12 16:53:24 -05:00
|
|
|
Output = anyhow::Result<crate::executor::KclValue, crate::errors::KclError>,
|
2024-09-16 15:10:33 -04:00
|
|
|
> + Send
|
|
|
|
+ '_,
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
>,
|
|
|
|
> {
|
2024-09-16 15:10:33 -04:00
|
|
|
Box::pin(show(exec_state, args))
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl crate::docs::StdLibFn for Show {
|
|
|
|
fn name(&self) -> String {
|
|
|
|
"show".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn summary(&self) -> String {
|
2024-03-13 12:56:46 -07:00
|
|
|
"This is some function.".to_string()
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn description(&self) -> String {
|
2024-03-13 12:56:46 -07:00
|
|
|
"It does shit.".to_string()
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn tags(&self) -> Vec<String> {
|
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
|
2024-12-05 14:27:51 -06:00
|
|
|
fn keyword_arguments(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2024-09-28 11:51:08 -07:00
|
|
|
fn args(&self, inline_subschemas: bool) -> Vec<crate::docs::StdLibFnArg> {
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
2024-09-28 11:51:08 -07:00
|
|
|
settings.inline_subschemas = inline_subschemas;
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
|
|
|
vec![crate::docs::StdLibFnArg {
|
|
|
|
name: "args".to_string(),
|
|
|
|
type_: "[number]".to_string(),
|
2024-09-30 12:30:22 -07:00
|
|
|
schema: generator.root_schema_for::<[f64; 2usize]>(),
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
required: true,
|
2024-12-05 14:27:51 -06:00
|
|
|
label_required: true,
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
|
2024-09-28 11:51:08 -07:00
|
|
|
fn return_value(&self, inline_subschemas: bool) -> Option<crate::docs::StdLibFnArg> {
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
let mut settings = schemars::gen::SchemaSettings::openapi3();
|
2024-09-28 11:51:08 -07:00
|
|
|
settings.inline_subschemas = inline_subschemas;
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
let mut generator = schemars::gen::SchemaGenerator::new(settings);
|
2024-09-30 12:30:22 -07:00
|
|
|
let schema = generator.root_schema_for::<f64>();
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
Some(crate::docs::StdLibFnArg {
|
|
|
|
name: "".to_string(),
|
|
|
|
type_: "number".to_string(),
|
2024-09-28 11:51:08 -07:00
|
|
|
schema,
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
required: true,
|
2024-12-05 14:27:51 -06:00
|
|
|
label_required: true,
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unpublished(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn deprecated(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
fn examples(&self) -> Vec<String> {
|
|
|
|
let code_blocks = vec![
|
|
|
|
"This is another code block.\nyes sirrr.\nshow",
|
|
|
|
"This is code.\nIt does other shit.\nshow",
|
|
|
|
];
|
|
|
|
code_blocks
|
|
|
|
.iter()
|
|
|
|
.map(|cb| {
|
2024-12-06 13:57:31 +13:00
|
|
|
let program = crate::Program::parse_no_errs(cb).unwrap();
|
2024-12-05 17:56:49 +13:00
|
|
|
let mut options: crate::parsing::ast::types::FormatOptions = Default::default();
|
2024-03-13 12:56:46 -07:00
|
|
|
options.insert_final_newline = false;
|
2024-11-20 15:19:25 +13:00
|
|
|
program.ast.recast(&options, 0)
|
2024-03-13 12:56:46 -07:00
|
|
|
})
|
|
|
|
.collect::<Vec<String>>()
|
|
|
|
}
|
|
|
|
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
fn std_lib_fn(&self) -> crate::std::StdFn {
|
|
|
|
boxed_show
|
|
|
|
}
|
|
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn crate::docs::StdLibFn> {
|
|
|
|
Box::new(self.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-13 12:56:46 -07:00
|
|
|
#[doc = r" This is some function."]
|
|
|
|
#[doc = r" It does shit."]
|
|
|
|
#[doc = r""]
|
|
|
|
#[doc = r" This is code."]
|
|
|
|
#[doc = r" It does other shit."]
|
|
|
|
#[doc = r" show"]
|
|
|
|
#[doc = r""]
|
|
|
|
#[doc = r" ```"]
|
|
|
|
#[doc = r" This is another code block."]
|
|
|
|
#[doc = r" yes sirrr."]
|
|
|
|
#[doc = r" show"]
|
|
|
|
#[doc = r" ```"]
|
2024-03-12 12:54:45 -07:00
|
|
|
fn inner_show(#[doc = r" The args to do shit to."] args: [f64; 2]) -> Result<Box<f64>> {
|
Remove just one enum (#1096)
# Problem
This is my proposal for fixing #1107 . I've only done it for one stdlib function, `tangentialArcTo` -- if y'all like it, I'll apply this idea to the rest of the stdlib.
Previously, if users want to put a tag on the arc, the function's parameters change type.
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is object
tangentialArcTo({to: [x, y], tag: "myTag"}, %)
```
# Solution
My proposal in #1006 is that KCL should have optional values. This means we can change the stdlib `tangentialArcTo` function to use them. In this PR, the calls are now like
```
// Tag missing: first param is array
tangentialArcTo([x, y], %)
// Tag present: first param is array still, but we now pass a tag at the end.
tangentialArcTo([x, y], %, "myTag")
```
This adds an "option" type to KCL typesystem, but it's not really revealed to users (no KCL types are revealed to users right now, they write untyped code and only interact with types when they get type errors upon executing programs). Also adds a None type, which is the default case of the Optional enum.
2023-12-18 23:49:32 -06:00
|
|
|
args
|
|
|
|
}
|