mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 13:13:43 +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)
|
||||
}
|
||||
}
|
|
@ -31,6 +31,8 @@ pub(crate) mod prepare_rename;
|
|||
pub use prepare_rename::*;
|
||||
pub(crate) mod rename;
|
||||
pub use rename::*;
|
||||
pub(crate) mod code_lens;
|
||||
pub use code_lens::*;
|
||||
|
||||
pub mod lsp_typst_boundary;
|
||||
pub use lsp_typst_boundary::*;
|
||||
|
@ -41,6 +43,11 @@ mod polymorphic {
|
|||
use super::prelude::*;
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OnExportRequest {
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OnSaveExportRequest {
|
||||
pub path: PathBuf,
|
||||
|
@ -56,10 +63,12 @@ mod polymorphic {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CompilerQueryRequest {
|
||||
OnExport(OnExportRequest),
|
||||
OnSaveExport(OnSaveExportRequest),
|
||||
Hover(HoverRequest),
|
||||
GotoDefinition(GotoDefinitionRequest),
|
||||
InlayHint(InlayHintRequest),
|
||||
CodeLens(CodeLensRequest),
|
||||
Completion(CompletionRequest),
|
||||
SignatureHelp(SignatureHelpRequest),
|
||||
Rename(RenameRequest),
|
||||
|
@ -76,10 +85,12 @@ mod polymorphic {
|
|||
pub fn fold_feature(&self) -> FoldRequestFeature {
|
||||
use FoldRequestFeature::*;
|
||||
match self {
|
||||
CompilerQueryRequest::OnExport(..) => Mergable,
|
||||
CompilerQueryRequest::OnSaveExport(..) => Mergable,
|
||||
CompilerQueryRequest::Hover(..) => PinnedFirst,
|
||||
CompilerQueryRequest::GotoDefinition(..) => PinnedFirst,
|
||||
CompilerQueryRequest::InlayHint(..) => Unique,
|
||||
CompilerQueryRequest::CodeLens(..) => Unique,
|
||||
CompilerQueryRequest::Completion(..) => Mergable,
|
||||
CompilerQueryRequest::SignatureHelp(..) => PinnedFirst,
|
||||
CompilerQueryRequest::Rename(..) => Mergable,
|
||||
|
@ -95,10 +106,12 @@ mod polymorphic {
|
|||
|
||||
pub fn associated_path(&self) -> Option<&Path> {
|
||||
Some(match self {
|
||||
CompilerQueryRequest::OnExport(..) => return None,
|
||||
CompilerQueryRequest::OnSaveExport(req) => &req.path,
|
||||
CompilerQueryRequest::Hover(req) => &req.path,
|
||||
CompilerQueryRequest::GotoDefinition(req) => &req.path,
|
||||
CompilerQueryRequest::InlayHint(req) => &req.path,
|
||||
CompilerQueryRequest::CodeLens(req) => &req.path,
|
||||
CompilerQueryRequest::Completion(req) => &req.path,
|
||||
CompilerQueryRequest::SignatureHelp(req) => &req.path,
|
||||
CompilerQueryRequest::Rename(req) => &req.path,
|
||||
|
@ -115,10 +128,12 @@ mod polymorphic {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CompilerQueryResponse {
|
||||
OnExport(Option<PathBuf>),
|
||||
OnSaveExport(()),
|
||||
Hover(Option<Hover>),
|
||||
GotoDefinition(Option<GotoDefinitionResponse>),
|
||||
InlayHint(Option<Vec<InlayHint>>),
|
||||
CodeLens(Option<Vec<CodeLens>>),
|
||||
Completion(Option<CompletionResponse>),
|
||||
SignatureHelp(Option<SignatureHelp>),
|
||||
PrepareRename(Option<PrepareRenameResponse>),
|
||||
|
|
|
@ -9,12 +9,14 @@ pub use comemo::{Track, Tracked};
|
|||
pub use itertools::{Format, Itertools};
|
||||
pub use log::{error, trace};
|
||||
pub use lsp_types::{
|
||||
CompletionResponse, DiagnosticRelatedInformation, DocumentSymbol, DocumentSymbolResponse,
|
||||
Documentation, FoldingRange, GotoDefinitionResponse, Hover, InlayHint, Location as LspLocation,
|
||||
MarkupContent, MarkupKind, Position as LspPosition, PrepareRenameResponse, SelectionRange,
|
||||
SemanticTokens, SemanticTokensDelta, SemanticTokensFullDeltaResult, SemanticTokensResult,
|
||||
SignatureHelp, SignatureInformation, SymbolInformation, Url, WorkspaceEdit,
|
||||
CodeLens, CompletionResponse, DiagnosticRelatedInformation, DocumentSymbol,
|
||||
DocumentSymbolResponse, Documentation, FoldingRange, GotoDefinitionResponse, Hover, InlayHint,
|
||||
Location as LspLocation, MarkupContent, MarkupKind, Position as LspPosition,
|
||||
PrepareRenameResponse, SelectionRange, SemanticTokens, SemanticTokensDelta,
|
||||
SemanticTokensFullDeltaResult, SemanticTokensResult, SignatureHelp, SignatureInformation,
|
||||
SymbolInformation, Url, WorkspaceEdit,
|
||||
};
|
||||
pub use serde_json::Value as JsonValue;
|
||||
pub use typst::diag::{EcoString, FileError, FileResult, Tracepoint};
|
||||
pub use typst::foundations::{Func, ParamInfo, Value};
|
||||
pub use typst::syntax::{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue