Move solids functions to KCL (#7214)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -618,6 +618,12 @@ impl FnData {
|
||||
pub(super) fn to_autocomplete_snippet(&self) -> String {
|
||||
if self.name == "loft" {
|
||||
return "loft([${0:sketch000}, ${1:sketch001}])".to_owned();
|
||||
} else if self.name == "union" {
|
||||
return "union([${0:extrude001}, ${1:extrude002}])".to_owned();
|
||||
} else if self.name == "subtract" {
|
||||
return "subtract([${0:extrude001}], tools = [${1:extrude002}])".to_owned();
|
||||
} else if self.name == "intersect" {
|
||||
return "intersect([${0:extrude001}, ${1:extrude002}])".to_owned();
|
||||
} else if self.name == "clone" {
|
||||
return "clone(${0:part001})".to_owned();
|
||||
} else if self.name == "hole" {
|
||||
@ -802,15 +808,12 @@ impl ArgData {
|
||||
return Some((index + n - 1, snippet));
|
||||
}
|
||||
match self.ty.as_deref() {
|
||||
Some(s) if s.starts_with("number") => Some((index, format!(r#"{label}${{{}:3.14}}"#, index))),
|
||||
Some("Point2d") => Some((
|
||||
index + 1,
|
||||
format!(r#"{label}[${{{}:3.14}}, ${{{}:3.14}}]"#, index, index + 1),
|
||||
)),
|
||||
Some(s) if s.starts_with("number") => Some((index, format!(r#"{label}${{{}:10}}"#, index))),
|
||||
Some("Point2d") => Some((index + 1, format!(r#"{label}[${{{}:0}}, ${{{}:0}}]"#, index, index + 1))),
|
||||
Some("Point3d") => Some((
|
||||
index + 2,
|
||||
format!(
|
||||
r#"{label}[${{{}:3.14}}, ${{{}:3.14}}, ${{{}:3.14}}]"#,
|
||||
r#"{label}[${{{}:0}}, ${{{}:0}}, ${{{}:0}}]"#,
|
||||
index,
|
||||
index + 1,
|
||||
index + 2
|
||||
|
@ -578,12 +578,6 @@ pub trait StdLibFn: std::fmt::Debug + Send + Sync {
|
||||
fn to_autocomplete_snippet(&self) -> Result<String> {
|
||||
if self.name() == "loft" {
|
||||
return Ok("loft([${0:sketch000}, ${1:sketch001}])".to_string());
|
||||
} else if self.name() == "union" {
|
||||
return Ok("union([${0:extrude001}, ${1:extrude002}])".to_string());
|
||||
} else if self.name() == "subtract" {
|
||||
return Ok("subtract([${0:extrude001}], tools = [${1:extrude002}])".to_string());
|
||||
} else if self.name() == "intersect" {
|
||||
return Ok("intersect([${0:extrude001}, ${1:extrude002}])".to_string());
|
||||
} else if self.name() == "subtract2D" {
|
||||
return Ok("subtract2d(${0:%}, tool = ${1:%})".to_string());
|
||||
}
|
||||
@ -994,7 +988,7 @@ mod tests {
|
||||
panic!();
|
||||
};
|
||||
let snippet = fillet_fn.to_autocomplete_snippet();
|
||||
assert_eq!(snippet, r#"fillet(radius = ${0:3.14}, tags = [${1:tag_or_edge_fn}])"#);
|
||||
assert_eq!(snippet, r#"fillet(radius = ${0:10}, tags = [${1:tag_or_edge_fn}])"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1014,11 +1008,14 @@ mod tests {
|
||||
#[test]
|
||||
fn get_autocomplete_snippet_pattern_circular_3d() {
|
||||
// We test this one specifically because it has ints and floats and strings.
|
||||
let pattern_fn: Box<dyn StdLibFn> = Box::new(crate::std::patterns::PatternCircular3D);
|
||||
let snippet = pattern_fn.to_autocomplete_snippet().unwrap();
|
||||
let data = kcl_doc::walk_prelude();
|
||||
let DocData::Fn(data) = data.find_by_name("patternCircular3d").unwrap() else {
|
||||
panic!();
|
||||
};
|
||||
let snippet = data.to_autocomplete_snippet();
|
||||
assert_eq!(
|
||||
snippet,
|
||||
r#"patternCircular3d(${0:%}, instances = ${1:10}, axis = [${2:1}, ${3:0}, ${4:0}], center = [${5:0}, ${6:0}, ${7:0}])"#
|
||||
r#"patternCircular3d(instances = ${0:10}, axis = [${1:1}, ${2:0}, ${3:0}], center = [${4:0}, ${5:0}, ${6:0}])"#
|
||||
);
|
||||
}
|
||||
|
||||
@ -1040,7 +1037,7 @@ mod tests {
|
||||
};
|
||||
let snippet = circle_fn.to_autocomplete_snippet();
|
||||
assert_eq!(
|
||||
snippet, r#"circle(center = [${0:0}, ${1:0}], diameter = ${2:3.14})"#,
|
||||
snippet, r#"circle(center = [${0:0}, ${1:0}], diameter = ${2:10})"#,
|
||||
"actual = left, expected = right"
|
||||
);
|
||||
}
|
||||
@ -1115,28 +1112,37 @@ mod tests {
|
||||
let snippet = helix_fn.to_autocomplete_snippet();
|
||||
assert_eq!(
|
||||
snippet,
|
||||
r#"helix(revolutions = ${0:3.14}, angleStart = ${1:3.14}, radius = ${2:3.14}, axis = ${3:X}, length = ${4:3.14})"#
|
||||
r#"helix(revolutions = ${0:10}, angleStart = ${1:10}, radius = ${2:10}, axis = ${3:X}, length = ${4:10})"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_autocomplete_snippet_union() {
|
||||
let union_fn: Box<dyn StdLibFn> = Box::new(crate::std::csg::Union);
|
||||
let snippet = union_fn.to_autocomplete_snippet().unwrap();
|
||||
let data = kcl_doc::walk_prelude();
|
||||
let DocData::Fn(data) = data.find_by_name("union").unwrap() else {
|
||||
panic!();
|
||||
};
|
||||
let snippet = data.to_autocomplete_snippet();
|
||||
assert_eq!(snippet, r#"union([${0:extrude001}, ${1:extrude002}])"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_autocomplete_snippet_subtract() {
|
||||
let subtract_fn: Box<dyn StdLibFn> = Box::new(crate::std::csg::Subtract);
|
||||
let snippet = subtract_fn.to_autocomplete_snippet().unwrap();
|
||||
let data = kcl_doc::walk_prelude();
|
||||
let DocData::Fn(data) = data.find_by_name("subtract").unwrap() else {
|
||||
panic!();
|
||||
};
|
||||
let snippet = data.to_autocomplete_snippet();
|
||||
assert_eq!(snippet, r#"subtract([${0:extrude001}], tools = [${1:extrude002}])"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_autocomplete_snippet_intersect() {
|
||||
let intersect_fn: Box<dyn StdLibFn> = Box::new(crate::std::csg::Intersect);
|
||||
let snippet = intersect_fn.to_autocomplete_snippet().unwrap();
|
||||
let data = kcl_doc::walk_prelude();
|
||||
let DocData::Fn(data) = data.find_by_name("intersect").unwrap() else {
|
||||
panic!();
|
||||
};
|
||||
let snippet = data.to_autocomplete_snippet();
|
||||
assert_eq!(snippet, r#"intersect([${0:extrude001}, ${1:extrude002}])"#);
|
||||
}
|
||||
|
||||
@ -1197,7 +1203,7 @@ mod tests {
|
||||
panic!();
|
||||
};
|
||||
let snippet = offset_plane_fn.to_autocomplete_snippet();
|
||||
assert_eq!(snippet, r#"offsetPlane(${0:XY}, offset = ${1:3.14})"#);
|
||||
assert_eq!(snippet, r#"offsetPlane(${0:XY}, offset = ${1:10})"#);
|
||||
}
|
||||
|
||||
// We want to test the snippets we compile at lsp start.
|
||||
|
Reference in New Issue
Block a user