From 62456fda01da419c9c9de43ce06e8b77d77a87b2 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Sun, 16 Nov 2025 04:37:48 +0800 Subject: [PATCH] dev: adjust a bit --- crates/tinymist-cli/src/cmd/query.rs | 1 + crates/tinymist-query/src/analysis/global.rs | 2 + crates/tinymist-query/src/code_lens.rs | 47 ++++++++++--------- crates/tinymist/src/project.rs | 1 + editors/vscode/src/extension.ts | 8 +++- locales/tinymist-rt.toml | 10 ++-- .../exporter/components/action-buttons.ts | 7 +-- .../exporter/components/format-selector.ts | 2 +- .../features/exporter/components/header.ts | 32 ------------- .../src/features/exporter/components/inout.ts | 9 ++-- .../exporter/components/preview-grid.ts | 2 +- .../src/features/exporter/index.ts | 16 ++----- .../src/features/exporter/styles.css | 7 +-- 13 files changed, 57 insertions(+), 87 deletions(-) delete mode 100644 tools/editor-tools/src/features/exporter/components/header.ts diff --git a/crates/tinymist-cli/src/cmd/query.rs b/crates/tinymist-cli/src/cmd/query.rs index 625aab1e..d04899a1 100644 --- a/crates/tinymist-cli/src/cmd/query.rs +++ b/crates/tinymist-cli/src/cmd/query.rs @@ -72,6 +72,7 @@ pub fn query_main(mut cmds: QueryCommands) -> Result<()> { allow_overlapping_token: const_config.tokens_overlapping_token_support, allow_multiline_token: const_config.tokens_multiline_token_support, remove_html: !config.support_html_in_markdown, + support_client_codelens: true, extended_code_action: config.extended_code_action, completion_feat: config.completion.clone(), color_theme: match config.color_theme.as_deref() { diff --git a/crates/tinymist-query/src/analysis/global.rs b/crates/tinymist-query/src/analysis/global.rs index d8886922..19e16c44 100644 --- a/crates/tinymist-query/src/analysis/global.rs +++ b/crates/tinymist-query/src/analysis/global.rs @@ -65,6 +65,8 @@ pub struct Analysis { pub allow_multiline_token: bool, /// Whether to remove html from markup content in responses. pub remove_html: bool, + /// Whether to add client-side code lens. + pub support_client_codelens: bool, /// Whether to utilize the extended `tinymist.resolveCodeAction` at client /// side. /// diff --git a/crates/tinymist-query/src/code_lens.rs b/crates/tinymist-query/src/code_lens.rs index 7fdb3ba3..33719c73 100644 --- a/crates/tinymist-query/src/code_lens.rs +++ b/crates/tinymist-query/src/code_lens.rs @@ -21,24 +21,29 @@ impl SemanticRequest for CodeLensRequest { let mut res = vec![]; let doc_start = ctx.to_lsp_range(0..0, &source); - let doc_lens = |title: &str, args: Vec| CodeLens { - range: doc_start, - command: Some(Command { - title: title.to_string(), - command: "tinymist.runCodeLens".to_string(), - arguments: Some(args), - }), - data: None, + let mut doc_lens = |title: &str, args: Vec| { + if !ctx.analysis.support_client_codelens { + return; + } + res.push(CodeLens { + range: doc_start, + command: Some(Command { + title: title.to_string(), + command: "tinymist.runCodeLens".to_string(), + arguments: Some(args), + }), + data: None, + }) }; - res.push(doc_lens( + doc_lens( &tinymist_l10n::t!("tinymist-query.code-action.profile", "Profile"), vec!["profile".into()], - )); - res.push(doc_lens( + ); + doc_lens( &tinymist_l10n::t!("tinymist-query.code-action.preview", "Preview"), vec!["preview".into()], - )); + ); let is_html = ctx .world() @@ -46,22 +51,20 @@ impl SemanticRequest for CodeLensRequest { .features .is_enabled(typst::Feature::Html); + doc_lens( + &tinymist_l10n::t!("tinymist-query.code-action.export", "Export"), + vec!["export".into()], + ); if is_html { - res.push(doc_lens( - &tinymist_l10n::t!("tinymist-query.code-action.exportHtml", "Export HTML"), - vec!["export-html".into()], - )); + doc_lens("HTML", vec!["export-html".into()]); } else { - res.push(doc_lens( - &tinymist_l10n::t!("tinymist-query.code-action.exportPdf", "Export PDF"), - vec!["export-pdf".into()], - )); + doc_lens("PDF", vec!["export-pdf".into()]); } - res.push(doc_lens( + doc_lens( &tinymist_l10n::t!("tinymist-query.code-action.more", "More .."), vec!["more".into()], - )); + ); Some(res) } diff --git a/crates/tinymist/src/project.rs b/crates/tinymist/src/project.rs index 4a3355fc..a3001a2f 100644 --- a/crates/tinymist/src/project.rs +++ b/crates/tinymist/src/project.rs @@ -174,6 +174,7 @@ impl ServerState { allow_overlapping_token: const_config.tokens_overlapping_token_support, allow_multiline_token: const_config.tokens_multiline_token_support, remove_html: !config.support_html_in_markdown, + support_client_codelens: true, extended_code_action: config.extended_code_action, completion_feat: config.completion.clone(), color_theme: match config.color_theme.as_deref() { diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts index 377ce508..50d09e4c 100644 --- a/editors/vscode/src/extension.ts +++ b/editors/vscode/src/extension.ts @@ -202,8 +202,8 @@ async function languageActivate(context: IContext) { const initTemplateCommand = (inPlace: boolean) => - (...args: string[]) => - initTemplate(context.context, inPlace, ...args); + (...args: string[]) => + initTemplate(context.context, inPlace, ...args); // prettier-ignore context.subscriptions.push( @@ -556,6 +556,10 @@ async function commandRunCodeLens(...args: string[]): Promise { void vscode.commands.executeCommand(`typst-preview.preview`); return; } + case "export": { + void vscode.commands.executeCommand(`tinymist.openExportTool`); + break; + } case "export-html": { await commandShow("Html"); break; diff --git a/locales/tinymist-rt.toml b/locales/tinymist-rt.toml index bed7bdfe..caced42a 100644 --- a/locales/tinymist-rt.toml +++ b/locales/tinymist-rt.toml @@ -5,13 +5,9 @@ en = "rootPath or typstExtraArgs.root must be an absolute path: {root:?}" zh = "rootPath 或 typstExtraArgs.root 必须是绝对路径:{root:?}" -[tinymist-query.code-action.exportHtml] -en = "Export HTML" -zh = "导出 HTML" - -[tinymist-query.code-action.exportPdf] -en = "Export PDF" -zh = "导出 PDF" +[tinymist-query.code-action.export] +en = "Export" +zh = "导出" [tinymist-query.code-action.more] en = "More .." diff --git a/tools/editor-tools/src/features/exporter/components/action-buttons.ts b/tools/editor-tools/src/features/exporter/components/action-buttons.ts index 23a8faec..cf365dfa 100644 --- a/tools/editor-tools/src/features/exporter/components/action-buttons.ts +++ b/tools/editor-tools/src/features/exporter/components/action-buttons.ts @@ -1,6 +1,6 @@ import van from "vanjs-core"; -const { div, h3, button } = van.tags; +const { div, button } = van.tags; interface ActionButtonsProps { onExport: () => void; @@ -10,8 +10,6 @@ export const ActionButtons = ({ onExport }: ActionButtonsProps) => { return div( { class: "flex flex-col gap-sm" }, - h3("Export Actions"), - // Action Buttons div( { class: "action-buttons flex items-center gap-md" }, @@ -23,7 +21,7 @@ export const ActionButtons = ({ onExport }: ActionButtonsProps) => { class: "btn action-button", onclick: onExport, }, - "📄 Export", + "Export", ), // Create Task Button @@ -33,7 +31,6 @@ export const ActionButtons = ({ onExport }: ActionButtonsProps) => { class: "btn btn-secondary action-button", onclick: handleCreateTask, }, - "⚙️", "Create Task", ), */ ), diff --git a/tools/editor-tools/src/features/exporter/components/format-selector.ts b/tools/editor-tools/src/features/exporter/components/format-selector.ts index 41559920..42ff81b2 100644 --- a/tools/editor-tools/src/features/exporter/components/format-selector.ts +++ b/tools/editor-tools/src/features/exporter/components/format-selector.ts @@ -26,11 +26,11 @@ const FormatCard = (format: ExportFormat, isSelected: boolean, onSelect: () => v return div( { class: `format-card ${isSelected ? "selected" : ""}`, + title: format.label, onclick: onSelect, }, div( { class: "flex justify-between items-center" }, - span({ class: "font-semibold" }, format.label), span({ class: "badge font-mono" }, `.${format.fileExtension}`), ), ); diff --git a/tools/editor-tools/src/features/exporter/components/header.ts b/tools/editor-tools/src/features/exporter/components/header.ts deleted file mode 100644 index 90e4203c..00000000 --- a/tools/editor-tools/src/features/exporter/components/header.ts +++ /dev/null @@ -1,32 +0,0 @@ -import van, { type ChildDom } from "vanjs-core"; - -const { div, h1, p } = van.tags; - -interface HeaderProps { - title?: string; - description?: string; - actions?: ChildDom; -} - -export const Header = - (props: HeaderProps = {}) => - () => { - const { - title = "Export Tool", - description = "Configure and export your Typst documents to various formats", - actions, - } = props; - - return div( - { class: "card flex flex-col gap-sm" }, - div( - { class: "flex flex-col sm:flex-row sm:justify-between sm:items-center gap-sm" }, - div( - { class: "flex flex-col gap-xs" }, - h1({ class: "text-xl font-semibold text-base-content" }, title), - p({ class: "text-desc font-sm" }, description), - ), - actions ? div({ class: "flex gap-xs" }, actions) : null, - ), - ); - }; diff --git a/tools/editor-tools/src/features/exporter/components/inout.ts b/tools/editor-tools/src/features/exporter/components/inout.ts index 882dd9d0..591afc0b 100644 --- a/tools/editor-tools/src/features/exporter/components/inout.ts +++ b/tools/editor-tools/src/features/exporter/components/inout.ts @@ -13,10 +13,13 @@ export const InputSection = ({ inputPath }: InputSectionProps) => { { class: "flex flex-col gap-sm" }, // Input Path Section div( - { class: "flex flex-col gap-xs" }, - h3({ class: "mb-xs" }, "Input Document"), + { class: "flex flex-row items-center gap-xs" }, + h3( + { class: "mb-xs", title: "Configure and export your Typst documents to various formats" }, + "Export Document", + ), input({ - class: "input", + class: "input flex-1", type: "text", placeholder: () => lastFocusedTypstDoc.val || "Document Path", value: inputPath, diff --git a/tools/editor-tools/src/features/exporter/components/preview-grid.ts b/tools/editor-tools/src/features/exporter/components/preview-grid.ts index ee73a71d..4e5c3aba 100644 --- a/tools/editor-tools/src/features/exporter/components/preview-grid.ts +++ b/tools/editor-tools/src/features/exporter/components/preview-grid.ts @@ -116,7 +116,7 @@ const PreviewEmpty = (onGenerate: () => void) => { class: "btn", onclick: onGenerate, }, - "Generate Preview", + "Flush", ), ), ); diff --git a/tools/editor-tools/src/features/exporter/index.ts b/tools/editor-tools/src/features/exporter/index.ts index 32a55d6c..5c0ea37c 100644 --- a/tools/editor-tools/src/features/exporter/index.ts +++ b/tools/editor-tools/src/features/exporter/index.ts @@ -3,7 +3,6 @@ import "./styles.css"; import { ActionButtons } from "./components/action-buttons"; import { FormatSelector } from "./components/format-selector"; -import { Header } from "./components/header"; import { InputSection } from "./components/inout"; import { OptionsPanel } from "./components/options-panel"; import { PreviewGrid } from "./components/preview-grid"; @@ -35,14 +34,14 @@ const ExportTool = () => { return div( { class: "export-tool-container flex flex-col gap-lg text-base-content" }, - Header({ - title: "Export Tool", - description: "Configure and export your Typst documents to various formats", - }), - // Input Document Section InputSection({ inputPath, outputPath }), + // Export Actions + ActionButtons({ + onExport: exportDocument, + }), + // Format Selection FormatSelector({ selectedFormat: format }), @@ -57,11 +56,6 @@ const ExportTool = () => { autoPreview, onPreview: generatePreview, }), - - // Export Actions - ActionButtons({ - onExport: exportDocument, - }), ); }; diff --git a/tools/editor-tools/src/features/exporter/styles.css b/tools/editor-tools/src/features/exporter/styles.css index 565aea0d..fe9ea5a2 100644 --- a/tools/editor-tools/src/features/exporter/styles.css +++ b/tools/editor-tools/src/features/exporter/styles.css @@ -5,20 +5,21 @@ max-width: 80rem; margin: auto; padding: 1rem; + transition: padding 0.2s ease; } /* Format Selector */ .format-selector { display: grid; - grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); + grid-template-columns: repeat(auto-fit, 4rem); gap: 0.75rem; } .format-card { - padding: 1rem; + padding: 0.5rem; background: var(--vscode-panel-background, #1e1e1e); border: 2px solid var(--vscode-panel-border, rgba(128, 128, 128, 0.35)); - border-radius: 0.5rem; + border-radius: 0.3rem; cursor: pointer; transition: all 0.2s ease; position: relative;