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

Function find_keyword_pos

src/completion/phpdoc/helpers.rs:12–27  ·  view source on GitHub ↗

Shared helpers for PHPDoc context detection and generation. These functions are used by both `context.rs` and `generation.rs` to parse PHP declarations (parameter lists, keyword positions, balanced parentheses). Find the position of a whole-word keyword in a declaration string. Returns the byte offset of the first occurrence of `keyword` that is not part of a larger identifier (i.e. the characte

(decl: &str, keyword: &str)

Source from the content-addressed store, hash-verified

10/// not part of a larger identifier (i.e. the characters immediately
11/// before and after the match are not ASCII-alphanumeric).
12pub(super) fn find_keyword_pos(decl: &str, keyword: &str) -> Option<usize> {
13 let lower = decl.to_lowercase();
14 let mut start = 0;
15 while let Some(pos) = lower[start..].find(keyword) {
16 let abs_pos = start + pos;
17 let before_ok = abs_pos == 0 || !decl.as_bytes()[abs_pos - 1].is_ascii_alphanumeric();
18 let after_pos = abs_pos + keyword.len();
19 let after_ok =
20 after_pos >= decl.len() || !decl.as_bytes()[after_pos].is_ascii_alphanumeric();
21 if before_ok && after_ok {
22 return Some(abs_pos);
23 }
24 start = abs_pos + keyword.len();
25 }
26 None
27}
28
29/// Find the position of the matching `)` for the first `(`, handling nesting.
30///

Callers 2

parse_declaration_infoFunction · 0.85
parse_symbol_infoFunction · 0.85

Calls 1

findMethod · 0.45

Tested by

no test coverage detected