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

Method find_member_position_in_class

src/definition/implementation.rs:1061–1096  ·  view source on GitHub ↗

Find a member position scoped to a specific class body. When multiple classes in the same file define a method with the same name, [`find_member_position`](Self::find_member_position) would always return the first match. This variant restricts the search to lines that fall within the class's `start_offset..end_offset` byte range so that each implementing class resolves to its own definition.

(
        content: &str,
        member_name: &str,
        kind: MemberKind,
        cls: &ClassInfo,
    )

Source from the content-addressed store, hash-verified

1059 /// byte range so that each implementing class resolves to its own
1060 /// definition.
1061 fn find_member_position_in_class(
1062 content: &str,
1063 member_name: &str,
1064 kind: MemberKind,
1065 cls: &ClassInfo,
1066 ) -> Option<Position> {
1067 // Fast path: use stored AST offset when available.
1068 let name_offset = cls.member_name_offset(member_name, kind.as_str());
1069 if name_offset.is_some() {
1070 return Self::find_member_position(content, member_name, kind, name_offset);
1071 }
1072
1073 // Convert byte offsets to line numbers.
1074 let start_line = content
1075 .get(..cls.start_offset as usize)
1076 .map(|s| s.matches('\n').count())
1077 .unwrap_or(0);
1078 let end_line = content
1079 .get(..cls.end_offset as usize)
1080 .map(|s| s.matches('\n').count())
1081 .unwrap_or(usize::MAX);
1082
1083 // Build a sub-content containing only the class body lines and
1084 // delegate to the existing searcher, adjusting the result line.
1085 let class_lines: Vec<&str> = content
1086 .lines()
1087 .skip(start_line)
1088 .take(end_line - start_line + 1)
1089 .collect();
1090 let class_body = class_lines.join("\n");
1091
1092 Self::find_member_position(&class_body, member_name, kind, None).map(|pos| Position {
1093 line: pos.line + start_line as u32,
1094 character: pos.character,
1095 })
1096 }
1097
1098 /// Get the FQN for a class given its short name, by looking it up in
1099 /// the `fqn_uri_index`.

Callers

nothing calls this directly

Calls 7

member_name_offsetMethod · 0.80
as_strMethod · 0.80
matchesMethod · 0.80
mapMethod · 0.45
getMethod · 0.45
countMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected