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

Method find_variable_scope

src/symbol_map/mod.rs:558–573  ·  view source on GitHub ↗

Determine the effective scope for a variable reference at `offset`. For most variable spans this is the same as [`find_enclosing_scope`]. However, **parameters** and docblock `@param $var` mentions** sit physically before the opening `{` of the function/method/closure body, so `find_enclosing_scope` returns the *parent* scope for them. This method detects those cases and returns the correct bod

(&self, var_name: &str, offset: u32)

Source from the content-addressed store, hash-verified

556 /// list.
557 /// 3. Otherwise, fall back to `find_enclosing_scope`.
558 pub fn find_variable_scope(&self, var_name: &str, offset: u32) -> u32 {
559 // Case 1: cursor is directly on a parameter or docblock @param
560 // definition token. Both sit physically before the body `{`,
561 // but their `VarDefSite.scope_start` points to the correct
562 // body scope.
563 if let Some(def) = self.var_defs.iter().find(|d| {
564 d.name == var_name
565 && (d.kind == VarDefKind::Parameter || d.kind == VarDefKind::DocblockParam)
566 && offset >= d.offset
567 && offset < d.offset + 1 + d.name.len() as u32
568 }) {
569 return def.scope_start;
570 }
571
572 self.find_enclosing_scope(offset)
573 }
574
575 /// Find the innermost narrowing block (if/elseif/else body, match
576 /// arm, switch case) that contains `offset`.

Callers 4

highlight_variableMethod · 0.80

Calls 3

iterMethod · 0.80
find_enclosing_scopeMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected