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

Function is_preceding_docblock_removed

src/stubs.rs:168–217  ·  view source on GitHub ↗

Shared helper: check if the docblock immediately preceding the declaration at `decl_pos` contains `@removed X.Y` where `php_version >= X.Y`.

(
    source: &str,
    decl_pos: usize,
    php_version: crate::types::PhpVersion,
)

Source from the content-addressed store, hash-verified

166/// declaration at `decl_pos` contains `@removed X.Y` where
167/// `php_version >= X.Y`.
168fn is_preceding_docblock_removed(
169 source: &str,
170 decl_pos: usize,
171 php_version: crate::types::PhpVersion,
172) -> bool {
173 let before = &source[..decl_pos];
174 let Some(doc_end) = before.rfind("*/") else {
175 return false;
176 };
177
178 // Make sure there is no intervening declaration between the
179 // docblock end and our target — otherwise the docblock belongs
180 // to a different element.
181 let between = &source[doc_end + 2..decl_pos];
182 if between.contains("function ") || between.contains("class ") || between.contains("interface ")
183 {
184 return false;
185 }
186
187 let Some(doc_start) = source[..doc_end].rfind("/**") else {
188 return false;
189 };
190
191 let docblock = &source[doc_start..doc_end + 2];
192
193 // Simple line-by-line scan for `@removed X.Y` instead of a full
194 // docblock parse. This is called for every stub entry during
195 // `set_php_version`, so avoiding the mago-docblock parser here
196 // saves significant startup time.
197 for line in docblock.lines() {
198 let trimmed = line.trim().trim_start_matches('*').trim();
199 let rest = if let Some(r) = trimmed.strip_prefix("@removed") {
200 r
201 } else {
202 continue;
203 };
204 // The version string follows the tag, separated by whitespace.
205 let rest = rest.trim_start();
206 if rest.is_empty() {
207 continue;
208 }
209 if let Some(ver) = crate::types::PhpVersion::from_composer_constraint(rest)
210 && php_version >= ver
211 {
212 return true;
213 }
214 }
215
216 false
217}
218
219/// Quick byte-level check whether a stub constant has been
220/// `@removed` at or before the given PHP version.

Callers 3

is_stub_function_removedFunction · 0.85
is_stub_class_removedFunction · 0.85
is_stub_constant_removedFunction · 0.85

Calls 2

containsMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected