mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-19 02: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())
|
||||
}
|
||||
|
|
|
@ -17,10 +17,11 @@ impl GotoDefinitionRequest {
|
|||
position_encoding: PositionEncoding,
|
||||
) -> Option<GotoDefinitionResponse> {
|
||||
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)?;
|
||||
let cursor = offset + 1;
|
||||
|
||||
let def = {
|
||||
let ast_node = LinkedNode::new(source.root()).leaf_at(typst_offset + 1)?;
|
||||
let ast_node = LinkedNode::new(source.root()).leaf_at(cursor)?;
|
||||
let t: &dyn World = world;
|
||||
find_definition(t.track(), source.id(), ast_node)?
|
||||
};
|
||||
|
|
|
@ -14,11 +14,13 @@ impl HoverRequest {
|
|||
position_encoding: PositionEncoding,
|
||||
) -> Option<Hover> {
|
||||
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_tooltip = typst_ide::tooltip(world, doc.as_deref(), &source, typst_offset)?;
|
||||
let typst_tooltip = typst_ide::tooltip(world, doc.as_deref(), &source, cursor)?;
|
||||
|
||||
let ast_node = LinkedNode::new(source.root()).leaf_at(typst_offset + 1)?;
|
||||
let ast_node = LinkedNode::new(source.root()).leaf_at(cursor)?;
|
||||
let range = typst_to_lsp::range(ast_node.range(), &source, position_encoding);
|
||||
|
||||
Some(Hover {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue