Fix to not send engine commands when only importing functions or constants (#5371)
* Change to not send engine commands when in isolated mode * Update output since not sending engine commands
This commit is contained in:
@ -17,7 +17,9 @@ use kcmc::{
|
||||
},
|
||||
ModelingCmd,
|
||||
};
|
||||
use kittycad_modeling_cmds::{self as kcmc, id::ModelingCmdId, websocket::ModelingBatch};
|
||||
use kittycad_modeling_cmds::{
|
||||
self as kcmc, id::ModelingCmdId, ok_response::OkModelingCmdResponse, websocket::ModelingBatch,
|
||||
};
|
||||
use tokio::sync::{mpsc, oneshot, RwLock};
|
||||
use tokio_tungstenite::tungstenite::Message as WsMsg;
|
||||
use uuid::Uuid;
|
||||
@ -459,6 +461,35 @@ impl EngineManager for EngineConnection {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// In isolated mode, we don't send the command to the engine.
|
||||
if self.execution_kind().is_isolated() {
|
||||
return match &cmd {
|
||||
WebSocketRequest::ModelingCmdBatchReq(ModelingBatch { requests, .. }) => {
|
||||
let mut responses = HashMap::with_capacity(requests.len());
|
||||
for request in requests {
|
||||
responses.insert(
|
||||
request.cmd_id,
|
||||
BatchResponse::Success {
|
||||
response: OkModelingCmdResponse::Empty {},
|
||||
},
|
||||
);
|
||||
}
|
||||
Ok(WebSocketResponse::Success(SuccessWebSocketResponse {
|
||||
request_id: Some(id),
|
||||
resp: OkWebSocketResponseData::ModelingBatch { responses },
|
||||
success: true,
|
||||
}))
|
||||
}
|
||||
_ => Ok(WebSocketResponse::Success(SuccessWebSocketResponse {
|
||||
request_id: Some(id),
|
||||
resp: OkWebSocketResponseData::Modeling {
|
||||
modeling_response: OkModelingCmdResponse::Empty {},
|
||||
},
|
||||
success: true,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
// Send the request to the engine, via the actor.
|
||||
|
@ -128,7 +128,7 @@ impl crate::engine::EngineManager for EngineConnection {
|
||||
responses: _,
|
||||
}) => {
|
||||
// Create the empty responses.
|
||||
let mut responses = HashMap::new();
|
||||
let mut responses = HashMap::with_capacity(requests.len());
|
||||
for request in requests {
|
||||
self.handle_command(&request.cmd, request.cmd_id, &id_to_source_range)?;
|
||||
responses.insert(
|
||||
|
@ -9,7 +9,11 @@ use anyhow::Result;
|
||||
use indexmap::IndexMap;
|
||||
use kcmc::{
|
||||
id::ModelingCmdId,
|
||||
websocket::{ModelingBatch, WebSocketRequest, WebSocketResponse},
|
||||
ok_response::OkModelingCmdResponse,
|
||||
websocket::{
|
||||
BatchResponse, ModelingBatch, OkWebSocketResponseData, SuccessWebSocketResponse, WebSocketRequest,
|
||||
WebSocketResponse,
|
||||
},
|
||||
ModelingCmd,
|
||||
};
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
@ -222,6 +226,35 @@ impl crate::engine::EngineManager for EngineConnection {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// In isolated mode, we don't send the command to the engine.
|
||||
if self.execution_kind().is_isolated() {
|
||||
return match &cmd {
|
||||
WebSocketRequest::ModelingCmdBatchReq(ModelingBatch { requests, .. }) => {
|
||||
let mut responses = HashMap::with_capacity(requests.len());
|
||||
for request in requests {
|
||||
responses.insert(
|
||||
request.cmd_id,
|
||||
BatchResponse::Success {
|
||||
response: OkModelingCmdResponse::Empty {},
|
||||
},
|
||||
);
|
||||
}
|
||||
Ok(WebSocketResponse::Success(SuccessWebSocketResponse {
|
||||
request_id: Some(id),
|
||||
resp: OkWebSocketResponseData::ModelingBatch { responses },
|
||||
success: true,
|
||||
}))
|
||||
}
|
||||
_ => Ok(WebSocketResponse::Success(SuccessWebSocketResponse {
|
||||
request_id: Some(id),
|
||||
resp: OkWebSocketResponseData::Modeling {
|
||||
modeling_response: OkModelingCmdResponse::Empty {},
|
||||
},
|
||||
success: true,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
let source_range_str = serde_json::to_string(&source_range).map_err(|e| {
|
||||
KclError::Engine(KclErrorDetails {
|
||||
message: format!("Failed to serialize source range: {:?}", e),
|
||||
|
@ -289,7 +289,7 @@ pub struct PreImportedGeometry {
|
||||
}
|
||||
|
||||
pub async fn send_to_engine(pre: PreImportedGeometry, ctxt: &ExecutorContext) -> Result<ImportedGeometry, KclError> {
|
||||
if ctxt.is_mock() {
|
||||
if ctxt.no_engine_commands() {
|
||||
return Ok(ImportedGeometry {
|
||||
id: pre.id,
|
||||
value: pre.command.files.iter().map(|f| f.path.to_string()).collect(),
|
||||
|
@ -483,6 +483,11 @@ impl ExecutorContext {
|
||||
self.context_type == ContextType::Mock || self.context_type == ContextType::MockCustomForwarded
|
||||
}
|
||||
|
||||
/// Returns true if we should not send engine commands for any reason.
|
||||
pub fn no_engine_commands(&self) -> bool {
|
||||
self.is_mock() || self.engine.execution_kind().is_isolated()
|
||||
}
|
||||
|
||||
pub async fn send_clear_scene(
|
||||
&self,
|
||||
exec_state: &mut ExecState,
|
||||
|
@ -266,7 +266,7 @@ pub(crate) async fn do_post_extrude(
|
||||
Some(extrude_surface)
|
||||
}
|
||||
}
|
||||
} else if args.ctx.is_mock() {
|
||||
} else if args.ctx.no_engine_commands() {
|
||||
// Only pre-populate the extrude surface if we are in mock mode.
|
||||
|
||||
let extrude_surface = ExtrudeSurface::ExtrudePlane(crate::execution::ExtrudePlane {
|
||||
@ -317,7 +317,7 @@ fn analyze_faces(exec_state: &mut ExecState, args: &Args, face_infos: Vec<Extrus
|
||||
sides: HashMap::with_capacity(face_infos.len()),
|
||||
..Default::default()
|
||||
};
|
||||
if args.ctx.is_mock() {
|
||||
if args.ctx.no_engine_commands() {
|
||||
// Create fake IDs for start and end caps, to make extrudes mock-execute safe
|
||||
faces.start_cap_id = Some(exec_state.next_uuid());
|
||||
faces.end_cap_id = Some(exec_state.next_uuid());
|
||||
|
@ -222,7 +222,7 @@ pub async fn get_opposite_edge(exec_state: &mut ExecState, args: Args) -> Result
|
||||
name = "getOppositeEdge",
|
||||
}]
|
||||
async fn inner_get_opposite_edge(tag: TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<Uuid, KclError> {
|
||||
if args.ctx.is_mock() {
|
||||
if args.ctx.no_engine_commands() {
|
||||
return Ok(exec_state.next_uuid());
|
||||
}
|
||||
let face_id = args.get_adjacent_face_to_tag(exec_state, &tag, false).await?;
|
||||
@ -299,7 +299,7 @@ async fn inner_get_next_adjacent_edge(
|
||||
exec_state: &mut ExecState,
|
||||
args: Args,
|
||||
) -> Result<Uuid, KclError> {
|
||||
if args.ctx.is_mock() {
|
||||
if args.ctx.no_engine_commands() {
|
||||
return Ok(exec_state.next_uuid());
|
||||
}
|
||||
let face_id = args.get_adjacent_face_to_tag(exec_state, &tag, false).await?;
|
||||
@ -384,7 +384,7 @@ async fn inner_get_previous_adjacent_edge(
|
||||
exec_state: &mut ExecState,
|
||||
args: Args,
|
||||
) -> Result<Uuid, KclError> {
|
||||
if args.ctx.is_mock() {
|
||||
if args.ctx.no_engine_commands() {
|
||||
return Ok(exec_state.next_uuid());
|
||||
}
|
||||
let face_id = args.get_adjacent_face_to_tag(exec_state, &tag, false).await?;
|
||||
|
@ -125,7 +125,7 @@ async fn inner_helix(
|
||||
meta: vec![args.source_range.into()],
|
||||
});
|
||||
|
||||
if args.ctx.is_mock() {
|
||||
if args.ctx.no_engine_commands() {
|
||||
return Ok(helix_result);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ async fn inner_mirror_2d(
|
||||
SketchSet::Sketches(sketches) => sketches,
|
||||
};
|
||||
|
||||
if args.ctx.is_mock() {
|
||||
if args.ctx.no_engine_commands() {
|
||||
return Ok(starting_sketches);
|
||||
}
|
||||
|
||||
|
@ -592,229 +592,5 @@ description: Artifact commands import_function_not_sketch.kcl
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_opposite_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cmdId": "[uuid]",
|
||||
"range": [
|
||||
304,
|
||||
330,
|
||||
1
|
||||
],
|
||||
"command": {
|
||||
"type": "solid3d_get_next_adjacent_edge",
|
||||
"object_id": "[uuid]",
|
||||
"edge_id": "[uuid]",
|
||||
"face_id": "[uuid]"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -1,82 +1,3 @@
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph path2 [Path]
|
||||
2["Path<br>[77, 103, 1]"]
|
||||
3["Segment<br>[109, 127, 1]"]
|
||||
4["Segment<br>[133, 152, 1]"]
|
||||
5["Segment<br>[158, 177, 1]"]
|
||||
6["Segment<br>[183, 202, 1]"]
|
||||
7["Segment<br>[208, 233, 1]"]
|
||||
8["Segment<br>[239, 260, 1]"]
|
||||
9["Segment<br>[266, 285, 1]"]
|
||||
10["Segment<br>[291, 298, 1]"]
|
||||
11[Solid2d]
|
||||
end
|
||||
1["Plane<br>[52, 71, 1]"]
|
||||
12["Sweep Revolve<br>[304, 330, 1]"]
|
||||
13[Wall]
|
||||
14[Wall]
|
||||
15[Wall]
|
||||
16[Wall]
|
||||
17[Wall]
|
||||
18[Wall]
|
||||
19[Wall]
|
||||
20[Wall]
|
||||
21["SweepEdge Adjacent"]
|
||||
22["SweepEdge Adjacent"]
|
||||
23["SweepEdge Adjacent"]
|
||||
24["SweepEdge Adjacent"]
|
||||
25["SweepEdge Adjacent"]
|
||||
26["SweepEdge Adjacent"]
|
||||
27["SweepEdge Adjacent"]
|
||||
1 --- 2
|
||||
2 --- 3
|
||||
2 --- 4
|
||||
2 --- 5
|
||||
2 --- 6
|
||||
2 --- 7
|
||||
2 --- 8
|
||||
2 --- 9
|
||||
2 --- 10
|
||||
2 ---- 12
|
||||
2 --- 11
|
||||
3 --- 13
|
||||
3 x--> 21
|
||||
4 --- 14
|
||||
4 --- 21
|
||||
5 --- 15
|
||||
5 --- 22
|
||||
6 --- 16
|
||||
6 --- 23
|
||||
7 --- 17
|
||||
7 --- 24
|
||||
8 --- 18
|
||||
8 --- 25
|
||||
9 --- 19
|
||||
9 --- 26
|
||||
10 --- 20
|
||||
10 --- 27
|
||||
12 --- 13
|
||||
12 --- 14
|
||||
12 --- 15
|
||||
12 --- 16
|
||||
12 --- 17
|
||||
12 --- 18
|
||||
12 --- 19
|
||||
12 --- 20
|
||||
12 <--x 3
|
||||
12 --- 21
|
||||
12 <--x 4
|
||||
12 <--x 5
|
||||
12 --- 22
|
||||
12 <--x 6
|
||||
12 --- 23
|
||||
12 <--x 7
|
||||
12 --- 24
|
||||
12 <--x 8
|
||||
12 --- 25
|
||||
12 <--x 9
|
||||
12 --- 26
|
||||
12 <--x 10
|
||||
12 --- 27
|
||||
```
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 19 KiB |
@ -1,12 +1,3 @@
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph path2 [Path]
|
||||
2["Path<br>[106, 149, 1]"]
|
||||
3["Segment<br>[106, 149, 1]"]
|
||||
4[Solid2d]
|
||||
end
|
||||
1["Plane<br>[81, 100, 1]"]
|
||||
1 --- 2
|
||||
2 --- 3
|
||||
2 --- 4
|
||||
```
|
||||
|
Reference in New Issue
Block a user