MCPcopy Create free account
hub / github.com/concensure/Semantic / build_safe_edit_patch

Function build_safe_edit_patch

retrieval/src/lib.rs:3779–3819  ·  view source on GitHub ↗
(
    plan: &engine::EditPlan,
    target_symbol: &SymbolRecord,
    edit_description: &str,
    existing_code: &str,
    llm_response_text: Option<&str>,
    fallback_transform: engine::ASTTransforma

Source from the content-addressed store, hash-verified

3777}
3778
3779fn build_safe_edit_patch(
3780 plan: &engine::EditPlan,
3781 target_symbol: &SymbolRecord,
3782 edit_description: &str,
3783 existing_code: &str,
3784 llm_response_text: Option<&str>,
3785 fallback_transform: engine::ASTTransformation,
3786) -> Result<engine::CodePatch> {
3787 if let Some(replacement_code) = llm_response_text.and_then(extract_replacement_code) {
3788 return patch_engine::PatchEngine::generate_replacement_patch(
3789 &target_symbol.file,
3790 existing_code,
3791 patch_engine::LineRange {
3792 start_line: target_symbol.start_line as usize,
3793 end_line: target_symbol.end_line as usize,
3794 },
3795 &replacement_code,
3796 );
3797 }
3798
3799 if plan.edit_type == engine::EditType::RenameSymbol {
3800 if let Some(new_name) = extract_rename_target(edit_description, &plan.target_symbol) {
3801 let renamed = replace_identifier_tokens(existing_code, &plan.target_symbol, &new_name);
3802 return patch_engine::PatchEngine::generate_replacement_patch(
3803 &target_symbol.file,
3804 existing_code,
3805 patch_engine::LineRange {
3806 start_line: 1,
3807 end_line: existing_code.lines().count().max(1),
3808 },
3809 &renamed,
3810 );
3811 }
3812 }
3813
3814 Ok(patch_engine::PatchEngine::generate_ast_patch(
3815 &target_symbol.file,
3816 &plan.target_symbol,
3817 fallback_transform,
3818 ))
3819}
3820
3821fn extract_replacement_code(response_text: &str) -> Option<String> {
3822 let trimmed = response_text.trim();

Callers 1

plan_safe_editMethod · 0.85

Calls 2

extract_rename_targetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…