A human-friendly DSL for ATProto Lexicons

Fix import reference codegen

+29 -6
+29 -6
mlf-codegen/src/lib.rs
··· 622 622 }) 623 623 } 624 624 } else if path.segments.len() == 1 { 625 - // Couldn't resolve namespace - fall back to heuristic 626 - // Single segment likely means local reference 625 + // Couldn't resolve namespace - check if it's an imported type 627 626 let name = &path.segments[0].name; 628 - json!({ 629 - "type": "ref", 630 - "ref": format!("#{}", name) 631 - }) 627 + let imports = workspace.get_imports(current_namespace); 628 + 629 + // Look for this name in imports 630 + if let Some((_local_name, original_path)) = imports.iter().find(|(local, _)| local == name) { 631 + // Build the full namespace#type reference from the import path 632 + // original_path is like ["com", "atproto", "label", "defs", "label"] 633 + // We want "com.atproto.label.defs#label" 634 + if original_path.len() > 1 { 635 + let namespace = original_path[..original_path.len() - 1].join("."); 636 + let type_name = original_path.last().unwrap(); 637 + json!({ 638 + "type": "ref", 639 + "ref": format!("{}#{}", namespace, type_name) 640 + }) 641 + } else { 642 + // Fallback: single-segment import (shouldn't happen but handle it) 643 + json!({ 644 + "type": "ref", 645 + "ref": format!("#{}", name) 646 + }) 647 + } 648 + } else { 649 + // Not an import - assume local reference 650 + json!({ 651 + "type": "ref", 652 + "ref": format!("#{}", name) 653 + }) 654 + } 632 655 } else { 633 656 // Multi-segment path ref - use as-is 634 657 let namespace = path.segments[..path.segments.len()-1]