Fix to account for cached body items when computing NodePath (#7030)
This commit is contained in:
@ -750,6 +750,7 @@ pub(super) fn build_artifact_graph(
|
||||
artifact_commands: &[ArtifactCommand],
|
||||
responses: &IndexMap<Uuid, WebSocketResponse>,
|
||||
ast: &Node<Program>,
|
||||
cached_body_items: usize,
|
||||
exec_artifacts: &mut IndexMap<ArtifactId, Artifact>,
|
||||
initial_graph: ArtifactGraph,
|
||||
) -> Result<ArtifactGraph, KclError> {
|
||||
@ -763,7 +764,7 @@ pub(super) fn build_artifact_graph(
|
||||
for exec_artifact in exec_artifacts.values_mut() {
|
||||
// Note: We only have access to the new AST. So if these artifacts
|
||||
// somehow came from cached AST, this won't fill in anything.
|
||||
fill_in_node_paths(exec_artifact, ast);
|
||||
fill_in_node_paths(exec_artifact, ast, cached_body_items);
|
||||
}
|
||||
|
||||
for artifact_command in artifact_commands {
|
||||
@ -790,6 +791,7 @@ pub(super) fn build_artifact_graph(
|
||||
&flattened_responses,
|
||||
&path_to_plane_id_map,
|
||||
ast,
|
||||
cached_body_items,
|
||||
exec_artifacts,
|
||||
)?;
|
||||
for artifact in artifact_updates {
|
||||
@ -807,16 +809,18 @@ pub(super) fn build_artifact_graph(
|
||||
|
||||
/// These may have been created with placeholder `CodeRef`s because we didn't
|
||||
/// have the entire AST available. Now we fill them in.
|
||||
fn fill_in_node_paths(artifact: &mut Artifact, program: &Node<Program>) {
|
||||
fn fill_in_node_paths(artifact: &mut Artifact, program: &Node<Program>, cached_body_items: usize) {
|
||||
match artifact {
|
||||
Artifact::StartSketchOnFace(face) => {
|
||||
if face.code_ref.node_path.is_empty() {
|
||||
face.code_ref.node_path = NodePath::from_range(program, face.code_ref.range).unwrap_or_default();
|
||||
face.code_ref.node_path =
|
||||
NodePath::from_range(program, cached_body_items, face.code_ref.range).unwrap_or_default();
|
||||
}
|
||||
}
|
||||
Artifact::StartSketchOnPlane(plane) => {
|
||||
if plane.code_ref.node_path.is_empty() {
|
||||
plane.code_ref.node_path = NodePath::from_range(program, plane.code_ref.range).unwrap_or_default();
|
||||
plane.code_ref.node_path =
|
||||
NodePath::from_range(program, cached_body_items, plane.code_ref.range).unwrap_or_default();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -905,6 +909,7 @@ fn artifacts_to_update(
|
||||
responses: &FnvHashMap<Uuid, OkModelingCmdResponse>,
|
||||
path_to_plane_id_map: &FnvHashMap<Uuid, Uuid>,
|
||||
ast: &Node<Program>,
|
||||
cached_body_items: usize,
|
||||
exec_artifacts: &IndexMap<ArtifactId, Artifact>,
|
||||
) -> Result<Vec<Artifact>, KclError> {
|
||||
let uuid = artifact_command.cmd_id;
|
||||
@ -918,7 +923,7 @@ fn artifacts_to_update(
|
||||
// correct value based on NodePath.
|
||||
let path_to_node = Vec::new();
|
||||
let range = artifact_command.range;
|
||||
let node_path = NodePath::from_range(ast, range).unwrap_or_default();
|
||||
let node_path = NodePath::from_range(ast, cached_body_items, range).unwrap_or_default();
|
||||
let code_ref = CodeRef {
|
||||
range,
|
||||
node_path,
|
||||
|
Reference in New Issue
Block a user