Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ kittycad = { version = "0.3.37", default-features = false, features = [
"js",
"requests",
] }
kittycad-modeling-cmds = { version = "0.2.131", features = [
"ts-rs",
"websocket",
] }
kittycad-modeling-cmds = { git = "https://github.com/KittyCAD/modeling-api.git", rev = "d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7", features = ["ts-rs","websocket"] }
lazy_static = "1.5.0"
miette = "7.6.0"
pyo3 = { version = "0.25.1" }
Expand Down
24 changes: 24 additions & 0 deletions rust/kcl-lib/src/execution/kcl_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@ impl From<&KclValue> for SourceRange {
}

impl KclValue {
pub(crate) fn id(&self) -> Option<uuid::Uuid> {
match self {
KclValue::Uuid { value, .. } => Some(*value),
KclValue::Bool { .. } => None,
KclValue::Number { .. } => None,
KclValue::String { .. } => None,
KclValue::Tuple { .. } => None,
KclValue::HomArray { .. } => None,
KclValue::Object { .. } => None,
KclValue::TagIdentifier(tag) => tag.get_cur_info().map(|info| info.id),
KclValue::TagDeclarator(_) => None,
KclValue::Plane { value } => Some(value.id),
KclValue::Face { value } => Some(value.id),
KclValue::Sketch { value } => Some(value.id),
KclValue::Solid { value } => Some(value.id),
KclValue::Helix { value } => Some(value.value),
KclValue::ImportedGeometry(imported_geometry) => Some(imported_geometry.id),
KclValue::Function { .. } => None,
KclValue::Module { .. } => None,
KclValue::Type { .. } => None,
KclValue::KclNone { .. } => None,
}
}

pub(crate) fn metadata(&self) -> Vec<Metadata> {
match self {
KclValue::Uuid { value: _, meta } => meta.clone(),
Expand Down
28 changes: 28 additions & 0 deletions rust/kcl-lib/src/std/label.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::errors::KclErrorDetails;

Check warning on line 1 in rust/kcl-lib/src/std/label.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/modeling-app/modeling-app/rust/kcl-lib/src/std/label.rs
use crate::std::Args;
use crate::{ExecState, KclError};
use crate::exec::KclValue;
use crate::execution::types::RuntimeType;

use kittycad_modeling_cmds::ModelingCmd;
use kittycad_modeling_cmds::each_cmd as mcmd;

pub async fn label(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let item: KclValue = args.get_unlabeled_kw_arg("item", &RuntimeType::any(), exec_state)?;
let text: String = args.get_kw_arg("text", &RuntimeType::string(), exec_state)?;
if let Some(id) = item.id() {
let command = ModelingCmd::from(mcmd::SetLabel {
object_id: id,
label: text,
});
let _ = exec_state.send_modeling_cmd((&args).into(), command).await?;
Ok(KclValue::none())
} else {
Err(KclError::Type {
details: KclErrorDetails::new(

Check warning on line 22 in rust/kcl-lib/src/std/label.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/modeling-app/modeling-app/rust/kcl-lib/src/std/label.rs
format!("This type is not suitable for labeling"),
vec![args.source_range.into()],
)
})
}
}
5 changes: 5 additions & 0 deletions rust/kcl-lib/src/std/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod edge;
pub mod extrude;
pub mod fillet;
pub mod helix;
pub mod label;
pub mod loft;
pub mod math;
pub mod mirror;
Expand Down Expand Up @@ -194,6 +195,10 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|e, a| Box::pin(crate::std::assert::assert_is(e, a)),
StdFnProps::default("std::assertIs"),
),
("prelude", "label") => (
|e, a| Box::pin(crate::std::label::label(e, a)),
StdFnProps::default("std::label"),
),
("solid", "fillet") => (
|e, a| Box::pin(crate::std::fillet::fillet(e, a)),
StdFnProps::default("std::solid::fillet").include_in_feature_tree(),
Expand Down
4 changes: 4 additions & 0 deletions rust/kcl-lib/std/prelude.kcl
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,7 @@ export fn assert(
/// If the value was false, the program will terminate with this error message
error?: string,
) {}

/// Set a label.
@(impl = std_rust)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark this as experimental until we settle on the final API.

Suggested change
@(impl = std_rust)
@(impl = std_rust, experimental = true)

You'll want to use @settings(experimentalFeatures = allow) at the top of your KCL file to be able to call it.

export fn label(@item: any, text: string): {}
Loading