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

Function resolve_in_top_level

src/completion/variable/forward_walk.rs:2491–2511  ·  view source on GitHub ↗

Resolve the target variable from top-level code (outside any function or class body) using the forward walker. Seeds superglobals, then walks all top-level statements forward to the cursor, skipping class/function/interface/enum/trait declarations (which have their own isolated scopes).

(
    var_name: &str,
    statements: impl Iterator<Item = &'b Statement<'b>>,
    ctx: &ForwardWalkCtx<'_>,
)

Source from the content-addressed store, hash-verified

2489/// the cursor, skipping class/function/interface/enum/trait declarations
2490/// (which have their own isolated scopes).
2491pub(crate) fn resolve_in_top_level<'b>(
2492 var_name: &str,
2493 statements: impl Iterator<Item = &'b Statement<'b>>,
2494 ctx: &ForwardWalkCtx<'_>,
2495) -> Option<Vec<ResolvedType>> {
2496 let mut scope = ScopeState::new();
2497
2498 // Seed superglobals so that `$_GET`, `$_POST`, etc. resolve.
2499 seed_superglobals(&mut scope);
2500
2501 // Walk the top-level statements forward.
2502 walk_body_forward(statements, &mut scope, ctx);
2503
2504 // Return `Some` when the variable exists in scope (even with
2505 // empty types), `None` when it was never seen.
2506 if scope.contains(var_name) {
2507 Some(scope.get(var_name).to_vec())
2508 } else {
2509 None
2510 }
2511}
2512
2513/// Walk top-level statements to build a scope of variable types for
2514/// `global` keyword resolution. This is a lightweight walk that only

Callers 1

Calls 4

seed_superglobalsFunction · 0.85
walk_body_forwardFunction · 0.85
containsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected