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

Function is_inside_docblock

src/completion/source/comment_position.rs:23–38  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

21/// Scans backwards from the cursor to find the nearest `/**` that has not
22/// been closed by a matching `*/` before the cursor position.
23pub 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.

Callers 3

handle_completionMethod · 0.85
extract_phpdoc_prefixFunction · 0.85

Calls 2

position_to_byte_offsetFunction · 0.85
containsMethod · 0.80

Tested by

no test coverage detected