Skip to content

Commit

Permalink
Implement folding for for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcaliburZero committed Nov 5, 2023
1 parent b56b545 commit b1a5644
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/server/state.rs
Expand Up @@ -326,6 +326,33 @@ impl ServerState {
}
}

// Find for loops
let query = Query::new(get_quickbms_language(), r#"(for_statement) @for_statement"#).unwrap();

let mut query_cursor = QueryCursor::new();
let text_callback = |node: tree_sitter::Node| format!("{:?}", node); // TODO: placeholder

let matches = query_cursor.captures(&query, tree.root_node(), text_callback);
for (m, _) in matches {
let for_statement = m.captures[0].node;
let location = for_statement.range().to_location(&url);

let for_body = for_statement.child_by_field_name("body");
if let Some(for_body) = for_body {
let for_body_location = for_body.range().to_location(&url);

// If statement body
folding_ranges.push(FoldingRange {
start_line: location.range.start.line,
start_character: None,
end_line: for_body_location.range.end.line,
end_character: None,
kind: Some(FoldingRangeKind::Region),
});
}
}


Some(folding_ranges)
}
}
Expand Down

0 comments on commit b1a5644

Please sign in to comment.