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

Commit 9e83a5f

Browse files
committed
Implement walkthrough processing with Dialect program execution
- Add process_walkthrough_element method using same pattern as ide_operation - Clone interpreter and use spawn_blocking for non-Send future handling - Process introduction section elements and execute Dialect programs - Support Comment, GitDiff, Action, and Markdown element types - Proper error handling with McpError::internal_error - Foundation complete for full walkthrough system
1 parent eab4e0d commit 9e83a5f

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

server/src/server.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,70 @@ impl DialecticServer {
277277
.await;
278278

279279
// Execute Dialect programs to resolve locations and render walkthrough
280-
// TODO: Implement walkthrough processing
280+
let mut resolved_elements = Vec::new();
281+
282+
// Process introduction section
283+
if let Some(intro_elements) = &params.introduction {
284+
for element in intro_elements {
285+
resolved_elements.push(self.process_walkthrough_element(element.clone()).await?);
286+
}
287+
}
288+
289+
// For now, just log the processing and return success
281290
self.ipc
282291
.send_log(
283292
LogLevel::Info,
284-
"Walkthrough processing - implementation in progress".to_string(),
293+
format!("Processed {} walkthrough elements", resolved_elements.len()),
285294
)
286295
.await;
287296

288297
Ok(CallToolResult::success(vec![Content::text(
289-
"Walkthrough tool called - processing implementation in progress",
298+
"Walkthrough successfully processed",
290299
)]))
291300
}
292301

302+
/// Process a single walkthrough element, executing Dialect programs if needed
303+
async fn process_walkthrough_element(
304+
&self,
305+
element: serde_json::Value,
306+
) -> Result<crate::ide::ResolvedWalkthroughElement, McpError> {
307+
use crate::ide::ResolvedWalkthroughElement;
308+
309+
match element {
310+
serde_json::Value::String(text) => {
311+
Ok(ResolvedWalkthroughElement::Markdown(text))
312+
}
313+
serde_json::Value::Object(_) => {
314+
// Clone interpreter and execute Dialect program (same pattern as ide_operation)
315+
let mut interpreter = self.interpreter.clone();
316+
317+
let result = tokio::task::spawn_blocking(move || {
318+
tokio::runtime::Handle::current()
319+
.block_on(async move { interpreter.evaluate(element).await })
320+
})
321+
.await
322+
.map_err(|e| McpError::internal_error("Task execution failed", Some(serde_json::json!({"error": e.to_string()}))))?
323+
.map_err(|e| McpError::internal_error("Dialect execution failed", Some(serde_json::json!({"error": e.to_string()}))))?;
324+
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+
}
336+
}
337+
_ => {
338+
// Convert other types to markdown
339+
Ok(ResolvedWalkthroughElement::Markdown(element.to_string()))
340+
}
341+
}
342+
}
343+
293344
/// Get the currently selected text from any active editor in VSCode
294345
///
295346
/// Works with source files, review panels, and any other text editor.

0 commit comments

Comments
 (0)