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

Commit d0b6d6a

Browse files
committed
Refactor walkthrough processing to eliminate duplication
- Change process_walkthrough_elements to take Option<&Vec> parameter - Remove duplicated if-let-Some logic from all four sections - Cleaner, more maintainable code with single pattern - Same functionality with less repetition
1 parent 9a8ee2f commit d0b6d6a

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

server/src/server.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,10 @@ impl DialecticServer {
278278

279279
// Execute Dialect programs to resolve locations and render walkthrough
280280
let resolved = crate::ide::ResolvedWalkthrough {
281-
introduction: if let Some(elements) = &params.introduction {
282-
Some(self.process_walkthrough_elements(elements).await?)
283-
} else { None },
284-
highlights: if let Some(elements) = &params.highlights {
285-
Some(self.process_walkthrough_elements(elements).await?)
286-
} else { None },
287-
changes: if let Some(elements) = &params.changes {
288-
Some(self.process_walkthrough_elements(elements).await?)
289-
} else { None },
290-
actions: if let Some(elements) = &params.actions {
291-
Some(self.process_walkthrough_elements(elements).await?)
292-
} else { None },
281+
introduction: self.process_walkthrough_elements(params.introduction.as_ref()).await?,
282+
highlights: self.process_walkthrough_elements(params.highlights.as_ref()).await?,
283+
changes: self.process_walkthrough_elements(params.changes.as_ref()).await?,
284+
actions: self.process_walkthrough_elements(params.actions.as_ref()).await?,
293285
};
294286

295287
// Log the processing result
@@ -310,13 +302,18 @@ impl DialecticServer {
310302
/// Process a list of walkthrough elements
311303
async fn process_walkthrough_elements(
312304
&self,
313-
elements: &[serde_json::Value],
314-
) -> Result<Vec<crate::ide::ResolvedWalkthroughElement>, McpError> {
315-
let mut resolved_elements = Vec::new();
316-
for element in elements {
317-
resolved_elements.push(self.process_walkthrough_element(element.clone()).await?);
305+
elements: Option<&Vec<serde_json::Value>>,
306+
) -> Result<Option<Vec<crate::ide::ResolvedWalkthroughElement>>, McpError> {
307+
match elements {
308+
Some(elements) => {
309+
let mut resolved_elements = Vec::new();
310+
for element in elements {
311+
resolved_elements.push(self.process_walkthrough_element(element.clone()).await?);
312+
}
313+
Ok(Some(resolved_elements))
314+
}
315+
None => Ok(None),
318316
}
319-
Ok(resolved_elements)
320317
}
321318

322319
/// Process a single walkthrough element, executing Dialect programs if needed

0 commit comments

Comments
 (0)