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

Method parse_php_versioned_with_namespaces

src/parser/mod.rs:1080–1138  ·  view source on GitHub ↗

Like [`parse_php_versioned`] but returns each class together with the namespace block it was declared in. This is needed by [`parse_and_cache_content_versioned`](crate::resolution) so that multi-namespace stub files (e.g. PDO.php with both `namespace { }` and `namespace Pdo { }`) resolve parent class names against the correct namespace context.

(
        content: &str,
        php_version: Option<PhpVersion>,
    )

Source from the content-addressed store, hash-verified

1078 /// `namespace { }` and `namespace Pdo { }`) resolve parent class
1079 /// names against the correct namespace context.
1080 pub fn parse_php_versioned_with_namespaces(
1081 content: &str,
1082 php_version: Option<PhpVersion>,
1083 ) -> Vec<(ClassInfo, Option<String>)> {
1084 with_parsed_program(content, "parse_php", |program, content| {
1085 let mut use_map = HashMap::new();
1086 Self::extract_use_statements_from_statements(program.statements.iter(), &mut use_map);
1087 let namespace = Self::extract_namespace_from_statements(program.statements.iter());
1088
1089 let doc_ctx = DocblockCtx {
1090 trivias: program.trivia.as_slice(),
1091 content,
1092 php_version,
1093 use_map,
1094 namespace,
1095 };
1096
1097 let mut result: Vec<(ClassInfo, Option<String>)> = Vec::new();
1098
1099 for statement in program.statements.iter() {
1100 match statement {
1101 Statement::Namespace(ns) => {
1102 let block_ns: Option<String> = ns
1103 .name
1104 .as_ref()
1105 .map(|ident| ident.value().to_string())
1106 .filter(|n| !n.is_empty());
1107
1108 let mut block_classes = Vec::new();
1109 Self::extract_classes_from_statements(
1110 ns.statements().iter(),
1111 &mut block_classes,
1112 Some(&doc_ctx),
1113 );
1114 for cls in block_classes {
1115 result.push((cls, block_ns.clone()));
1116 }
1117 }
1118 Statement::Class(_)
1119 | Statement::Interface(_)
1120 | Statement::Trait(_)
1121 | Statement::Enum(_) => {
1122 let mut top_classes = Vec::new();
1123 Self::extract_classes_from_statements(
1124 std::iter::once(statement),
1125 &mut top_classes,
1126 Some(&doc_ctx),
1127 );
1128 for cls in top_classes {
1129 result.push((cls, None));
1130 }
1131 }
1132 _ => {}
1133 }
1134 }
1135
1136 result
1137 })

Callers

nothing calls this directly

Calls 7

with_parsed_programFunction · 0.85
iterMethod · 0.80
filterMethod · 0.80
pushMethod · 0.80
cloneMethod · 0.80
mapMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected