diff --git a/crates/tinymist-cli/src/cmd/query.rs b/crates/tinymist-cli/src/cmd/query.rs index d04899a1..cf1808e1 100644 --- a/crates/tinymist-cli/src/cmd/query.rs +++ b/crates/tinymist-cli/src/cmd/query.rs @@ -72,7 +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, + support_client_codelens: config.support_client_codelens, 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/code_lens.rs b/crates/tinymist-query/src/code_lens.rs index 33719c73..f01302e9 100644 --- a/crates/tinymist-query/src/code_lens.rs +++ b/crates/tinymist-query/src/code_lens.rs @@ -66,6 +66,32 @@ impl SemanticRequest for CodeLensRequest { vec!["more".into()], ); + if !ctx.analysis.support_client_codelens + && let Some(uri) = path_to_url(&self.path) + .ok() + .and_then(|u| serde_json::to_value(u).ok()) + { + res.push(CodeLens { + range: doc_start, + command: Some(Command { + title: if is_html { + tinymist_l10n::t!("tinymist-query.code-action.exportPdf", "Export PDF") + } else { + tinymist_l10n::t!("tinymist-query.code-action.exportHtml", "Export HTML") + } + .to_string(), + command: if is_html { + "tinymist.exportPdf" + } else { + "tinymist.exportHtml" + } + .to_string(), + arguments: Some(vec![uri]), + }), + data: None, + }) + } + Some(res) } } diff --git a/crates/tinymist/src/config.rs b/crates/tinymist/src/config.rs index dbb6b5fb..a42e7d1e 100644 --- a/crates/tinymist/src/config.rs +++ b/crates/tinymist/src/config.rs @@ -87,6 +87,8 @@ pub struct Config { pub notify_status: bool, /// Whether to remove HTML from markup content in responses. pub support_html_in_markdown: bool, + /// Whether to support client code lenses. + pub support_client_codelens: bool, /// Whether to utilize the extended `tinymist.resolveCodeAction` at client /// side. pub extended_code_action: bool, @@ -355,6 +357,7 @@ impl Config { assign_config!(semantic_tokens := "semanticTokens"?: SemanticTokensMode); assign_config!(delegate_fs_requests := "delegateFsRequests"?: bool); assign_config!(support_html_in_markdown := "supportHtmlInMarkdown"?: bool); + assign_config!(support_client_codelens := "supportClientCodelens"?: bool); assign_config!(extended_code_action := "supportExtendedCodeAction"?: bool); assign_config!(development := "development"?: bool); assign_config!(system_fonts := "systemFonts"?: Option); @@ -1203,6 +1206,7 @@ mod tests { test_good_config("semanticTokens"); test_good_config("delegateFsRequests"); test_good_config("supportHtmlInMarkdown"); + test_good_config("supportClientCodelens"); test_good_config("supportExtendedCodeAction"); test_good_config("development"); test_good_config("systemFonts"); diff --git a/crates/tinymist/src/project.rs b/crates/tinymist/src/project.rs index a3001a2f..24f030f5 100644 --- a/crates/tinymist/src/project.rs +++ b/crates/tinymist/src/project.rs @@ -174,7 +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, + support_client_codelens: config.support_client_codelens, 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.shared.ts b/editors/vscode/src/extension.shared.ts index 6c389676..1d0e2989 100644 --- a/editors/vscode/src/extension.shared.ts +++ b/editors/vscode/src/extension.shared.ts @@ -40,6 +40,7 @@ function configureEditorAndLanguage(context: ExtensionContext, trait: TinymistTr config.triggerSuggestAndParameterHints = true; config.triggerParameterHints = true; config.supportHtmlInMarkdown = true; + config.supportClientCodelens = true; config.supportExtendedCodeAction = true; config.customizedShowDocument = true; config.delegateFsRequests = false; // todo: detect live sharing. diff --git a/tests/fixtures/initialization/vscode-1.87.2.json b/tests/fixtures/initialization/vscode-1.87.2.json index 107b4574..03465915 100644 --- a/tests/fixtures/initialization/vscode-1.87.2.json +++ b/tests/fixtures/initialization/vscode-1.87.2.json @@ -276,6 +276,7 @@ "triggerParameterHints": true, "triggerSuggestAndParameterHints": true, "supportHtmlInMarkdown": true, + "supportClientCodelens": true, "supportExtendedCodeAction": true, "customizedShowDocument": true, "experimentalFormatterMode": "disable"