fix: don't panic on bad node range

This commit is contained in:
Myriad-Dreamin 2024-03-08 21:13:22 +08:00
parent 4abde9de2e
commit 964def25a9
13 changed files with 51 additions and 92 deletions

View file

@ -15,15 +15,14 @@ impl CompletionRequest {
position_encoding: PositionEncoding,
) -> Option<CompletionResponse> {
let source = get_suitable_source_in_workspace(world, &self.path).ok()?;
let typst_offset =
lsp_to_typst::position_to_offset(self.position, position_encoding, &source);
let typst_offset = lsp_to_typst::position(self.position, position_encoding, &source)?;
let (typst_start_offset, completions) =
typst_ide::autocomplete(world, doc.as_deref(), &source, typst_offset, self.explicit)?;
let lsp_start_position =
typst_to_lsp::offset_to_position(typst_start_offset, position_encoding, &source);
let replace_range = LspRawRange::new(lsp_start_position, self.position);
let replace_range = LspRange::new(lsp_start_position, self.position);
Some(typst_to_lsp::completions(&completions, replace_range).into())
}
}