Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit 6b40418

Browse files
committed
Simplify walkthrough element deserialization using serde(untagged)
- Remove messy if-else chain for type checking - Use ResolvedWalkthroughElement's serde(untagged) for automatic deserialization - Cleaner, more maintainable code that leverages existing type system - Single point of failure with clear error message
1 parent 9e83a5f commit 6b40418

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

server/src/server.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,9 @@ impl DialecticServer {
322322
.map_err(|e| McpError::internal_error("Task execution failed", Some(serde_json::json!({"error": e.to_string()}))))?
323323
.map_err(|e| McpError::internal_error("Dialect execution failed", Some(serde_json::json!({"error": e.to_string()}))))?;
324324

325-
// Try to deserialize as different element types
326-
if let Ok(comment) = serde_json::from_value::<crate::ide::ResolvedComment>(result.clone()) {
327-
Ok(ResolvedWalkthroughElement::Comment(comment))
328-
} else if let Ok(file_changes) = serde_json::from_value::<Vec<crate::synthetic_pr::FileChange>>(result.clone()) {
329-
Ok(ResolvedWalkthroughElement::GitDiff(file_changes))
330-
} else if let Ok(action) = serde_json::from_value::<crate::ide::ResolvedAction>(result.clone()) {
331-
Ok(ResolvedWalkthroughElement::Action(action))
332-
} else {
333-
// Fallback to markdown
334-
Ok(ResolvedWalkthroughElement::Markdown(result.to_string()))
335-
}
325+
// Deserialize directly using serde(untagged)
326+
serde_json::from_value(result)
327+
.map_err(|e| McpError::internal_error("Failed to deserialize result", Some(serde_json::json!({"error": e.to_string()}))))
336328
}
337329
_ => {
338330
// Convert other types to markdown

0 commit comments

Comments
 (0)