Returns `true` if the given position is inside a `/** … */` docblock. Scans backwards from the cursor to find the nearest `/**` that has not been closed by a matching `*/` before the cursor position.
(content: &str, position: Position)
| 21 | /// Scans backwards from the cursor to find the nearest `/**` that has not |
| 22 | /// been closed by a matching `*/` before the cursor position. |
| 23 | pub fn is_inside_docblock(content: &str, position: Position) -> bool { |
| 24 | // Convert position to byte offset for easier scanning |
| 25 | let byte_offset = position_to_byte_offset(content, position); |
| 26 | |
| 27 | let before_cursor = &content[..byte_offset.min(content.len())]; |
| 28 | |
| 29 | // Find the last `/**` before the cursor |
| 30 | let Some(open_pos) = before_cursor.rfind("/**") else { |
| 31 | return false; |
| 32 | }; |
| 33 | |
| 34 | // Check if there is a `*/` between the `/**` and the cursor |
| 35 | // (which would mean the docblock is closed) |
| 36 | let after_open = &before_cursor[open_pos + 3..]; |
| 37 | !after_open.contains("*/") |
| 38 | } |
| 39 | |
| 40 | /// Returns `true` if the given position is inside a `//` line comment or |
| 41 | /// a `/* … */` block comment that is **not** a `/** … */` docblock. |
no test coverage detected