LSP: Update examples to use new KCL stdlib

This commit is contained in:
Adam Chalmers
2025-01-06 16:14:13 -06:00
committed by Nick Cameron
parent b079af20da
commit bdeda51078
17 changed files with 218 additions and 176 deletions

View File

@ -18,7 +18,7 @@ line(sketch: Sketch, end_absolute?: [number], end?: [number], tag?: TagDeclarato
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `sketch` | [`Sketch`](/docs/kcl/types/Sketch) | Which sketch should this path be added to? | Yes |
| `end_absolute` | `[number]` | Which absolute point should this line go to? Incompatible with `to`. | No |
| `end_absolute` | `[number]` | Which absolute point should this line go to? Incompatible with `end`. | No |
| `end` | `[number]` | How far away (along the X and Y axes) should this line go? Incompatible with `endAbsolute`. | No |
| `tag` | [`TagDeclarator`](/docs/kcl/types#tag-declaration) | Create a new tag which refers to this line | No |

View File

@ -112,6 +112,7 @@ impl crate::docs::StdLibFn for SomeFn {
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
}
@ -127,6 +128,7 @@ impl crate::docs::StdLibFn for SomeFn {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -112,6 +112,7 @@ impl crate::docs::StdLibFn for SomeFn {
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
}
@ -127,6 +128,7 @@ impl crate::docs::StdLibFn for SomeFn {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -170,6 +170,7 @@ impl crate::docs::StdLibFn for Show {
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
}
@ -185,6 +186,7 @@ impl crate::docs::StdLibFn for Show {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -113,6 +113,7 @@ impl crate::docs::StdLibFn for Show {
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
}
@ -128,6 +129,7 @@ impl crate::docs::StdLibFn for Show {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -171,6 +171,7 @@ impl crate::docs::StdLibFn for MyFunc {
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
}
@ -186,6 +187,7 @@ impl crate::docs::StdLibFn for MyFunc {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -172,6 +172,7 @@ impl crate::docs::StdLibFn for LineTo {
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
},
crate::docs::StdLibFnArg {
name: "sketch".to_string(),
@ -180,6 +181,7 @@ impl crate::docs::StdLibFn for LineTo {
required: true,
label_required: true,
description: "the sketch you're adding the line to".to_string(),
include_in_snippet: true,
},
]
}
@ -196,6 +198,7 @@ impl crate::docs::StdLibFn for LineTo {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -170,6 +170,7 @@ impl crate::docs::StdLibFn for Min {
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
}
@ -185,6 +186,7 @@ impl crate::docs::StdLibFn for Min {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -113,6 +113,7 @@ impl crate::docs::StdLibFn for Show {
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
}
@ -128,6 +129,7 @@ impl crate::docs::StdLibFn for Show {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -113,6 +113,7 @@ impl crate::docs::StdLibFn for Import {
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
}
@ -128,6 +129,7 @@ impl crate::docs::StdLibFn for Import {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -113,6 +113,7 @@ impl crate::docs::StdLibFn for Import {
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
}
@ -128,6 +129,7 @@ impl crate::docs::StdLibFn for Import {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -113,6 +113,7 @@ impl crate::docs::StdLibFn for Import {
required: false,
label_required: true,
description: String::new().to_string(),
include_in_snippet: false,
}]
}
@ -128,6 +129,7 @@ impl crate::docs::StdLibFn for Import {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -113,6 +113,7 @@ impl crate::docs::StdLibFn for Show {
required: true,
label_required: true,
description: String::new().to_string(),
include_in_snippet: true,
}]
}
@ -128,6 +129,7 @@ impl crate::docs::StdLibFn for Show {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -120,6 +120,7 @@ impl crate::docs::StdLibFn for SomeFunction {
required: true,
label_required: true,
description: String::new(),
include_in_snippet: true,
})
}

View File

@ -60,6 +60,7 @@ pub struct StdLibFnArg {
/// If the argument is required.
pub required: bool,
/// Include this in completion snippets?
#[serde(default, skip_serializing_if = "is_false")]
pub include_in_snippet: bool,
/// Additional information that could be used instead of the type's description.
/// This is helpful if the type is really basic, like "u32" -- that won't tell the user much about
@ -81,6 +82,10 @@ fn its_true() -> bool {
true
}
fn is_false(b: &bool) -> bool {
!b
}
impl StdLibFnArg {
/// If the argument is a primitive.
pub fn is_primitive(&self) -> Result<bool> {
@ -115,7 +120,7 @@ impl StdLibFnArg {
} else if self.type_ == "KclValue" && self.required {
return Ok(Some((index, format!("{label}${{{}:{}}}", index, "3"))));
}
self.get_autocomplete_snippet_from_schema(&self.schema.schema.clone().into(), index)
self.get_autocomplete_snippet_from_schema(&self.schema.schema.clone().into(), index, in_keyword_fn)
.map(|maybe| maybe.map(|(index, snippet)| (index, format!("{label}{snippet}"))))
}
@ -132,6 +137,7 @@ impl StdLibFnArg {
&self,
schema: &schemars::schema::Schema,
index: usize,
in_keyword_fn: bool,
) -> Result<Option<(usize, String)>> {
match schema {
schemars::schema::Schema::Object(o) => {
@ -146,7 +152,7 @@ impl StdLibFnArg {
}
if let Some(serde_json::Value::Bool(nullable)) = o.extensions.get("nullable") {
if *nullable && !self.include_in_snippet {
if (!in_keyword_fn && *nullable) || (in_keyword_fn && !self.include_in_snippet) {
return Ok(None);
}
}
@ -160,7 +166,12 @@ impl StdLibFnArg {
return Ok(Some((index, format!(r#"${{{}:"tag_or_edge_fn"}}"#, index))));
} else if format == "double" {
return Ok(Some((index, format!(r#"${{{}:3.14}}"#, index))));
} else if format == "uint" || format == "int64" || format == "uint32" || format == "uint64" {
} else if format == "uint"
|| format == "int64"
|| format == "uint32"
|| format == "uint64"
|| format == "uint8"
{
return Ok(Some((index, format!(r#"${{{}:10}}"#, index))));
} else {
anyhow::bail!("unknown format: {}", format);
@ -189,7 +200,7 @@ impl StdLibFnArg {
continue;
}
if let Some((new_index, snippet)) = self.get_autocomplete_snippet_from_schema(prop, i)? {
if let Some((new_index, snippet)) = self.get_autocomplete_snippet_from_schema(prop, i, false)? {
fn_docs.push_str(&format!("\t{} = {},\n", prop_name, snippet));
i = new_index + 1;
}
@ -211,7 +222,11 @@ impl StdLibFnArg {
"[{}]",
(0..val)
.map(|v| self
.get_autocomplete_snippet_from_schema(items, index + (v as usize))
.get_autocomplete_snippet_from_schema(
items,
index + (v as usize),
in_keyword_fn
)
.unwrap()
.unwrap()
.1)
@ -225,7 +240,7 @@ impl StdLibFnArg {
index,
format!(
"[{}]",
self.get_autocomplete_snippet_from_schema(items, index)?
self.get_autocomplete_snippet_from_schema(items, index, in_keyword_fn)?
.ok_or_else(|| anyhow::anyhow!("expected snippet"))?
.1
),
@ -237,7 +252,7 @@ impl StdLibFnArg {
index,
format!(
"[{}]",
self.get_autocomplete_snippet_from_schema(items, index)?
self.get_autocomplete_snippet_from_schema(items, index, in_keyword_fn)?
.ok_or_else(|| anyhow::anyhow!("expected snippet"))?
.1
),
@ -280,7 +295,7 @@ impl StdLibFnArg {
return Ok(Some((index, parsed_enum_values[0].to_string())));
} else if let Some(item) = items.iter().next() {
if let Some((new_index, snippet)) =
self.get_autocomplete_snippet_from_schema(item, index)?
self.get_autocomplete_snippet_from_schema(item, index, in_keyword_fn)?
{
i = new_index + 1;
fn_docs.push_str(&snippet);
@ -289,7 +304,7 @@ impl StdLibFnArg {
} else if let Some(items) = &subschemas.any_of {
if let Some(item) = items.iter().next() {
if let Some((new_index, snippet)) =
self.get_autocomplete_snippet_from_schema(item, index)?
self.get_autocomplete_snippet_from_schema(item, index, in_keyword_fn)?
{
i = new_index + 1;
fn_docs.push_str(&snippet);
@ -451,11 +466,11 @@ pub trait StdLibFn: std::fmt::Debug + Send + Sync {
} else if self.name() == "hole" {
return Ok("hole(${0:holeSketch}, ${1:%})${}".to_string());
}
let is_keyword_fn = self.keyword_arguments();
let in_keyword_fn = self.keyword_arguments();
let mut args = Vec::new();
let mut index = 0;
for arg in self.args(true).iter() {
if let Some((i, arg_str)) = arg.get_autocomplete_snippet(index, is_keyword_fn)? {
if let Some((i, arg_str)) = arg.get_autocomplete_snippet(index, in_keyword_fn)? {
index = i + 1;
args.push(arg_str);
}
@ -691,6 +706,7 @@ fn get_autocomplete_string_from_schema(schema: &schemars::schema::Schema) -> Res
return Ok(Primitive::Uuid.to_string());
} else if format == "double"
|| format == "uint"
|| format == "uint8"
|| format == "int64"
|| format == "uint32"
|| format == "uint64"
@ -898,7 +914,7 @@ mod tests {
fn get_autocomplete_snippet_extrude() {
let extrude_fn: Box<dyn StdLibFn> = Box::new(crate::std::extrude::Extrude);
let snippet = extrude_fn.to_autocomplete_snippet().unwrap();
assert_eq!(snippet, r#"extrude(${0:3.14}, ${1:%})${}"#);
assert_eq!(snippet, r#"extrude(${0:%}, length: ${1:3.14})${}"#);
}
#[test]

View File

@ -725,11 +725,11 @@ async fn test_kcl_lsp_completions_tags() {
version: 1,
text: r#"part001 = startSketchOn('XY')
|> startProfileAt([11.19, 28.35], %)
|> line([28.67, -13.25], %, $here)
|> line([-4.12, -22.81], %)
|> line([-33.24, 14.55], %)
|> close(%)
|> extrude(5, %)"#
|> line(end = [28.67, -13.25], tag = $here)
|> line(end = [-4.12, -22.81])
|> line(end = [-33.24, 14.55])
|> close()
|> extrude(length = 5)"#
.to_string(),
},
})
@ -1113,11 +1113,11 @@ async fn test_kcl_lsp_semantic_tokens_with_modifiers() {
version: 1,
text: r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %, $seg01)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)
|> line(end = [20, 0])
|> line(end = [0, 20], tag = $seg01)
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)
thing = {blah: "foo"}
bar = thing.blah
@ -1415,11 +1415,11 @@ async fn test_kcl_lsp_document_symbol_tag() {
version: 1,
text: r#"part001 = startSketchOn('XY')
|> startProfileAt([11.19, 28.35], %)
|> line([28.67, -13.25], %, $here)
|> line([-4.12, -22.81], %)
|> line([-33.24, 14.55], %)
|> close(%)
|> extrude(5, %)"#
|> line(end = [28.67, -13.25], tag = $here)
|> line(end = [-4.12, -22.81])
|> line(end = [-33.24, 14.55])
|> close()
|> extrude(length = 5)"#
.to_string(),
},
})
@ -1518,15 +1518,15 @@ overHangLength = .4
// Sketch and revolve the inside bearing piece
insideRevolve = startSketchOn('XZ')
|> startProfileAt([insideDia / 2, 0], %)
|> line([0, thickness + sphereDia / 2], %)
|> line([overHangLength, 0], %)
|> line([0, -thickness], %)
|> line([-overHangLength + thickness, 0], %)
|> line([0, -sphereDia], %)
|> line([overHangLength - thickness, 0], %)
|> line([0, -thickness], %)
|> line([-overHangLength, 0], %)
|> close(%)
|> line(end = [0, thickness + sphereDia / 2])
|> line(end = [overHangLength, 0])
|> line(end = [0, -thickness])
|> line(end = [-overHangLength + thickness, 0])
|> line(end = [0, -sphereDia])
|> line(end = [overHangLength - thickness, 0])
|> line(end = [0, -thickness])
|> line(end = [-overHangLength, 0])
|> close()
|> revolve({ axis: 'y' }, %)
// Sketch and revolve one of the balls and duplicate it using a circular pattern. (This is currently a workaround, we have a bug with rotating on a sketch that touches the rotation axis)
@ -1535,13 +1535,13 @@ sphere = startSketchOn('XZ')
0.05 + insideDia / 2 + thickness,
0 - 0.05
], %)
|> line([sphereDia - 0.1, 0], %)
|> line(end = [sphereDia - 0.1, 0])
|> arc({
angle_start: 0,
angle_end: -180,
radius: sphereDia / 2 - 0.05
}, %)
|> close(%)
|> close()
|> revolve({ axis: 'x' }, %)
|> patternCircular3d({
axis: [0, 0, 1],
@ -1557,15 +1557,15 @@ outsideRevolve = startSketchOn('XZ')
insideDia / 2 + thickness + sphereDia,
0
], %)
|> line([0, sphereDia / 2], %)
|> line([-overHangLength + thickness, 0], %)
|> line([0, thickness], %)
|> line([overHangLength, 0], %)
|> line([0, -2 * thickness - sphereDia], %)
|> line([-overHangLength, 0], %)
|> line([0, thickness], %)
|> line([overHangLength - thickness, 0], %)
|> close(%)
|> line(end = [0, sphereDia / 2])
|> line(end = [-overHangLength + thickness, 0])
|> line(end = [0, thickness])
|> line(end = [overHangLength, 0])
|> line(end = [0, -2 * thickness - sphereDia])
|> line(end = [-overHangLength, 0])
|> line(end = [0, thickness])
|> line(end = [overHangLength - thickness, 0])
|> close()
|> revolve({ axis: 'y' }, %)"#
.to_string(),
},
@ -1619,15 +1619,15 @@ overHangLength = .4
// Sketch and revolve the inside bearing piece
insideRevolve = startSketchOn('XZ')
|> startProfileAt([insideDia / 2, 0], %)
|> line([0, thickness + sphereDia / 2], %)
|> line([overHangLength, 0], %)
|> line([0, -thickness], %)
|> line([-overHangLength + thickness, 0], %)
|> line([0, -sphereDia], %)
|> line([overHangLength - thickness, 0], %)
|> line([0, -thickness], %)
|> line([-overHangLength, 0], %)
|> close(%)
|> line(end = [0, thickness + sphereDia / 2])
|> line(end = [overHangLength, 0])
|> line(end = [0, -thickness])
|> line(end = [-overHangLength + thickness, 0])
|> line(end = [0, -sphereDia])
|> line(end = [overHangLength - thickness, 0])
|> line(end = [0, -thickness])
|> line(end = [-overHangLength, 0])
|> close()
|> revolve({ axis = 'y' }, %)
// Sketch and revolve one of the balls and duplicate it using a circular pattern. (This is currently a workaround, we have a bug with rotating on a sketch that touches the rotation axis)
@ -1636,13 +1636,13 @@ sphere = startSketchOn('XZ')
0.05 + insideDia / 2 + thickness,
0 - 0.05
], %)
|> line([sphereDia - 0.1, 0], %)
|> line(end = [sphereDia - 0.1, 0])
|> arc({
angle_start = 0,
angle_end = -180,
radius = sphereDia / 2 - 0.05
}, %)
|> close(%)
|> close()
|> revolve({ axis = 'x' }, %)
|> patternCircular3d({
axis = [0, 0, 1],
@ -1658,15 +1658,15 @@ outsideRevolve = startSketchOn('XZ')
insideDia / 2 + thickness + sphereDia,
0
], %)
|> line([0, sphereDia / 2], %)
|> line([-overHangLength + thickness, 0], %)
|> line([0, thickness], %)
|> line([overHangLength, 0], %)
|> line([0, -2 * thickness - sphereDia], %)
|> line([-overHangLength, 0], %)
|> line([0, thickness], %)
|> line([overHangLength - thickness, 0], %)
|> close(%)
|> line(end = [0, sphereDia / 2])
|> line(end = [-overHangLength + thickness, 0])
|> line(end = [0, thickness])
|> line(end = [overHangLength, 0])
|> line(end = [0, -2 * thickness - sphereDia])
|> line(end = [-overHangLength, 0])
|> line(end = [0, thickness])
|> line(end = [overHangLength - thickness, 0])
|> close()
|> revolve({ axis = 'y' }, %)"#
);
}
@ -1907,8 +1907,8 @@ async fn test_copilot_lsp_completions_raw() {
|> startProfileAt([0, 0], %)
"#
.to_string(),
r#" |> close(%)
|> extrude(10, %)"#
r#" |> close()
|> extrude(length = 10)"#
.to_string(),
)
.await
@ -1926,8 +1926,8 @@ async fn test_copilot_lsp_completions_raw() {
|> startProfileAt([0, 0], %)
"#
.to_string(),
r#" |> close(%)
|> extrude(10, %)"#
r#" |> close()
|> extrude(length = 10)"#
.to_string(),
)
.await
@ -1965,8 +1965,8 @@ async fn test_copilot_lsp_completions() {
source: r#"bracket = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> close(%)
|> extrude(10, %)
|> close()
|> extrude(length = 10)
"#
.to_string(),
tab_size: 4,
@ -2234,15 +2234,15 @@ async fn kcl_test_kcl_lsp_update_units() {
let same_text = r#"fn cube = (pos, scale) => {
sg = startSketchOn('XY')
|> startProfileAt(pos, %)
|> line([0, scale], %)
|> line([scale, 0], %)
|> line([0, -scale], %)
|> line(end = [0, scale])
|> line(end = [scale, 0])
|> line(end = [0, -scale])
return sg
}
part001 = cube([0,0], 20)
|> close(%)
|> extrude(20, %)"#
|> close()
|> extrude(length = 20)"#
.to_string();
// Send open file.
@ -2259,7 +2259,7 @@ part001 = cube([0,0], 20)
// Get the tokens.
let tokens = server.token_map.get("file:///test.kcl").unwrap().clone();
assert_eq!(tokens.as_slice().len(), 120);
assert_eq!(tokens.as_slice().len(), 123);
// Get the ast.
let ast = server.ast_map.get("file:///test.kcl").unwrap().clone();
@ -2382,11 +2382,11 @@ async fn kcl_test_kcl_lsp_diagnostics_on_execution_error() {
version: 1,
text: r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)
|> fillet({
radius: 3.14,
tags: ["tag_or_edge_fn"],
@ -2403,11 +2403,11 @@ async fn kcl_test_kcl_lsp_diagnostics_on_execution_error() {
// Update the text.
let new_text = r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#
.to_string();
// Send change file.
server
@ -2441,11 +2441,11 @@ async fn kcl_test_kcl_lsp_full_to_empty_file_updates_ast_and_memory() {
version: 1,
text: r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#
.to_string(),
},
})
@ -2490,11 +2490,11 @@ async fn kcl_test_kcl_lsp_code_unchanged_but_has_diagnostics_reexecute() {
let code = r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -2583,11 +2583,11 @@ async fn kcl_test_kcl_lsp_code_and_ast_unchanged_but_has_diagnostics_reexecute()
let code = r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -2671,11 +2671,11 @@ async fn kcl_test_kcl_lsp_code_and_ast_units_unchanged_but_has_diagnostics_reexe
let code = r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -2762,11 +2762,11 @@ async fn kcl_test_kcl_lsp_code_and_ast_units_unchanged_but_has_memory_reexecute_
let code = r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -2832,11 +2832,11 @@ async fn kcl_test_kcl_lsp_cant_execute_set() {
let code = r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -3029,10 +3029,10 @@ async fn kcl_test_kcl_lsp_code_with_parse_error_and_ast_unchanged_but_has_diagno
let code = r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> ^^^things(3.14, %)"#;
// Send open file.
@ -3084,11 +3084,11 @@ async fn kcl_test_kcl_lsp_code_with_lint_and_ast_unchanged_but_has_diagnostics_r
let code = r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -3138,10 +3138,10 @@ async fn kcl_test_kcl_lsp_code_with_lint_and_parse_error_and_ast_unchanged_but_h
let code = r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> ^^^^thing(3.14, %)"#;
// Send open file.
@ -3193,11 +3193,11 @@ async fn kcl_test_kcl_lsp_code_lint_and_ast_unchanged_but_has_diagnostics_reexec
let code = r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %, $seg01)
|> line([-20, 0], %, $seg01)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20], tag = $seg01)
|> line(end = [-20, 0], tag = $seg01)
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -3258,11 +3258,11 @@ async fn kcl_test_kcl_lsp_code_lint_reexecute_new_lint() {
let code = r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %, $seg01)
|> line([-20, 0], %, $seg01)
|> close(%)
|> extrude(3.14, %)"#;
|> line(end = [20, 0])
|> line(end = [0, 20], tag = $seg01)
|> line(end = [-20, 0], tag = $seg01)
|> close()
|> extrude(length = 3.14)"#;
// Send open file.
server
@ -3300,11 +3300,11 @@ part001 = startSketchOn('XY')
range_length: None,
text: r#"part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %, $seg01)
|> line([-20, 0], %, $seg01)
|> close(%)
|> extrude(3.14, %)
|> line(end = [20, 0])
|> line(end = [0, 20], tag = $seg01)
|> line(end = [-20, 0], tag = $seg01)
|> close()
|> extrude(length = 3.14)
NEW_LINT = 1"#
.to_string(),
}],
@ -3331,10 +3331,10 @@ async fn kcl_test_kcl_lsp_code_lint_reexecute_new_ast_error() {
let code = r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %, $seg01)
|> line([-20, 0], %, $seg01)
|> close(%)
|> line(end = [20, 0])
|> line(end = [0, 20], tag = $seg01)
|> line(end = [-20, 0], tag = $seg01)
|> close()
|> ^^^extrude(3.14, %)"#;
// Send open file.
@ -3373,11 +3373,11 @@ part001 = startSketchOn('XY')
range_length: None,
text: r#"part001 = startSketchOn('XY')
|> ^^^^startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %, $seg01)
|> line([-20, 0], %, $seg01)
|> close(%)
|> extrude(3.14, %)
|> line(end = [20, 0])
|> line(end = [0, 20], tag = $seg01)
|> line(end = [-20, 0], tag = $seg01)
|> close()
|> extrude(length = 3.14)
NEW_LINT = 1"#
.to_string(),
}],
@ -3404,10 +3404,10 @@ async fn kcl_test_kcl_lsp_code_lint_reexecute_had_lint_new_parse_error() {
let code = r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
"#;
// Send open file.
@ -3455,11 +3455,11 @@ part001 = startSketchOn('XY')
range_length: None,
text: r#"part001 = startSketchOn('XY')
|> ^^^^startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> extrude(3.14, %)
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
|> extrude(length = 3.14)
NEW_LINT = 1"#
.to_string(),
}],
@ -3495,10 +3495,10 @@ async fn kcl_test_kcl_lsp_code_lint_reexecute_had_lint_new_execution_error() {
let code = r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %)
|> line([0, 20], %)
|> line([-20, 0], %)
|> close(%)
|> line(end = [20, 0])
|> line(end = [0, 20])
|> line(end = [-20, 0])
|> close()
"#;
// Send open file.
@ -3551,10 +3551,10 @@ part001 = startSketchOn('XY')
text: r#"LINT = 1
part001 = startSketchOn('XY')
|> startProfileAt([-10, -10], %)
|> line([20, 0], %, $seg01)
|> line([0, 20], %, $seg01)
|> line([-20, 0], %)
|> close(%)
|> line(end = [20, 0], tag = $seg01)
|> line(end = [0, 20], tag = $seg01)
|> line(end = [-20, 0])
|> close()
"#
.to_string(),
}],

View File

@ -92,7 +92,7 @@ pub enum StartOrEnd {
End,
}
pub const NEW_TAG_KW: &'static str = "tag";
pub const NEW_TAG_KW: &str = "tag";
/// Draw a line to a point.
pub async fn line(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
@ -1461,7 +1461,7 @@ pub(crate) fn inner_profile_start(sketch: Sketch) -> Result<[f64; 2], KclError>
/// Close the current sketch.
pub async fn close(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let sketch = args.get_unlabeled_kw_arg("sketch")?;
let tag = args.get_kw_arg_opt("tag");
let tag = args.get_kw_arg_opt(NEW_TAG_KW);
let new_sketch = inner_close(sketch, tag, exec_state, args).await?;
Ok(KclValue::Sketch {
value: Box::new(new_sketch),