MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / deduplicate_name

Function deduplicate_name

src/code_actions/extract_function.rs:765–794  ·  view source on GitHub ↗

Deduplicate a base name against existing names in the appropriate scope. For methods, checks against sibling method names in the class. For functions, checks against `function ` patterns in the file.

(base: &str, content: &str, ctx: &EnclosingContext)

Source from the content-addressed store, hash-verified

763/// For methods, checks against sibling method names in the class.
764/// For functions, checks against `function <name>` patterns in the file.
765fn deduplicate_name(base: &str, content: &str, ctx: &EnclosingContext) -> String {
766 let mut name = base.to_string();
767 let mut counter = 1u32;
768
769 match ctx.target {
770 ExtractionTarget::Method => {
771 // Check against sibling method names in the class.
772 loop {
773 if !ctx.sibling_method_names.contains(&name) {
774 break;
775 }
776 counter += 1;
777 name = format!("{}{}", base, counter);
778 }
779 }
780 ExtractionTarget::Function => {
781 // Check against function declarations in the file.
782 loop {
783 let pattern_fn = format!("function {}", name);
784 if !content.contains(&pattern_fn) {
785 break;
786 }
787 counter += 1;
788 name = format!("{}{}", base, counter);
789 }
790 }
791 }
792
793 name
794}
795
796// ─── Selection trimming ────────────────────────────────────────────────────
797

Callers 1

generate_function_nameFunction · 0.70

Calls 1

containsMethod · 0.80

Tested by

no test coverage detected