@@ -115,7 +115,7 @@ where
115
115
seq. end ( )
116
116
}
117
117
118
- #[ derive( Debug , Clone , Serialize , PartialEq , Eq , ts_rs:: TS ) ]
118
+ #[ derive( Debug , Clone , Default , Serialize , PartialEq , Eq , ts_rs:: TS ) ]
119
119
#[ ts( export_to = "Artifact.ts" ) ]
120
120
#[ serde( rename_all = "camelCase" ) ]
121
121
pub struct CodeRef {
@@ -744,19 +744,28 @@ impl ArtifactGraph {
744
744
}
745
745
746
746
/// Build the artifact graph from the artifact commands and the responses. The
747
- /// initial graph is the graph cached from a previous execution.
747
+ /// initial graph is the graph cached from a previous execution. NodePaths of
748
+ /// `exec_artifacts` are filled in from the AST.
748
749
pub ( super ) fn build_artifact_graph (
749
750
artifact_commands : & [ ArtifactCommand ] ,
750
751
responses : & IndexMap < Uuid , WebSocketResponse > ,
751
752
ast : & Node < Program > ,
752
- exec_artifacts : & IndexMap < ArtifactId , Artifact > ,
753
+ exec_artifacts : & mut IndexMap < ArtifactId , Artifact > ,
753
754
initial_graph : ArtifactGraph ,
754
755
) -> Result < ArtifactGraph , KclError > {
755
756
let mut map = initial_graph. into_map ( ) ;
756
757
757
758
let mut path_to_plane_id_map = FnvHashMap :: default ( ) ;
758
759
let mut current_plane_id = None ;
759
760
761
+ // Fill in NodePaths for artifacts that were added directly to the map
762
+ // during execution.
763
+ for exec_artifact in exec_artifacts. values_mut ( ) {
764
+ // Note: We only have access to the new AST. So if these artifacts
765
+ // somehow came from cached AST, this won't fill in anything.
766
+ fill_in_node_paths ( exec_artifact, ast) ;
767
+ }
768
+
760
769
for artifact_command in artifact_commands {
761
770
if let ModelingCmd :: EnableSketchMode ( EnableSketchMode { entity_id, .. } ) = artifact_command. command {
762
771
current_plane_id = Some ( entity_id) ;
@@ -790,12 +799,7 @@ pub(super) fn build_artifact_graph(
790
799
}
791
800
792
801
for exec_artifact in exec_artifacts. values ( ) {
793
- let mut new_artifact = exec_artifact. clone ( ) ;
794
- // Fill in NodePaths for artifacts that were added directly to the map
795
- // during execution.
796
- fill_in_node_paths ( & mut new_artifact, ast) ;
797
-
798
- merge_artifact_into_map ( & mut map, new_artifact) ;
802
+ merge_artifact_into_map ( & mut map, exec_artifact. clone ( ) ) ;
799
803
}
800
804
801
805
Ok ( ArtifactGraph { map } )
@@ -806,10 +810,14 @@ pub(super) fn build_artifact_graph(
806
810
fn fill_in_node_paths ( artifact : & mut Artifact , program : & Node < Program > ) {
807
811
match artifact {
808
812
Artifact :: StartSketchOnFace ( face) => {
809
- face. code_ref . node_path = NodePath :: from_range ( program, face. code_ref . range ) . unwrap_or_default ( ) ;
813
+ if face. code_ref . node_path . is_empty ( ) {
814
+ face. code_ref . node_path = NodePath :: from_range ( program, face. code_ref . range ) . unwrap_or_default ( ) ;
815
+ }
810
816
}
811
817
Artifact :: StartSketchOnPlane ( plane) => {
812
- plane. code_ref . node_path = NodePath :: from_range ( program, plane. code_ref . range ) . unwrap_or_default ( ) ;
818
+ if plane. code_ref . node_path . is_empty ( ) {
819
+ plane. code_ref . node_path = NodePath :: from_range ( program, plane. code_ref . range ) . unwrap_or_default ( ) ;
820
+ }
813
821
}
814
822
_ => { }
815
823
}
@@ -1152,16 +1160,19 @@ fn artifacts_to_update(
1152
1160
let extra_artifact = exec_artifacts. values ( ) . find ( |a| {
1153
1161
if let Artifact :: StartSketchOnFace ( s) = a {
1154
1162
s. face_id == face_id
1163
+ } else if let Artifact :: StartSketchOnPlane ( s) = a {
1164
+ s. plane_id == face_id
1155
1165
} else {
1156
1166
false
1157
1167
}
1158
1168
} ) ;
1159
- let sketch_on_face_source_range = extra_artifact
1169
+ let sketch_on_face_code_ref = extra_artifact
1160
1170
. and_then ( |a| match a {
1161
- Artifact :: StartSketchOnFace ( s) => Some ( s. code_ref . range ) ,
1162
- // TODO: If we didn't find it, it's probably a bug.
1171
+ Artifact :: StartSketchOnFace ( s) => Some ( s. code_ref . clone ( ) ) ,
1172
+ Artifact :: StartSketchOnPlane ( s ) => Some ( s . code_ref . clone ( ) ) ,
1163
1173
_ => None ,
1164
1174
} )
1175
+ // TODO: If we didn't find it, it's probably a bug.
1165
1176
. unwrap_or_default ( ) ;
1166
1177
1167
1178
return_arr. push ( Artifact :: Wall ( Wall {
@@ -1170,11 +1181,7 @@ fn artifacts_to_update(
1170
1181
edge_cut_edge_ids : Vec :: new ( ) ,
1171
1182
sweep_id : path_sweep_id,
1172
1183
path_ids : Vec :: new ( ) ,
1173
- face_code_ref : CodeRef {
1174
- range : sketch_on_face_source_range,
1175
- node_path : NodePath :: from_range ( ast, sketch_on_face_source_range) . unwrap_or_default ( ) ,
1176
- path_to_node : Vec :: new ( ) ,
1177
- } ,
1184
+ face_code_ref : sketch_on_face_code_ref,
1178
1185
cmd_id : artifact_command. cmd_id ,
1179
1186
} ) ) ;
1180
1187
let mut new_seg = seg. clone ( ) ;
@@ -1207,27 +1214,27 @@ fn artifacts_to_update(
1207
1214
let extra_artifact = exec_artifacts. values ( ) . find ( |a| {
1208
1215
if let Artifact :: StartSketchOnFace ( s) = a {
1209
1216
s. face_id == face_id
1217
+ } else if let Artifact :: StartSketchOnPlane ( s) = a {
1218
+ s. plane_id == face_id
1210
1219
} else {
1211
1220
false
1212
1221
}
1213
1222
} ) ;
1214
- let sketch_on_face_source_range = extra_artifact
1223
+ let sketch_on_face_code_ref = extra_artifact
1215
1224
. and_then ( |a| match a {
1216
- Artifact :: StartSketchOnFace ( s) => Some ( s. code_ref . range ) ,
1225
+ Artifact :: StartSketchOnFace ( s) => Some ( s. code_ref . clone ( ) ) ,
1226
+ Artifact :: StartSketchOnPlane ( s) => Some ( s. code_ref . clone ( ) ) ,
1217
1227
_ => None ,
1218
1228
} )
1229
+ // TODO: If we didn't find it, it's probably a bug.
1219
1230
. unwrap_or_default ( ) ;
1220
1231
return_arr. push ( Artifact :: Cap ( Cap {
1221
1232
id : face_id,
1222
1233
sub_type,
1223
1234
edge_cut_edge_ids : Vec :: new ( ) ,
1224
1235
sweep_id : path_sweep_id,
1225
1236
path_ids : Vec :: new ( ) ,
1226
- face_code_ref : CodeRef {
1227
- range : sketch_on_face_source_range,
1228
- node_path : NodePath :: from_range ( ast, sketch_on_face_source_range) . unwrap_or_default ( ) ,
1229
- path_to_node : Vec :: new ( ) ,
1230
- } ,
1237
+ face_code_ref : sketch_on_face_code_ref,
1231
1238
cmd_id : artifact_command. cmd_id ,
1232
1239
} ) ) ;
1233
1240
let Some ( Artifact :: Sweep ( sweep) ) = artifacts. get ( & path_sweep_id) else {
0 commit comments