mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-19 10:45:02 +00:00
feat: fix show pdf and add export pdf code lens
This commit is contained in:
parent
b508843fc0
commit
e714ab462f
10 changed files with 218 additions and 55 deletions
41
crates/tinymist-query/src/code_lens.rs
Normal file
41
crates/tinymist-query/src/code_lens.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use lsp_types::Command;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CodeLensRequest {
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
impl CodeLensRequest {
|
||||
pub fn request(
|
||||
self,
|
||||
world: &TypstSystemWorld,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<Vec<CodeLens>> {
|
||||
let source = get_suitable_source_in_workspace(world, &self.path).ok()?;
|
||||
|
||||
let doc_start = typst_to_lsp::range(0..0, &source, position_encoding);
|
||||
|
||||
let mut res = vec![];
|
||||
|
||||
let run_code_lens_cmd = |title: &str, args: Vec<JsonValue>| Command {
|
||||
title: title.to_string(),
|
||||
command: "tinymist.runCodeLens".to_string(),
|
||||
arguments: Some(args),
|
||||
};
|
||||
|
||||
let doc_lens = |title: &str, args: Vec<JsonValue>| CodeLens {
|
||||
range: doc_start,
|
||||
command: Some(run_code_lens_cmd(title, args)),
|
||||
data: None,
|
||||
};
|
||||
|
||||
res.push(doc_lens("Preview", vec!["preview".into()]));
|
||||
res.push(doc_lens("Preview in ..", vec!["preview-in".into()]));
|
||||
res.push(doc_lens("Export PDF", vec!["export-pdf".into()]));
|
||||
res.push(doc_lens("Export ..", vec!["export-as".into()]));
|
||||
|
||||
Some(res)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue