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)
| 20 | /// |
| 21 | /// Returns `None` when no `->` or `::` is found (i.e. `AccessKind::Other`). |
| 22 | pub 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 | } |