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

Function is_preceded_by_use

src/classmap_scanner.rs:1592–1610  ·  view source on GitHub ↗

Check whether the keyword at position `i` is preceded by `use ` (with optional whitespace), indicating a `use function` or `use const` import statement rather than a declaration.

(content: &[u8], i: usize)

Source from the content-addressed store, hash-verified

1590/// (with optional whitespace), indicating a `use function` or `use const`
1591/// import statement rather than a declaration.
1592fn is_preceded_by_use(content: &[u8], i: usize) -> bool {
1593 if i < 4 {
1594 return false;
1595 }
1596 // Walk backwards over whitespace.
1597 let mut j = i - 1;
1598 while j > 0 && content[j].is_ascii_whitespace() {
1599 j -= 1;
1600 }
1601 // Check for `use` (the 'e' is at j, 'u' at j-2).
1602 if j >= 2 && &content[j - 2..=j] == b"use" {
1603 // Make sure `use` itself is at a keyword boundary (not part
1604 // of a longer identifier like `reuse`).
1605 if j - 2 == 0 || is_boundary_char(content[j - 3]) {
1606 return true;
1607 }
1608 }
1609 false
1610}
1611
1612/// Check whether a keyword can start at this offset.
1613///

Callers 1

find_symbolsFunction · 0.85

Calls 1

is_boundary_charFunction · 0.85

Tested by

no test coverage detected