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

Function resolve_to_fqn

src/util.rs:35–66  ·  view source on GitHub ↗

Resolve an unqualified or partially-qualified PHP class/function name to a fully-qualified name using the file's `use` map and namespace. Rules: - Leading `\` — strip it and return (already fully-qualified). - Unqualified (no `\`): 1. Check the `use_map` for a direct mapping. 2. Prefix with the current namespace. 3. Fall back to the bare name (global namespace). - Qualified (contains `\`, no lead

(
    name: &str,
    use_map: &HashMap<String, String>,
    namespace: &Option<String>,
)

Source from the content-addressed store, hash-verified

33/// 2. Prefix with the current namespace.
34/// 3. Fall back to the bare name.
35pub(crate) fn resolve_to_fqn(
36 name: &str,
37 use_map: &HashMap<String, String>,
38 namespace: &Option<String>,
39) -> String {
40 // Already fully-qualified with leading `\` — strip and return.
41 if let Some(stripped) = name.strip_prefix('\\') {
42 return stripped.to_string();
43 }
44
45 // Unqualified name (no backslash) — try use_map, then namespace, then bare.
46 if !name.contains('\\') {
47 if let Some(fqn) = use_map.get(name) {
48 return fqn.clone();
49 }
50 if let Some(ns) = namespace {
51 return format!("{}\\{}", ns, name);
52 }
53 return name.to_string();
54 }
55
56 // Qualified name (contains `\` but no leading `\`).
57 let first_segment = name.split('\\').next().unwrap_or(name);
58 if let Some(fqn_prefix) = use_map.get(first_segment) {
59 let rest = &name[first_segment.len()..];
60 return format!("{}{}", fqn_prefix, rest);
61 }
62 if let Some(ns) = namespace {
63 return format!("{}\\{}", ns, name);
64 }
65 name.to_string()
66}
67
68/// Resolve a class name to its FQN via the class loader.
69///

Calls 4

containsMethod · 0.80
cloneMethod · 0.80
nextMethod · 0.80
getMethod · 0.45