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

Method extract_functions_from_statements

src/parser/functions.rs:80–464  ·  view source on GitHub ↗

Extract standalone function definitions from a sequence of statements. Recurses into `Statement::Namespace` blocks, passing the namespace name down so that each `FunctionInfo` records which namespace it belongs to (if any).

(
        statements: impl Iterator<Item = &'a Statement<'a>>,
        functions: &mut Vec<FunctionInfo>,
        current_namespace: &Option<String>,
        doc_ctx: Option<&DocblockCtx<'a>>,
    )

Source from the content-addressed store, hash-verified

78 /// name down so that each `FunctionInfo` records which namespace it
79 /// belongs to (if any).
80 pub(crate) fn extract_functions_from_statements<'a>(
81 statements: impl Iterator<Item = &'a Statement<'a>>,
82 functions: &mut Vec<FunctionInfo>,
83 current_namespace: &Option<String>,
84 doc_ctx: Option<&DocblockCtx<'a>>,
85 ) {
86 for statement in statements {
87 match statement {
88 Statement::Function(func) => {
89 // Skip functions whose #[PhpStormStubsElementAvailable]
90 // range excludes the target PHP version.
91 if let Some(ctx) = doc_ctx
92 && let Some(ver) = ctx.php_version
93 && !is_available_for_version(&func.attribute_lists, ctx, ver)
94 {
95 continue;
96 }
97
98 // Skip functions whose docblock has `@removed X.Y`
99 // where X.Y <= the target PHP version.
100 if let Some(ctx) = doc_ctx
101 && let Some(ver) = ctx.php_version
102 && is_removed_for_version(func, ctx, ver)
103 {
104 continue;
105 }
106
107 let name = atom(func.name.value);
108 let name_offset = func.name.span.start.offset;
109 let php_version = doc_ctx.and_then(|ctx| ctx.php_version);
110 let mut parameters = extract_parameters(
111 &func.parameter_list,
112 doc_ctx.map(|ctx| ctx.content),
113 php_version,
114 doc_ctx,
115 );
116 let raw_native_return_type = func
117 .return_type_hint
118 .as_ref()
119 .map(|rth| extract_hint_type(&rth.hint));
120
121 // Check for a #[LanguageLevelTypeAware] override on the
122 // function's return type. When present, it replaces the
123 // native type hint with the version-appropriate string.
124 let native_return_type = if let Some(ctx) = doc_ctx
125 && let Some(ver) = ctx.php_version
126 {
127 super::extract_language_level_type(&func.attribute_lists, ctx, ver)
128 .or(raw_native_return_type)
129 } else {
130 raw_native_return_type
131 };
132
133 // Apply PHPDoc `@return` override for the function.
134 // Also extract PHPStan conditional return types,
135 // type assertion annotations, and `@deprecated` if present.
136
137 // Parse the docblock once — used by both the

Callers

nothing calls this directly

Tested by

no test coverage detected