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

Method file_context

src/util.rs:1569–1607  ·  view source on GitHub ↗

Gather the per-file context (classes, use-map, namespace) in one call. This replaces the repeated lock-and-unwrap boilerplate that was duplicated across the completion handler, definition resolver, member definition, implementation resolver, and variable definition modules. Each of those sites used to have three nearly-identical blocks acquiring `uri_classes_index`, `use_map`, and `namespace_map

(&self, uri: &str)

Source from the content-addressed store, hash-verified

1567 /// blocks acquiring `uri_classes_index`, `use_map`, and `namespace_map` locks
1568 /// and extracting the entry for a given URI.
1569 pub(crate) fn file_context(&self, uri: &str) -> FileContext {
1570 let classes = self
1571 .uri_classes_index
1572 .read()
1573 .get(uri)
1574 .cloned()
1575 .unwrap_or_default();
1576
1577 // The legacy use_map (short name → FQN from `use` statements)
1578 // remains the canonical import table. `resolved_names` is a
1579 // supplementary data source for consumers that can query by
1580 // byte offset — it must NOT replace the use_map because
1581 // `to_use_map()` only contains names that are actually
1582 // *referenced* in the code, not all *declared* imports.
1583 // The unused-imports diagnostic relies on seeing declared-but-
1584 // unreferenced imports.
1585 let use_map = self
1586 .file_imports
1587 .read()
1588 .get(uri)
1589 .cloned()
1590 .unwrap_or_default();
1591
1592 let namespace = self
1593 .file_namespaces
1594 .read()
1595 .get(uri)
1596 .and_then(|spans| spans.first())
1597 .and_then(|s| s.namespace.clone());
1598
1599 let resolved_names = self.resolved_names.read().get(uri).cloned();
1600
1601 FileContext {
1602 classes,
1603 use_map,
1604 namespace,
1605 resolved_names,
1606 }
1607 }
1608
1609 /// Like [`file_context`](Self::file_context) but resolves the namespace
1610 /// for the namespace block that contains `byte_offset`.

Callers 15

runFunction · 0.80
handle_inlay_hintsMethod · 0.80
on_type_formattingMethod · 0.80
handle_signature_helpMethod · 0.80
supertypes_implMethod · 0.80
subtypes_implMethod · 0.80
resolve_from_symbolMethod · 0.80

Calls 3

cloneMethod · 0.80
getMethod · 0.45
firstMethod · 0.45