mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-23 04:35:00 +00:00
fix: call typst-ide with cursor values
This commit is contained in:
parent
888aecbe7e
commit
2a60c1caf9
3 changed files with 15 additions and 9 deletions
|
@ -14,14 +14,17 @@ impl CompletionRequest {
|
|||
doc: Option<Arc<TypstDocument>>,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<CompletionResponse> {
|
||||
let doc = doc.as_deref();
|
||||
let source = get_suitable_source_in_workspace(world, &self.path).ok()?;
|
||||
let typst_offset = lsp_to_typst::position(self.position, position_encoding, &source)?;
|
||||
let offset = lsp_to_typst::position(self.position, position_encoding, &source)?;
|
||||
// the typst's cursor is 1-based, so we need to add 1 to the offset
|
||||
let cursor = offset + 1;
|
||||
|
||||
let (typst_start_offset, completions) =
|
||||
typst_ide::autocomplete(world, doc.as_deref(), &source, typst_offset, self.explicit)?;
|
||||
let (offset, completions) =
|
||||
typst_ide::autocomplete(world, doc, &source, cursor, self.explicit)?;
|
||||
|
||||
let lsp_start_position =
|
||||
typst_to_lsp::offset_to_position(typst_start_offset, position_encoding, &source);
|
||||
typst_to_lsp::offset_to_position(offset, position_encoding, &source);
|
||||
let replace_range = LspRange::new(lsp_start_position, self.position);
|
||||
Some(typst_to_lsp::completions(&completions, replace_range).into())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue