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

Method load_stub_class

src/resolution.rs:213–242  ·  view source on GitHub ↗

Try to load a class from the embedded stub index only. This is the in-memory-only counterpart of [`find_or_load_class`]. It checks the `uri_classes_index` first (O(1) via the FQN index), and if the class hasn't been parsed yet, looks it up in the in-memory `stub_index`. When found there, it parses and caches the stub under a `phpantom-stub://` URI so subsequent lookups are free. No disk I/O is

(&self, class_name: &str)

Source from the content-addressed store, hash-verified

211 /// PSR-4, vendor) are not resolved — callers that need those should
212 /// use [`find_or_load_class`] instead.
213 pub(crate) fn load_stub_class(&self, class_name: &str) -> Option<Arc<ClassInfo>> {
214 let last_segment = short_name(class_name);
215
216 // Fast path: already parsed and cached.
217 if let Some(cls) = self.find_class_in_uri_classes_index(class_name) {
218 return Some(cls);
219 }
220
221 // Look up in the in-memory stub index.
222 let stub_idx = self.stub_index.read();
223 let stub_content = if class_name.contains('\\') {
224 // Namespaced lookup (e.g. "BcMath\\Number").
225 stub_idx.get(class_name).copied()
226 } else {
227 // Global-namespace lookup (e.g. "PDO").
228 stub_idx.get(last_segment).copied()
229 };
230
231 if let Some(content) = stub_content {
232 let stub_uri = format!("phpantom-stub://{}", class_name);
233 let ver = Some(self.php_version());
234 if let Some(classes) = self.parse_and_cache_content_versioned(content, &stub_uri, ver)
235 && let Some(cls) = classes.iter().find(|c| c.name == last_segment)
236 {
237 return Some(Arc::clone(cls));
238 }
239 }
240
241 None
242 }
243
244 /// Parse a PHP file from disk (or from a phar archive), cache the
245 /// results, and return the extracted classes.

Callers 2

ctor_params_forMethod · 0.80
check_context_matchMethod · 0.80

Calls 8

containsMethod · 0.80
php_versionMethod · 0.80
iterMethod · 0.80
short_nameFunction · 0.70
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected