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

Method handle_folding_range

src/folding.rs:22–46  ·  view source on GitHub ↗

Compute folding ranges for the given file content. Re-parses the source with `mago_syntax` (the raw AST is not cached) and walks every statement/expression to emit `FoldingRange` entries.

(&self, content: &str)

Source from the content-addressed store, hash-verified

20 /// Re-parses the source with `mago_syntax` (the raw AST is not cached)
21 /// and walks every statement/expression to emit `FoldingRange` entries.
22 pub fn handle_folding_range(&self, content: &str) -> Option<Vec<FoldingRange>> {
23 let arena = Bump::new();
24 let file_id = mago_database::file::FileId::new("input.php");
25 let program = mago_syntax::parser::parse_file_content(&arena, file_id, content);
26
27 let mut ranges: Vec<FoldingRange> = Vec::new();
28
29 // ── AST walk ──
30 for stmt in program.statements.iter() {
31 collect_from_statement(stmt, content, &mut ranges);
32 }
33
34 // ── Trivia (comments) ──
35 collect_comment_ranges(&program.trivia, content, &mut ranges);
36
37 // Filter out single-line ranges and sort by start position.
38 ranges.retain(|r| r.start_line < r.end_line);
39 ranges.sort_by(|a, b| {
40 a.start_line
41 .cmp(&b.start_line)
42 .then(a.end_line.cmp(&b.end_line))
43 });
44
45 Some(ranges)
46 }
47}
48
49// ─── Helpers ────────────────────────────────────────────────────────────────

Callers 2

folding_rangeMethod · 0.80
get_folding_rangesFunction · 0.80

Calls 3

collect_comment_rangesFunction · 0.85
iterMethod · 0.80
collect_from_statementFunction · 0.70

Tested by

no test coverage detected