The list_changed_functions tool was showing functions in a suboptimal order. All additions and deletions have a magnitude of 1.0, so they were appearing first, making it hard to find the most interesting changes (modified functions with actual code differences).
Changed Functions (showing 50 of 693):
1. tx_isp_proc_w00_show - deleted (magnitude: 1.00, similarity: 0.00)
2. tx_isp_proc_w00_open - deleted (magnitude: 1.00, similarity: 0.00)
3. tx_isp_proc_w01_show - deleted (magnitude: 1.00, similarity: 0.00)
...
This made it difficult to find the most important changes - functions that were actually modified with varying degrees of change.
Improved the sorting algorithm in crates/mcp-server/src/comparison/context.rs to prioritize by change type first, then by magnitude within each type:
-
Modified functions (sorted by magnitude, highest first)
- These are the most interesting - actual code changes
- Higher magnitude = more significant changes
-
Added functions (alphabetically)
- New functionality added to the codebase
-
Deleted functions (alphabetically)
- Functionality removed from the codebase
-
Renamed/moved functions (sorted by magnitude)
- Structural changes with minimal code impact
/// Get functions sorted by change magnitude (most changed first)
///
/// Sorting priority:
/// 1. Modified functions (sorted by magnitude, highest first)
/// 2. Added functions (alphabetically)
/// 3. Deleted functions (alphabetically)
/// 4. Renamed/moved functions (sorted by magnitude)
pub fn get_sorted_changes(&self) -> Vec<FunctionChange> {
let mut changes = self.function_changes.clone();
changes.sort_by(|a, b| {
// First, prioritize by change type
let type_priority_a = Self::change_type_priority(&a.change_type);
let type_priority_b = Self::change_type_priority(&b.change_type);
match type_priority_a.cmp(&type_priority_b) {
std::cmp::Ordering::Equal => {
// Within same type, sort by magnitude (descending) then name
match b.change_magnitude.partial_cmp(&a.change_magnitude) {
Some(std::cmp::Ordering::Equal) | None => {
a.function_name.cmp(&b.function_name)
}
Some(ordering) => ordering,
}
}
ordering => ordering,
}
});
changes
}
/// Get priority for change type (lower number = higher priority)
fn change_type_priority(change_type: &str) -> u8 {
match change_type {
"modified" => 0, // Highest priority - actual code changes
"added" => 1, // New functionality
"deleted" => 2, // Removed functionality
"renamed" => 3, // Structural changes
"moved" => 4, // File reorganization
_ => 5, // Unknown types last
}
}Changed Functions (showing 5 of 5):
1. old_name - modified (magnitude: 0.26, similarity: 0.74)
Source: test.c (lines 22-22)
Target: test.c (lines 21-21)
Summary: Function 'old_name' modified (similarity: 0.74)
2. heavily_modified - modified (magnitude: 0.08, similarity: 0.92)
Source: test.c (lines 15-15)
Target: test.c (lines 10-10)
Summary: Function 'heavily_modified' modified (similarity: 0.92)
3. slightly_modified - modified (magnitude: 0.02, similarity: 0.98)
Source: test.c (lines 9-9)
Target: test.c (lines 4-4)
Summary: Function 'slightly_modified' modified (similarity: 0.98)
4. added_function - added (magnitude: 1.00, similarity: 0.00)
Target: test.c (lines 31-31)
Summary: Function added
5. deleted_function - deleted (magnitude: 1.00, similarity: 0.00)
Source: test.c (lines 4-4)
Summary: Function deleted
✅ Modified functions appear first - The most interesting changes are immediately visible
✅ Magnitude-based ranking within modified - Functions with more significant changes appear higher
✅ Logical grouping - Similar change types are grouped together
✅ Better UX for large codebases - When you have 693 changes, you see the most important ones first
The fix has been tested and verified:
./test_sorting_fix.shResults:
- ✅ Modified functions appear first (positions 1-3)
- ✅ Within modified, higher magnitude comes first (0.26 > 0.08 > 0.02)
- ✅ Added functions come next (position 4)
- ✅ Deleted functions come last (position 5)
The fix has been applied and the server restarted:
- ✅ Code updated in
crates/mcp-server/src/comparison/context.rs - ✅ Binary rebuilt at
target/release/smart-diff-mcp - ✅ MCP server restarted with new binary
The improved sorting is now active!
- No breaking changes - The API remains the same
- Better user experience - Most relevant changes appear first
- Scalable - Works well with large numbers of changes (e.g., 693 functions)
- Intuitive - Matches developer expectations about what's "most changed"
This improvement is especially valuable when:
- Reviewing large refactorings - Modified functions with actual logic changes appear first
- Understanding impact - See the most significant changes immediately
- Code review - Focus on the functions that matter most
- Debugging - Quickly identify functions with substantial changes
- The magnitude calculation for modified functions is:
1.0 - similarity_score - A similarity of 0.74 means 26% change (magnitude 0.26)
- A similarity of 0.98 means 2% change (magnitude 0.02)
- Additions and deletions always have magnitude 1.0 (complete change)