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

Function find_class_at_offset

src/util.rs:772–778  ·  view source on GitHub ↗

Find which class the cursor (byte offset) is inside. When multiple classes contain the offset (e.g. an anonymous class nested inside a named class's method), the smallest (most specific) class is returned. This ensures that `$this` inside an anonymous class body resolves to the anonymous class, not the outer class.

(classes: &[Arc<ClassInfo>], offset: u32)

Source from the content-addressed store, hash-verified

770/// class is returned. This ensures that `$this` inside an anonymous
771/// class body resolves to the anonymous class, not the outer class.
772pub(crate) fn find_class_at_offset(classes: &[Arc<ClassInfo>], offset: u32) -> Option<&ClassInfo> {
773 classes
774 .iter()
775 .map(|c| c.as_ref())
776 .filter(|c| offset >= c.start_offset && offset <= c.end_offset)
777 .min_by_key(|c| c.end_offset - c.start_offset)
778}
779
780/// Find a class in a slice by name, preferring namespace-aware matching
781/// when the name is fully qualified.

Calls 3

filterMethod · 0.80
iterMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected