feat: associate request function

This commit is contained in:
Myriad-Dreamin 2024-03-07 16:31:16 +08:00
parent 0c7e67ed9a
commit 50ca444915
9 changed files with 215 additions and 206 deletions

View file

@ -6,22 +6,25 @@ pub struct SelectionRangeRequest {
pub positions: Vec<LspPosition>,
}
pub fn selection_range(
world: &TypstSystemWorld,
req: SelectionRangeRequest,
position_encoding: PositionEncoding,
) -> Option<Vec<SelectionRange>> {
let source = get_suitable_source_in_workspace(world, &req.path).ok()?;
impl SelectionRangeRequest {
pub fn request(
self,
world: &TypstSystemWorld,
position_encoding: PositionEncoding,
) -> Option<Vec<SelectionRange>> {
let source = get_suitable_source_in_workspace(world, &self.path).ok()?;
let mut ranges = Vec::new();
for position in req.positions {
let typst_offset = lsp_to_typst::position_to_offset(position, position_encoding, &source);
let tree = LinkedNode::new(source.root());
let leaf = tree.leaf_at(typst_offset)?;
ranges.push(range_for_node(&source, position_encoding, &leaf));
let mut ranges = Vec::new();
for position in self.positions {
let typst_offset =
lsp_to_typst::position_to_offset(position, position_encoding, &source);
let tree = LinkedNode::new(source.root());
let leaf = tree.leaf_at(typst_offset)?;
ranges.push(range_for_node(&source, position_encoding, &leaf));
}
Some(ranges)
}
Some(ranges)
}
fn range_for_node(