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

Function extract_completion_target

src/completion/target.rs:22–40  ·  view source on GitHub ↗

Detect the access operator before the cursor position and extract both the `AccessKind` and the textual subject to its left. Returns `None` when no `->` or `::` is found (i.e. `AccessKind::Other`).

(content: &str, position: Position)

Source from the content-addressed store, hash-verified

20///
21/// Returns `None` when no `->` or `::` is found (i.e. `AccessKind::Other`).
22pub fn extract_completion_target(content: &str, position: Position) -> Option<CompletionTarget> {
23 let lines: Vec<&str> = content.lines().collect();
24 if position.line as usize >= lines.len() {
25 return None;
26 }
27
28 // Collapse multi-line method chains so that continuation lines
29 // (starting with `->` or `?->`) are joined with preceding lines.
30 let (line, col) =
31 collapse_continuation_lines(&lines, position.line as usize, position.character as usize);
32 let chars: Vec<char> = line.chars().collect();
33
34 let (subject, access_kind) = detect_access_operator(&chars, col)?;
35
36 Some(CompletionTarget {
37 access_kind,
38 subject,
39 })
40}

Calls 2

detect_access_operatorFunction · 0.85