2024-12-10 18:50:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								mod  cache ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-03 01:05:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								use   kcl_lib ::{ 
  
						 
					
						
							
								
									
										
										
										
											2025-03-03 10:26:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     test_server ::{ execute_and_export_step ,   execute_and_snapshot ,   execute_and_snapshot_no_auth } , 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ExecError , 
  
						 
					
						
							
								
									
										
										
										
											2024-10-03 01:05:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-12 14:59:40 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-15 17:41:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/// The minimum permissible difference between asserted twenty-twenty images.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/// i.e. how different the current model snapshot can be from the previous saved one.
  
						 
					
						
							
								
									
										
										
										
											2024-12-10 18:50:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pub ( crate )   const   MIN_DIFF : f64  =   0.99 ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-15 17:41:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								macro_rules !   kcl_input   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     ( $file :literal )   = >   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         include_str! ( concat! ( " inputs/ " ,   $file ,   " .kcl " ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 18:50:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pub ( crate )   fn  assert_out ( test_name : & str ,   result : & image ::DynamicImage )   -> String  { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   path   =   format! ( " e2e/executor/outputs/ {test_name} .png " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-12-10 18:50:22 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     twenty_twenty ::assert_image ( & path ,   result ,   MIN_DIFF ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     path 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-05 11:52:45 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_fillet_duplicate_tags ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " fillet_duplicate_tags " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-05 11:52:45 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-12 11:24:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . expect_err ( " Code should have failed due to the duplicate edges being filletted " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   err   =   err . as_kcl_error ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-05 11:52:45 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
									
										
										
										
											2025-03-12 11:24:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         err . message ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         " The same edge ID is being referenced multiple times, which is not allowed. Please select a different edge " 
  
						 
					
						
							
								
									
										
										
										
											2024-03-05 11:52:45 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-04-28 14:20:38 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( err . source_ranges ( ) . len ( ) ,   3 ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-05 11:52:45 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-18 17:31:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_execute_engine_error_return ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 5.5229 ,   5.25217 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10.50433 ,   - 1.19122 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 8.01362 ,   - 5.48731 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 1.02877 ,   - 6.76825 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 11.53311 ,   2.81559 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   4 ) 
  
						 
					
						
							
								
									
										
										
										
											2023-09-18 17:31:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   expected_msg   =   " engine: Modeling command failed: [ApiError { error_code: BadRequest, message:  \" The path is not closed.  Solid2D construction requires a closed path! \"  }] " ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   err   =   result . unwrap_err ( ) . as_kcl_error ( ) . unwrap ( ) . get_message ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( err ,   expected_msg ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-18 17:31:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-09-19 14:20:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-27 09:46:13 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_execute_i_shape ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-03-27 09:46:13 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     // This is some code from lee that starts a pipe expression with a variable.
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " i_shape " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-27 09:46:13 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " i_shape " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-27 09:46:13 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-19 14:20:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-03-28 13:11:09 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ ignore ]   // No longer a stack overflow problem, instead it causes an engine internal error.
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_execute_pipes_on_pipes ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " pipes_on_pipes " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-19 14:20:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " pipes_on_pipes " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-19 14:20:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-09-19 16:05:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-08 15:06:41 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_execute_cylinder ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " cylinder " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-11-08 15:06:41 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " cylinder " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-11-08 15:06:41 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-20 19:35:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_execute_kittycad_svg ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " kittycad_svg " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-20 19:35:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " kittycad_svg " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-20 19:35:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-29 21:40:31 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async   fn  kcl_test_execute_lsystem ( )   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " lsystem " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-10-29 21:40:31 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " lsystem " ,   & result ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-19 16:05:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-09-27 15:44:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_member_expression_sketch ( )   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " member_expression_sketch " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-19 16:05:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-09-27 15:44:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " member_expression_sketch " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-19 16:05:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-09-25 12:14:41 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_helix_defaults ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-31 15:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " helix_defaults " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " helix_defaults " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_helix_defaults_negative_extrude ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-31 15:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " helix_defaults_negative_extrude " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " helix_defaults_negative_extrude " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_helix_with_length ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-31 15:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " helix_with_length " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " helix_with_length " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_dimensions_match ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-31 15:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " dimensions_match " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " dimensions_match " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-25 17:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_close_arc ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-31 15:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " close_arc " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-25 12:14:41 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " close_arc " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-25 12:14:41 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-09-25 15:25:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_negative_args ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-31 15:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " negative_args " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-25 15:25:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " negative_args " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-25 15:25:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-09-29 14:41:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_basic_tangential_arc_with_point ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 16:32:46 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" boxSketch = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   tangentialArc ( end   =   [ - 5 ,   5 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 5 ,   - 15 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2023-09-29 14:41:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " tangential_arc_with_point " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-29 14:41:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_basic_tangential_arc_to ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 16:32:46 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" boxSketch = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   tangentialArc ( endAbsolute   =   [ - 5 ,   15 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 5 ,   - 15 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2023-09-29 14:41:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " tangential_arc_to " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-09-29 14:41:14 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_different_planes_same_drawing ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" width = 5
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								height   =   10 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								length   =   12 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  box ( sk1 ,   sk2 ,   scale ,   plane )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   boxsketch   =   startSketchOn ( plane ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ sk1 ,   sk2 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   scale ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   return   boxsketch 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								box ( 0 ,   0 ,   5 ,   ' xy ' ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								box ( 10 ,   23 ,   8 ,   ' xz ' ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								box ( 30 ,   43 ,   18 ,   ' - xy ' ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								thing   =   box ( - 12 ,   - 15 ,   10 ,   ' yz ' ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								box ( - 20 ,   - 5 ,   10 ,   ' xy ' ) " #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " different_planes_same_drawing " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_lots_of_planes ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" sigmaAllow = 15000 // psi
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								width   =   11   // inch
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								p   =   150   // Force on shelf - lbs
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								distance   =   12   // inches
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								FOS   =   2 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								thickness   =   sqrt ( distance   *   p   *   FOS   *   6   /   ( sigmaAllow   *   width ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								filletR   =   thickness   *   2 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								shelfMountL   =   9 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								wallMountL   =   8 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bracket   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   wallMountL ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   tangentialArc ( radius   =   filletR ,   angle   =   90   ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - shelfMountL ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - thickness ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ shelfMountL ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   tangentialArc ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        radius   =   filletR   -   thickness , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angle   =   - 90 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - wallMountL ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   width ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ - 15.53 ,   - 10.28 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10.49 ,   - 2.08 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10.42 ,   8.47 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 19.16 ,   5.1 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   4 ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part002   =   startSketchOn ( ' - XZ ' ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ - 9.35 ,   19.18 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 32.14 ,   - 2.47 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 8.39 ,   - 3.73 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part003   =   startSketchOn ( ' - XZ ' ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 13.82 ,   16.51 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 6.24 ,   - 30.82 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 8.39 ,   - 3.73 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part004   =   startSketchOn ( YZ ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 19.04 ,   20.22 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 9.44 ,   - 30.16 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 8.39 ,   - 3.73 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " lots_of_planes " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-10-05 14:27:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_holes ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" square = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( center   =   [ 2 ,   2 ] ,   radius =   . 5 ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( center   =   [ 2 ,   8 ] ,   radius =   . 5 ) ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " holes " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02: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 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async   fn  optional_params ( )   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   code   =   r #" 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     fn  other_circle ( pos ,   radius ,   tag ? )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-18 17:40:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         | >   arc ( angleEnd   =   360 ,   angleStart   =   0 ,   radius   =   radius ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         | >   extrude ( length   =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08: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 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   } 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								thing   =   other_circle ( [ 2 ,   2 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												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 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " optional_params " ,   & result ) ; 
  
						 
					
						
							
								
									
										
											 
										
											
												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 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_rounded_with_holes ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn tarc(to, sktch, tag?) {
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   return   tangentialArc ( sktch ,   endAbsolute   =   to ,   tag   =   tag ) 
  
						 
					
						
							
								
									
										
											 
										
											
												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 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  roundedRectangle ( pos ,   w ,   l ,   cornerRadius )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   rr   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ pos [ 0 ]   -   w / 2 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( endAbsolute   =   [ pos [ 0 ]   -   w / 2 ,   pos [ 1 ]   -   l / 2   +   cornerRadius ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-24 14:45:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   tarc ( [ pos [ 0 ]   -   w / 2   +   cornerRadius ,   pos [ 1 ]   -   l / 2 ] ,   % ,   $arc0 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( endAbsolute   =   [ pos [ 0 ]   +   w / 2   -   cornerRadius ,   pos [ 1 ]   -   l / 2 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												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 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   tarc ( [ pos [ 0 ]   +   w / 2 ,   pos [ 1 ]   -   l / 2   +   cornerRadius ] ,   % ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( endAbsolute   =   [ pos [ 0 ]   +   w / 2 ,   pos [ 1 ]   +   l / 2   -   cornerRadius ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-24 14:45:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   tarc ( [ pos [ 0 ]   +   w / 2   -   cornerRadius ,   pos [ 1 ]   +   l / 2 ] ,   % ,   $arc2 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( endAbsolute   =   [ pos [ 0 ]   -   w / 2   +   cornerRadius ,   pos [ 1 ]   +   l / 2 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												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 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   tarc ( [ pos [ 0 ]   -   w / 2 ,   pos [ 1 ]   +   l / 2   -   cornerRadius ] ,   % ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   return   rr 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								holeRadius   =   1 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								holeIndex   =   6 
  
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part   =   roundedRectangle ( [ 0 ,   0 ] ,   20 ,   20 ,   4 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( center   =   [ - holeIndex ,   holeIndex ] ,   radius =   holeRadius ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( center   =   [ holeIndex ,   holeIndex ] ,   radius =   holeRadius ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( center   =   [ - holeIndex ,   - holeIndex ] ,   radius =   holeRadius ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( center   =   [ holeIndex ,   - holeIndex ] ,   radius =   holeRadius ) ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " rounded_with_holes " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-10-13 12:02:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2023-11-09 13:08:11 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_top_level_expression ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r # "startSketchOn(XY) |> circle(center = [0,0], radius= 22) |> extrude(length = 14)"# ; 
  
						 
					
						
							
								
									
										
										
										
											2023-11-09 13:08:11 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " top_level_expression " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2023-11-09 13:08:11 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-23 15:59:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_linear_basic_with_math ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" num = 12
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								distance   =   5 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part   =    startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 0 , 0 ] ,   radius =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternLinear2d ( axis   =   [ 0 , 1 ] ,   instances   =   num ,   distance   =   distance   -   1 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-04-23 15:59:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_linear_basic_with_math " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-04-23 15:59:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_linear_basic ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part =  startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 0 , 0 ] ,   radius =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternLinear2d ( axis   =   [ 0 , 1 ] ,   instances   =   13 ,   distance   =   4 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_linear_basic " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_linear_basic_3d ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 , 1 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 1 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - 1 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternLinear3d ( axis   =   [ 1 ,   0 ,   1 ] ,   instances   =   4 ,   distance   =   6 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_linear_basic_3d " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_linear_basic_negative_distance ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 0 , 0 ] ,   radius =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternLinear2d ( axis   =   [ 0 , 1 ] ,   instances   =   13 ,   distance   =   - 2 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_linear_basic_negative_distance " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_linear_basic_negative_axis ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 0 , 0 ] ,   radius =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternLinear2d ( axis   =   [ 0 , - 1 ] ,   instances   =   13 ,   distance   =   2 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_linear_basic_negative_axis " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_linear_basic_holes ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" circles = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 5 ,   5 ] ,   radius =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternLinear2d ( axis   =   [ 1 , 1 ] ,   instances   =   13 ,   distance   =   3 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								rectangle   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   50 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 50 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 50 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circles ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_linear_basic_holes " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-11 15:08:54 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-13 13:20:49 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_circular_basic_2d ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 0 , 0 ] ,   radius =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternCircular2d ( center   =   [ 20 ,   20 ] ,   instances   =   13 ,   arcDegrees   =   210 ,   rotateDuplicates   =   true ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-13 13:20:49 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_circular_basic_2d " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-13 13:20:49 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_circular_basic_3d ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 , 1 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 1 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - 1 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternCircular3d ( axis   =   [ 0 , 0 ,   1 ] ,   center   =   [ - 20 ,   - 20 ,   - 20 ] ,   instances   =   41 ,   arcDegrees   =   360 ,   rotateDuplicates   =   false ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-13 13:20:49 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_circular_basic_3d " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-13 13:20:49 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_patterns_circular_3d_tilted_axis ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 , 1 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 1 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - 1 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   patternCircular3d ( axis   =   [ 1 , 1 , 0 ] ,   center   =   [ 10 ,   0 ,   10 ] ,   instances   =   11 ,   arcDegrees   =   360 ,   rotateDuplicates   =   true ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-13 13:20:49 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " patterns_circular_3d_tilted_axis " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-13 13:20:49 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_file_doesnt_exist ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" import 'thing.obj'
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								model   =   cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "semantic: KclErrorDetails { source_ranges: [SourceRange([0, 18, 0])], message: "File `thing.obj` does not exist." }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_obj_with_mtl ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" import 'e2e/executor/inputs/cube.obj'
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								model   =   cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " import_obj_with_mtl " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_obj_with_mtl_units ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" @(format = obj, lengthUnit = m)
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import   ' e2e / executor / inputs / cube . obj ' 
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								model   =   cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " import_obj_with_mtl_units " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 15:55:59 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_stl ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" import 'e2e/executor/inputs/2-5-long-m8-chc-screw.stl' as screw
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								model   =   screw " #;
  
						 
					
						
							
								
									
										
										
										
											2024-07-17 15:55:59 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " import_stl " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-17 15:55:59 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_gltf_with_bin ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" import 'e2e/executor/inputs/cube.gltf'
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								model   =   cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " import_gltf_with_bin " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_gltf_embedded ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" import 'e2e/executor/inputs/cube-embedded.gltf' as cube
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								model   =   cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " import_gltf_embedded " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_glb ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" import 'e2e/executor/inputs/cube.glb'
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								model   =   cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " import_glb " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_glb_no_assign ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" import 'e2e/executor/inputs/cube.glb'
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " import_glb_no_assign " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_import_ext_doesnt_match ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" @(format = obj, lengthUnit = m)
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import   ' e2e / executor / inputs / cube . gltf ' 
  
						 
					
						
							
								
									
										
										
										
											2025-02-13 06:24:27 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								model   =   cube " #;
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "semantic: KclErrorDetails { source_ranges: [SourceRange([32, 70, 0])], message: "The given format does not match the file extension. Expected: `gltf`, Given: `obj`" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-02-12 12:18:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_cube_mm ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   scale ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								myCube   =   cube ( [ 0 , 0 ] ,   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " cube_mm " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_cube_cm ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" @settings(defaultLengthUnit = cm)
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  cube ( pos ,   scale )   { 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   scale ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								myCube   =   cube ( [ 0 , 0 ] ,   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " cube_cm " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_cube_m ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" @settings(defaultLengthUnit = m)
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  cube ( pos ,   scale )   { 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   scale ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								myCube   =   cube ( [ 0 , 0 ] ,   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " cube_m " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_cube_in ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" @settings(defaultLengthUnit = in)
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  cube ( pos ,   scale )   { 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   scale ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								myCube   =   cube ( [ 0 , 0 ] ,   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " cube_in " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_cube_ft ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" @settings(defaultLengthUnit = ft)
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  cube ( pos ,   scale )   { 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   scale ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								myCube   =   cube ( [ 0 , 0 ] ,   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " cube_ft " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_cube_yd ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" @settings(defaultLengthUnit = yd)
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  cube ( pos ,   scale )   { 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   scale ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								myCube   =   cube ( [ 0 , 0 ] ,   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " cube_yd " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-20 17:55:06 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 19:07:17 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_error_sketch_on_arc_face ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   tangentialArc ( end   =   [ 0 ,   scale ] ,   tag   =   $here ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 19:07:17 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   cube ( [ 0 ,   0 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 19:07:17 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part002   =   startSketchOn ( part001 ,   face   =   part001 . sketch . tags . here ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 5 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 5 ,   5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   1 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 19:07:17 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 19:07:17 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . err ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   ExecError ::Kcl ( err )   =   err   else   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         panic! ( " Expected KCL error, found  {err} " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 19:07:17 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         err . error . message ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         " could not sketch tangential arc, because its center would be infinitely far away in the X direction " 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 19:07:17 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:54:42 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_sketch_on_face_of_face ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:54:42 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   cube ( [ 0 , 0 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:54:42 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part002   =   startSketchOn ( part001 ,   face   =   END ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   5 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:54:42 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part003   =   startSketchOn ( part002 ,   face   =   END ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 5 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   5 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:54:42 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " sketch_on_face_of_face " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:54:42 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-03-05 12:46:05 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_stdlib_kcl_error_right_code_path ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" square = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( center   =   [ 2 ,   8 ] ,   radius =   . 5 ) ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-05 12:46:05 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . err ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   ExecError ::Kcl ( err )   =   err   else   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         panic! ( " Expected KCL error, found  {err} " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         err . error . message ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         " This function requires a keyword argument 'center' " 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-05 12:46:05 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-03-07 14:53:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_sketch_on_face_circle ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-07 14:53:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   cube ( [ 0 , 0 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-07 14:53:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part002   =   startSketchOn ( part001 ,   face   =   END ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   circle ( center   =   [ 0 ,   0 ] ,   radius =   5 )  
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   5 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-07 14:53:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " sketch_on_face_circle " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-07 14:53:37 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-03-07 15:35:26 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_stdlib_kcl_error_circle ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" // Mounting Plate
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// A flat piece of material, often metal or plastic, that serves as a support or base for attaching, securing, or mounting various types of equipment, devices, or components. 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Create a function that defines the body width and length of the mounting plate. Tag the corners so they can be passed through the fillet function.
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  rectShape ( pos ,   w ,   l )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   rr   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ pos [ 0 ]   -   ( w   /   2 ) ,   pos [ 1 ]   -   ( l   /   2 ) ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ pos [ 0 ]   +   w   /   2 ,   pos [ 1 ]   -   ( l   /   2 ) ] ,   tag   =   $edge1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ pos [ 0 ]   +   w   /   2 ,   pos [ 1 ]   +   l   /   2 ] ,   tag   =   $edge2 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ pos [ 0 ]   -   ( w   /   2 ) ,   pos [ 1 ]   +   l   /   2 ] ,   tag   =   $edge3 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( tag   =   $edge4 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   return   rr 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Define the hole radius and x, y location constants
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								holeRadius   =   1 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								holeIndex   =   6 
  
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Create the mounting plate extrusion, holes, and fillets
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part   =   rectShape ( [ 0 ,   0 ] ,   20 ,   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( ' XY ' ,   center   =   [ - holeIndex ,   holeIndex ] ,   radius   =   holeRadius ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( ' XY ' ,   center   =   [ holeIndex ,   holeIndex ] ,   radius   =   holeRadius ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( ' XY ' ,   center   =   [ - holeIndex ,   - holeIndex ] ,   radius   =   holeRadius ) ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   circle ( ' XY ' ,   center   =   [ holeIndex ,   - holeIndex ] ,   radius   =   holeRadius ) ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   2 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        radius   =   4 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tags   =   [ 
  
						 
					
						
							
								
									
										
										
										
											2024-07-27 22:56:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								           getNextAdjacentEdge ( edge1 ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           getNextAdjacentEdge ( edge2 ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           getNextAdjacentEdge ( edge3 ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								           getNextAdjacentEdge ( edge4 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ] 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . err ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   ExecError ::Kcl ( err )   =   err   else   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         panic! ( " Expected KCL error, found  {err} " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         err . error . message ( ) , 
  
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         " This function expected the input argument to be of type SketchOrSurface but it's actually of type string (text) " 
  
						 
					
						
							
								
									
										
										
										
											2024-03-11 13:37:22 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-03-20 20:44:52 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_simple_revolve ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   Y ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " simple_revolve " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_simple_revolve_uppercase ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   Y ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " simple_revolve_uppercase " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_simple_revolve_negative ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   - Y ,   angle   =   180 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " simple_revolve_negative " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_revolve_bad_angle_low ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   Y ,   angle   =   - 455 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . err ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . unwrap ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . to_string ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . contains ( " Expected angle to be between -360 and 360 and not 0, found `-455` " ) ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_revolve_bad_angle_high ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   Y ,   angle   =   455 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . err ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . unwrap ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . to_string ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . contains ( " Expected angle to be between -360 and 360 and not 0, found `455` " ) ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_simple_revolve_custom_angle ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   Y ,   angle   =   180 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " simple_revolve_custom_angle " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_simple_revolve_custom_axis ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   {   direction   =   [ 0 ,   - 1 ] ,   origin   =   [ 0 , 0 ]   } ,   angle   =   180 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " simple_revolve_custom_axis " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_revolve_on_edge ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" box = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ,   tag   =   $revolveAxis ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   startSketchOn ( box ,   face   =   END ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 5 ,   10 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   revolve ( axis   =   getOppositeEdge ( revolveAxis ) ,   angle   =   90 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " revolve_on_edge " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_revolve_on_edge_get_edge ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" box = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ,   tag   =   $revolveAxis ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   startSketchOn ( box ,   face   =   revolveAxis ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 5 ,   10 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   revolve ( axis   =   revolveAxis ,   angle   =   90 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-04-15 19:37:59 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     result . unwrap_err ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-08-29 15:27:00 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     //this fails right now, but slightly differently, lets just say its enough for it to fail - mike
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     //assert_eq!(
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     //    result.err().unwrap().to_string(),
  
						 
					
						
							
								
									
										
										
										
											2024-11-07 11:23:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     //    r#"engine: KclErrorDetails { source_ranges: [SourceRange([346, 390, 0])], message: "Modeling command failed: [ApiError { error_code: InternalEngine, message: \"Solid3D revolve failed:  sketch profile must lie entirely on one side of the revolution axis\" }]" }"#
  
						 
					
						
							
								
									
										
										
										
											2024-08-29 15:27:00 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     //);
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_revolve_on_face_circle_edge ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" box = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   20 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 20 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 20 ] ,   tag   =   $revolveAxis )  
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   startSketchOn ( box ,   face   =   " END " ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   circle ( center   =   [ 10 , 10 ] ,   radius =   4 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   revolve ( 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     angle   =   90 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     axis   =   getOppositeEdge ( revolveAxis ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " revolve_on_face_circle_edge " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_revolve_on_face_circle ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" box = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   20 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 20 ,   0 ] ,   tag   =   $revolveAxis ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 20 ] )  
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   startSketchOn ( box ,   face   =   " END " ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   circle ( center   =   [ 10 , 10 ] ,   radius =   4   ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   revolve ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     angle   =   - 90 ,  
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     axis   =   Y  
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " revolve_on_face_circle " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_revolve_on_face ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" box = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( tag   =   $revolveAxis ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   startSketchOn ( box ,   face   =   END ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 5 ,   10 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   revolve ( 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       axis   =   Y , 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       angle   =   - 90 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " revolve_on_face " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_basic_revolve_circle ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" sketch001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   circle ( center   =   [ 15 ,   0 ] ,   radius =   5 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   revolve ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     angle   =   360 ,  
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     axis   =   Y  
  
						 
					
						
							
								
									
										
										
										
											2025-03-18 20:34:44 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " basic_revolve_circle " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_simple_revolve_sketch_on_edge ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   startProfile ( at   =   [ 4 ,   12 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 4 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 6 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 3.75 ,   - 4.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ 0 ,   - 5.5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   line ( end   =   [ - 2 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-03 22:44:52 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      | >   revolve ( axis   =   Y ,   angle   =   180 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part002   =   startSketchOn ( part001 ,   face   =   END ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ 4.5 ,   - 5 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 5 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - 5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   5 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " simple_revolve_sketch_on_edge " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 19:07:16 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-03-29 15:06:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_plumbus_fillets ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn make_circle(ext, face, pos, radius) {
  
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( ext ,   face   =   face ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ pos [ 0 ]   +   radius ,   pos [ 1 ] ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-18 17:40:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   arc ( 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        angleEnd   =   360 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angleStart   =   0 , 
  
						 
					
						
							
								
									
										
										
										
											2025-04-18 17:40:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        radius   =   radius , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tag   =   $arc1 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-29 15:06:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  pentagon ( len )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ - len   /   2 ,   - len   /   2 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   0 ,   length   =   len ,   tag   =   $a ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angle   =   segAng ( a )   +   180   -   108 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        length   =   len , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tag   =   $b , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angle   =   segAng ( b )   +   180   -   108 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        length   =   len , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tag   =   $c , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angle   =   segAng ( c )   +   180   -   108 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        length   =   len , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tag   =   $d , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angle   =   segAng ( d )   +   180   -   108 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        length   =   len , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-29 15:06:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								p   =   pentagon ( 32 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-29 15:06:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								circle0   =   make_circle ( p ,   p . sketch . tags . a ,   [ 0 ,   0 ] ,   2.5 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								plumbus0   =   circle0 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        radius   =   0.5 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tags   =   [ circle0 . tags . arc1 ,   getOppositeEdge ( circle0 . tags . arc1 ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-29 15:06:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								circle1   =   make_circle ( p ,   p . sketch . tags . b ,   [ 0 ,   0 ] ,   2.5 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								plumbus1   =   circle1 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         radius   =   0.5 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         tags   =   [ circle1 . tags . arc1 ,   getOppositeEdge ( circle1 . tags . arc1 ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       ) 
  
						 
					
						
							
								
									
										
										
										
											2024-03-29 15:06:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " plumbus_fillets " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-03-29 15:06:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-04-02 18:28:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-15 17:18:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_empty_file_is_ok ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-04-15 17:18:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r # ""# ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     result . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-04-15 17:18:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-02 18:28:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_member_expression_in_params ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn capScrew(originStart, length, dia, capDia, capHeadLength) {
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   screwHead   =   startSketchOn ( { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       origin   =   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       x   =   originStart [ 0 ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       y   =   originStart [ 1 ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       z   =   originStart [ 2 ] , 
  
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       } , 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       xAxis   =   {   x   =   0 ,   y   =   0 ,   z   =   - 1   } , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       yAxis   =   {   x   =   1 ,   y   =   0 ,   z   =   0   } , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       zAxis   =   {   x   =   0 ,   y   =   1 ,   z   =   0   } 
  
						 
					
						
							
								
									
										
										
										
											2024-04-02 18:28:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   } ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 0 ,   0 ] ,   radius =   capDia   /   2 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   extrude ( length   =   capHeadLength ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   screw   =   startSketchOn ( screwHead ,   face   =   START ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   circle ( center   =   [ 0 ,   0 ] ,   radius =   dia   /   2 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   extrude ( length   =   length ) 
  
						 
					
						
							
								
									
										
										
										
											2024-04-02 18:28:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   return   screw 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								capScrew ( [ 0 ,   0.5 ,   0 ] ,   50 ,   37.5 ,   50 ,   25 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " member_expression_in_params " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-04-02 18:28:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-04-10 18:51:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-09-03 13:34:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_bracket_with_fillets ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-04-10 18:51:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" // Shelf Bracket
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// This is a shelf bracket made out of 6061-T6 aluminum sheet metal. The required thickness is calculated based on a point load of 300 lbs applied to the end of the shelf. There are two brackets holding up the shelf, so the moment experienced is divided by 2. The shelf is 1 foot long from the wall.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sigmaAllow   =   35000   // psi
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								width   =   6   // inch
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								p   =   300   // Force on shelf - lbs
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								distance   =   12   // inches
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								M   =   12   *   300   /   2   // Moment experienced at fixed end of bracket
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								FOS   =   2   // Factor of safety of 2
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								shelfMountL   =   8   // The length of the bracket holding up the shelf is 6 inches
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								wallMountL   =   8   // the length of the bracket
  
						 
					
						
							
								
									
										
										
										
											2024-04-10 18:51:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Calculate the thickness off the allowable bending stress and factor of safety
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								thickness   =   sqrt ( 6   *   M   *   FOS   /   ( width   *   sigmaAllow ) ) 
  
						 
					
						
							
								
									
										
										
										
											2024-04-10 18:51:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 0.25 inch fillet radius
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								filletR   =   0.25 
  
						 
					
						
							
								
									
										
										
										
											2024-04-10 18:51:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Sketch the bracket and extrude with fillets
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bracket   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   wallMountL ] ,   tag   =   $outerEdge ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - shelfMountL ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - thickness ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ shelfMountL   -   thickness ,   0 ] ,   tag   =   $innerEdge ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - wallMountL   +   thickness ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   width ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        radius   =   filletR , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tags   =   [ getNextAdjacentEdge ( innerEdge ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        radius   =   filletR   +   thickness , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tags   =   [ getNextAdjacentEdge ( outerEdge ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
										
										
											2024-04-10 18:51:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     result . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-04-10 18:51:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-05-20 21:59:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_error_empty_start_sketch_on_string ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" part001 = startSketchOn('-XZ')
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 75.75 ,   184.25 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 190.03 ,   - 118.13 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 33.38 ,   - 202.86 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 315.86 ,   - 64.2 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   tangentialArc ( endAbsolute   =   [ - 147.66 ,   121.34 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   100 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-05-20 21:59:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								secondSketch   =   startSketchOn ( part001 ,   face   =   ' ' ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   circle ( center   =   [ - 20 ,   50 ] ,   radius =   40 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-05-20 21:59:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . unwrap_err ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   err   =   err . as_kcl_error ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-05-20 21:59:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
									
										
										
										
											2025-04-11 14:17:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         err . message ( ) , 
  
						 
					
						
							
								
									
										
										
										
											2025-04-14 05:58:19 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         " The arg face was given, but it was the wrong type. It should be type FaceTag but it was string (text) " 
  
						 
					
						
							
								
									
										
										
										
											2024-05-20 21:59:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-05-21 00:49:57 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_error_user_function_wrong_args ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" length = .750
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								width   =   0.500 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								height   =   0.500 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								dia   =   4 
  
						 
					
						
							
								
									
										
										
										
											2024-05-21 00:49:57 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								fn  squareHole ( l ,   w )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   squareHoleSketch   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ - width   /   2 ,   - length   /   2 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ width   /   2 ,   - length   /   2 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ width   /   2 ,   length   /   2 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ - width   /   2 ,   length   /   2 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-05-21 00:49:57 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   return   squareHoleSketch 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								extrusion   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 17:40:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   circle ( center   =   [ 0 ,   0 ] ,   radius =   dia / 2   ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   subtract2d ( tool   =   squareHole ( length ,   width ,   height ) ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   extrude ( length   =   height ) 
  
						 
					
						
							
								
									
										
										
										
											2024-05-21 00:49:57 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-05-21 00:49:57 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-04-26 15:31:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   expected_msg   =   " semantic: Expected 2 arguments, got 3 " ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   err   =   result . unwrap_err ( ) . as_kcl_error ( ) . unwrap ( ) . get_message ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( err ,   expected_msg ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-05-21 00:49:57 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-05-21 23:35:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-21 16:44:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_array_of_sketches ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" plane001 = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 16:44:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								profile001   =   plane001 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 40.82 ,   240.82 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 235.72 ,   - 8.16 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 13.27 ,   - 253.07 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 247.97 ,   - 19.39 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ profileStartX ( % ) ,   profileStartY ( % ) ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 16:44:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								profile002   =   plane001 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 47.17 ,   - 71.91 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 247.96 ,   - 4.03 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 17.26 ,   - 116.79 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 235.87 ,   12.66 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ profileStartX ( % ) ,   profileStartY ( % ) ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 16:44:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   [ profile001 ,   profile002 ] 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 16:44:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  extrude ( sketch001 ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 16:44:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " array_of_sketches " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 16:44:31 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 19:54:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_circular_pattern3d_array_of_extrudes ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" plane001 = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 19:54:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   plane001 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 40.82 ,   240.82 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 235.72 ,   - 8.16 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 13.27 ,   - 253.07 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 247.97 ,   - 19.39 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ profileStartX ( % ) ,   profileStartY ( % ) ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 19:54:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch002   =   plane001 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 47.17 ,   - 71.91 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 247.96 ,   - 4.03 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 17.26 ,   - 116.79 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 235.87 ,   12.66 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ profileStartX ( % ) ,   profileStartY ( % ) ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 19:54:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								extrudes   =   [ sketch001 ,   sketch002 ]  
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 19:54:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pattn1   =   patternLinear3d ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        extrudes , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        axis   =   [ 0 ,   1 ,   0 ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        instances   =   3 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        distance   =   20 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 19:54:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " pattern3d_array_of_extrudes " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-21 19:54:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_fillets_referencing_other_fillets ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" // Z-Bracket
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Z-brackets are designed to affix or hang objects from a wall by securing them to the wall's studs. These brackets offer support and mounting solutions for bulky or heavy items that may be challenging to attach directly. Serving as a protective feature, Z-brackets help prevent heavy loads from moving or toppling, enhancing safety in the environment where they are used.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Define constants
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								foot1Length   =   4 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								height   =   4 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								foot2Length   =   5 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								width   =   4 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								filletRad   =   0.25 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								thickness   =   0.125 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								cornerFilletRad   =   0.5 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								holeDia   =   0.5 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   startSketchOn ( XZ ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ - foot1Length ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   thickness ] ,   tag   =   $cornerFillet1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ foot1Length ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   height ] ,   tag   =   $fillet1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ foot2Length ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - thickness ] ,   tag   =   $cornerFillet2 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - foot2Length + thickness ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - height ] ,   tag   =   $fillet2 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								baseExtrusion   =   extrude ( sketch001 ,   length   =   width ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     radius   =   cornerFilletRad , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     tags   =   [ cornerFillet1 ,   cornerFillet2 ,   getOppositeEdge ( cornerFillet1 ) ,   getOppositeEdge ( cornerFillet2 ) ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     radius   =   filletRad , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     tags   =   [ getPreviousAdjacentEdge ( fillet1 ) ,   getPreviousAdjacentEdge ( fillet2 ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    radius   =   filletRad   +   thickness , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags   =   [ getNextAdjacentEdge ( fillet1 ) ,   getNextAdjacentEdge ( fillet2 ) ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " fillets_referencing_other_fillets " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_chamfers_referencing_other_chamfers ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" // Z-Bracket
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Z-brackets are designed to affix or hang objects from a wall by securing them to the wall's studs. These brackets offer support and mounting solutions for bulky or heavy items that may be challenging to attach directly. Serving as a protective feature, Z-brackets help prevent heavy loads from moving or toppling, enhancing safety in the environment where they are used.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Define constants
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								foot1Length   =   4 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								height   =   4 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								foot2Length   =   5 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								width   =   4 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								chamferRad   =   0.25 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								thickness   =   0.125 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								cornerChamferRad   =   0.5 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								holeDia   =   0.5 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								sketch001   =   startSketchOn ( XZ ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ - foot1Length ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   thickness ] ,   tag   =   $cornerChamfer1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ foot1Length ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   height ] ,   tag   =   $chamfer1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ foot2Length ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - thickness ] ,   tag   =   $cornerChamfer2 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - foot2Length + thickness ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - height ] ,   tag   =   $chamfer2 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								baseExtrusion   =   extrude ( sketch001 ,   length   =   width ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   chamfer ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     length   =   cornerChamferRad , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     tags   =   [ cornerChamfer1 ,   cornerChamfer2 ,   getOppositeEdge ( cornerChamfer1 ) ,   getOppositeEdge ( cornerChamfer2 ) ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   chamfer ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     length   =   chamferRad , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     tags   =   [ getPreviousAdjacentEdge ( chamfer1 ) ,   getPreviousAdjacentEdge ( chamfer2 ) ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   chamfer ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    length   =   chamferRad   +   thickness , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags   =   [ getNextAdjacentEdge ( chamfer1 ) ,   getNextAdjacentEdge ( chamfer2 ) ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " chamfers_referencing_other_chamfers " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 14:31:37 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 16:22:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-08-13 16:25:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_shell_with_tag ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" sketch001 = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 61.74 ,   206.13 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-07 22:07:16 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   xLine ( length   =   305.11 ,   tag   =   $seg01 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   yLine ( length   =   - 291.85 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   xLine ( length   =   - segLen ( seg01 ) ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ profileStartX ( % ) ,   profileStartY ( % ) ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   40.14 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-06 20:03:12 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   shell ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     faces   =   [ seg01 ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     thickness   =   3.14 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 16:22:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-08-13 16:25:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " shell_with_tag " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-22 16:22:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_linear_pattern3d_filleted_sketch ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   cube ( [ 0 , 0 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   close ( tag   =   $line1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       radius   =   10 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       tags   =   [ getOppositeEdge ( line1 ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pattn1   =   patternLinear3d ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      part001 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      axis   =   [ 1 ,   0 ,   0 ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      instances   =   4 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      distance   =   40 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " linear_pattern3d_filleted_sketch " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_circular_pattern3d_filleted_sketch ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   cube ( [ 0 , 0 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   close ( tag   =   $line1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   fillet ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     radius   =   10 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     tags   =   [ getOppositeEdge ( line1 ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pattn2   =   patternCircular3d ( part001 ,   axis   =   [ 0 , 0 ,   1 ] ,   center   =   [ - 20 ,   - 20 ,   - 20 ] ,   instances   =   5 ,   arcDegrees   =   360 ,   rotateDuplicates   =   false )  
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " circular_pattern3d_filleted_sketch " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_circular_pattern3d_chamfered_sketch ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   cube ( [ 0 , 0 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   close ( tag   =   $line1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   chamfer ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       length   =   10 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       tags   =   [ getOppositeEdge ( line1 ) ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pattn2   =   patternCircular3d ( part001 ,   axis   =   [ 0 , 0 ,   1 ] ,   center   =   [ - 20 ,   - 20 ,   - 20 ] ,   instances   =   5 ,   arcDegrees   =   360 ,   rotateDuplicates   =   false ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " circular_pattern3d_chamfered_sketch " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 19:19:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 23:04:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_tag_chamfer_with_more_than_one_edge_should_fail ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn cube(pos, scale) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   sg   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   pos ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   scale ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ scale ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   - scale ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 23:04:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   return   sg 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-02 20:59:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								part001   =   cube ( [ 0 , 0 ] ,   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   close ( tag   =   $line1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     | >   extrude ( length   =   20 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-21 14:41:25 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   chamfer ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     length   =   10 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     tags   =   [ line1 ,   getOppositeEdge ( line1 ) ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     tag   =   $chamfer1 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 23:04:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . err ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   ExecError ::Kcl ( err )   =   err   else   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         panic! ( " Expected KCL error, found  {err} " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 23:04:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         err . error . message ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         " You can only tag one edge at a time with a tagged chamfer. Either delete the tag for the chamfer fn if you don't need it OR separate into individual chamfer functions for each tag. " 
  
						 
					
						
							
								
									
										
										
										
											2024-06-23 23:04:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-24 14:45:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_duplicate_tags_should_error ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn triangle(len) {
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   return   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ - len   /   2 ,   - len   /   2 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   0 ,   length   =   len   ,   tag   =   $a ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angle   =   segAng ( a )   +   120 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        length   =   len , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tag   =   $b , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angle   =   segAng ( b )   +   120 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        length   =   len , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tag   =   $a , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-24 14:45:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								p   =   triangle ( 200 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-06-24 14:45:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . unwrap_err ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   err   =   err . as_kcl_error ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( err . message ( ) ,   " Cannot redefine `a` " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-24 14:45:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-06-25 10:35:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_global_tags ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " global-tags " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " global_tags " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-25 10:35:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-06-27 22:20:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-27 22:56:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_extrude_inside_fn_with_tags ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " extrude-inside-fn-with-tags " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " extrude-inside-fn-with-tags " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-27 22:56:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 22:20:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_pattern_vase ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " pattern_vase " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " pattern_vase " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-06-27 22:20:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-07-05 15:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-05 16:53:13 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_scoped_tags ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " scoped-tags " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " scoped_tags " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-05 16:53:13 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-05 15:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_order_sketch_extrude_in_order ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " order-sketch-extrude-in-order " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " order-sketch-extrude-in-order " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-05 15:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_order_sketch_extrude_out_of_order ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " order-sketch-extrude-out-of-order " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " order-sketch-extrude-out-of-order " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-05 15:37:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-07-09 23:39:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_extrude_custom_plane ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " extrude-custom-plane " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 11:14:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_out ( " extrude-custom-plane " ,   & result ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-09 23:39:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 16:09:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_arc_error_same_start_end ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-18 17:40:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   arc ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angleStart   =   180 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        angleEnd   =   180 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        radius   =   1.5 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-11 16:06:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   patternCircular2d ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        arcDegrees   =   360 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        center   =   [ 0 ,   0 ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        instances   =   6 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        rotateDuplicates   =   true 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 16:09:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-04-18 17:40:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   err   =   result . expect_err ( " Code should have failed due to end angle === start angle " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   err   =   err . as_kcl_error ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( err . message ( ) ,   " Arc start and end angles must be different " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 16:09:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_to_x_90 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" exampleSketch = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   90 ,   endAbsoluteX   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								example   =   extrude ( exampleSketch ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([70, 111, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_to_x_270 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" exampleSketch = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   270 ,   endAbsoluteX   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								example   =   extrude ( exampleSketch ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([70, 112, 0])], message: "Cannot have an x constrained angle of 270 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_to_y_0 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" exampleSketch = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   0 ,   endAbsoluteY   =   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 20 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   70 ,   endAbsoluteY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								example   =   extrude ( exampleSketch ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([70, 110, 0])], message: "Cannot have a y constrained angle of 0 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_to_y_180 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" exampleSketch = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   180 ,   endAbsoluteY   =   20 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 20 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   70 ,   endAbsoluteY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								example   =   extrude ( exampleSketch ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([70, 112, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_of_x_length_90 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" sketch001 = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   90 ,   lengthX   =   90 ,   tag   =   $edge1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   - 15 ,   lengthX   =   - 15 ,   tag   =   $edge2 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( tag   =   $edge3 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								extrusion   =   extrude ( sketch001 ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([66, 116, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_of_x_length_270 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" sketch001 = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   90 ,   lengthX   =   90 ,   tag   =   $edge1 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   - 15 ,   lengthX   =   - 15 ,   tag   =   $edge2 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 5 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( tag   =   $edge3 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								extrusion   =   extrude ( sketch001 ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([66, 116, 0])], message: "Cannot have an x constrained angle of 90 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_of_y_length_0 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" exampleSketch = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   0 ,   lengthY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   135 ,   lengthY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 30 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								example   =   extrude ( exampleSketch ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([95, 130, 0])], message: "Cannot have a y constrained angle of 0 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_of_y_length_180 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" exampleSketch = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   180 ,   lengthY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   135 ,   lengthY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 30 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								example   =   extrude ( exampleSketch ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([95, 132, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_angled_line_of_y_length_negative_180 ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" exampleSketch = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 10 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   - 180 ,   lengthY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   10 ] ) 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   angledLine ( angle   =   135 ,   lengthY   =   10 ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( end   =   [ - 10 ,   0 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   line ( end   =   [ 0 ,   - 30 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								example   =   extrude ( exampleSketch ,   length   =   10 ) 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
											
												KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
  => `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
											 
										 
										
											2025-04-09 14:55:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "type: KclErrorDetails { source_ranges: [SourceRange([95, 133, 0])], message: "Cannot have a y constrained angle of 180 degrees" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 20:36:18 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 23:49:28 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_error_inside_fn_also_has_source_range_of_call_site ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn someFunction(something) {
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 23:49:28 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   startSketchOn ( something ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								someFunction ( ' INVALID ' ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 23:49:28 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "semantic: KclErrorDetails { source_ranges: [SourceRange([45, 54, 0]), SourceRange([59, 82, 0])], message: "This function expected the input argument to be Solid or Plane but it's actually of type string (text)" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 23:49:28 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
									
										
										
										
											2024-07-30 16:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async   fn  kcl_test_error_inside_fn_also_has_source_range_of_call_site_recursive ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" fn someFunction(something) {
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     fn  someNestedFunction ( something2 )   { 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 23:49:28 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         startSketchOn ( something2 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     someNestedFunction ( something ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								someFunction ( ' INVALID ' ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 23:49:28 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert_eq! ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         result . err ( ) . unwrap ( ) . to_string ( ) , 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								         r # "semantic: KclErrorDetails { source_ranges: [SourceRange([91, 101, 0]), SourceRange([114, 143, 0]), SourceRange([147, 170, 0])], message: "This function expected the input argument to be Solid or Plane but it's actually of type string (text)" }"# 
  
						 
					
						
							
								
									
										
										
										
											2024-07-28 23:49:28 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2024-10-03 01:05:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async   fn  kcl_test_error_no_auth_websocket ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-04-30 13:12:40 +12:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" sketch001 = startSketchOn(XZ)
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   startProfile ( at   =   [ 61.74 ,   206.13 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-03-07 22:07:16 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   xLine ( length   =   305.11 ,   tag   =   $seg01 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   yLine ( length   =   - 291.85 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   xLine ( length   =   - segLen ( seg01 ) ) 
  
						 
					
						
							
								
									
										
											 
										
											
												KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
 line\(([^=]*), %\)
 line(end = $1)
 line\((.*), %, (.*)\)
 line(end = $1, tag = $2)
 lineTo\((.*), %\)
 line(endAbsolute = $1)
 lineTo\((.*), %, (.*)\)
 line(endAbsolute = $1, tag = $2)
 extrude\((.*), %\)
 extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
 close\(%, (.*)\)
 close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
 - Make a lineTo helper
 - Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
 - Test was looking for the old style of `line` call to choose an offset
   for pathToNode
 - Test assumed that the `tag` param was always the third one, but in
   a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
											 
										 
										
											2025-02-04 08:31:43 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   line ( endAbsolute   =   [ profileStartX ( % ) ,   profileStartY ( % ) ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   close ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   extrude ( length   =   40.14 ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-06 20:03:12 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   shell ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     faces   =   [ seg01 ] , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     thickness   =   3.14 , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   ) 
  
						 
					
						
							
								
									
										
										
										
											2024-10-03 01:05:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot_no_auth ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2024-10-03 01:05:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert! ( result . is_err ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert! ( result 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . err ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . unwrap ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . to_string ( ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         . contains ( " Please send the following object over this websocket " ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async   fn  kcl_test_ensure_nothing_left_in_batch_single_file ( )   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   code   =   r #" @settings(defaultLengthUnit = in)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Set units in inches (in)
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Define constants
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								innerDiameter   =   0.364 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								outerDiameter   =   35   /   64 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								length   =   1   +   1   /   2 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// create a sketch on the XY plane
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								sketch000   =   startSketchOn ( XY ) 
  
						 
					
						
							
								
									
										
										
										
											2025-04-25 16:01:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   startProfile ( at   =   [ 0 ,   0 ] ) 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     | >   line ( end   =   [ 0 ,   innerDiameter   /   2 ] ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   ctx   =   kcl_lib ::ExecutorContext ::new_with_default_client ( ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-15 10:08:39 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   mut   exec_state   =   kcl_lib ::ExecState ::new ( & ctx ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   program   =   kcl_lib ::Program ::parse_no_errs ( code ) . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-07 18:45:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ctx . run ( & program ,   & mut   exec_state ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     // Ensure nothing is left in the batch
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert! ( ctx . engine . batch ( ) . read ( ) . await . is_empty ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert! ( ctx . engine . batch_end ( ) . read ( ) . await . is_empty ( ) ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-05 22:09:00 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     ctx . close ( ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async   fn  kcl_test_ensure_nothing_left_in_batch_multi_file ( )   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     // Get the current working directory.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   current_dir   =   std ::env ::current_dir ( ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     // Get the code in the test directory we need.
  
						 
					
						
							
								
									
										
										
										
											2025-03-01 13:59:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   path   =   current_dir . join ( " tests/assembly_non_default_units/input.kcl " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   std ::fs ::read_to_string ( & path ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     // Change the current working directory to the test directory.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     std ::env ::set_current_dir ( path . parent ( ) . unwrap ( ) ) . unwrap ( ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   ctx   =   kcl_lib ::ExecutorContext ::new_with_default_client ( ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-15 10:08:39 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   mut   exec_state   =   kcl_lib ::ExecState ::new ( & ctx ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   program   =   kcl_lib ::Program ::parse_no_errs ( & code ) . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-07 18:45:33 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     ctx . run ( & program ,   & mut   exec_state ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     // Ensure nothing is left in the batch
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert! ( ctx . engine . batch ( ) . read ( ) . await . is_empty ( ) ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     assert! ( ctx . engine . batch_end ( ) . read ( ) . await . is_empty ( ) ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-05 22:09:00 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     ctx . close ( ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-02-28 11:52:14 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
									
										
										
										
											2025-03-03 10:26:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-10 22:53:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async   fn  kcl_test_better_type_names ( )   { 
  
						 
					
						
							
								
									
										
										
										
											2025-03-21 22:39:12 +13:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   code   =   r #" startSketchOn(XY)
  
						 
					
						
							
								
									
										
										
										
											2025-03-10 22:53:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   | >   circle ( center   =   [ - 95.51 ,   - 74.7 ] ,   radius   =   262.23 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   | >   appearance ( metalness   =   0.9 ) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								" #;
  
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   result   =   execute_and_snapshot ( code ,   None ) . await ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-10 22:53:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   err   =   match   result . err ( )   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         Some ( x )   = >   match   x   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             ExecError ::Kcl ( kcl_error_with_outputs )   = >   kcl_error_with_outputs . error . message ( ) . to_owned ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             ExecError ::Connection ( _ )   = >   todo! ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             ExecError ::BadPng ( _ )   = >   todo! ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             ExecError ::BadExport ( _ )   = >   todo! ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         } , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         None   = >   todo! ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } ; 
  
						 
					
						
							
								
									
										
										
										
											2025-04-17 17:22:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     assert_eq! ( err ,   " This function expected the input argument to be one or more Solids or imported geometry but it's actually of type Sketch. You can convert a sketch (2D) into a Solid (3D) by calling a function like `extrude` or `revolve` " ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-10 22:53:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-03 10:26:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#[ tokio::test(flavor =  " multi_thread " ) ] 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async   fn  kcl_test_exporting_step_file ( )   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     // This tests export like how we do it in cli and kcl.py.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     let   code   =   kcl_input! ( " helix_defaults_negative_extrude " ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-31 10:56:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     let   ( _ ,   _ ,   files )   =   execute_and_export_step ( code ,   None ) . await . unwrap ( ) ; 
  
						 
					
						
							
								
									
										
										
										
											2025-03-03 10:26:01 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     for   file   in   files   { 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         expectorate ::assert_contents ( 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             format! ( " e2e/executor/outputs/helix_defaults_negative_extrude_ {} " ,   file . name ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             std ::str ::from_utf8 ( & file . contents ) . unwrap ( ) , 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								         ) ; 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     } 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}