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

Function apply_property_narrowing

src/completion/resolver.rs:1450–1486  ·  view source on GitHub ↗

Apply instanceof / assert narrowing for a property-access path. This is the property-level analog of the narrowing that [`super::variable::resolution::walk_statements_for_assignments`] performs for plain variables. It re-parses the source, locates the enclosing method body, and walks its statements with a [`VarResolutionCtx`] whose `var_name` is the full property path (e.g. `$this->timeline`).

(
    property_path: &str,
    current_class: &ClassInfo,
    rctx: &ResolutionCtx<'_>,
    results: &mut Vec<Arc<ClassInfo>>, // still operates on Arc<ClassInfo> — called from property chain
)

Source from the content-addressed store, hash-verified

1448/// [`super::types::narrowing::expr_to_subject_key`], so no changes
1449/// to those functions are required.
1450pub(crate) fn apply_property_narrowing(
1451 property_path: &str,
1452 current_class: &ClassInfo,
1453 rctx: &ResolutionCtx<'_>,
1454 results: &mut Vec<Arc<ClassInfo>>, // still operates on Arc<ClassInfo> — called from property chain
1455) {
1456 use crate::parser::with_parsed_program;
1457
1458 // The narrowing walk functions operate on Vec<ClassInfo>, so unwrap
1459 // the Arcs, run narrowing, then re-wrap.
1460 let mut plain: Vec<ClassInfo> = results.drain(..).map(Arc::unwrap_or_clone).collect();
1461
1462 with_parsed_program(
1463 rctx.content,
1464 "apply_property_narrowing",
1465 |program, _content| {
1466 let ctx = VarResolutionCtx {
1467 var_name: property_path,
1468 current_class,
1469 all_classes: rctx.all_classes,
1470 content: rctx.content,
1471 cursor_offset: rctx.cursor_offset,
1472 class_loader: rctx.class_loader,
1473 loaders: Loaders::with_function(rctx.function_loader),
1474 resolved_class_cache: crate::virtual_members::active_resolved_class_cache(),
1475 enclosing_return_type: None,
1476 top_level_scope: None,
1477 branch_aware: false,
1478 match_arm_narrowing: HashMap::new(),
1479 scope_var_resolver: None,
1480 };
1481 walk_property_narrowing_in_statements(program.statements.iter(), &ctx, &mut plain);
1482 },
1483 );
1484
1485 *results = plain.into_iter().map(Arc::new).collect();
1486}
1487
1488/// Walk top-level statements to find the class + method containing the
1489/// cursor, then apply narrowing to `results` for the given property path.

Calls 6

with_parsed_programFunction · 0.85
iterMethod · 0.80
into_iterMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected