diff --git a/crates/tinymist-analysis/src/docs.rs b/crates/tinymist-analysis/src/docs.rs index 0fb48253..c814504e 100644 --- a/crates/tinymist-analysis/src/docs.rs +++ b/crates/tinymist-analysis/src/docs.rs @@ -2,5 +2,5 @@ mod def; pub use def::*; -mod tidy; +pub mod tidy; pub use tidy::*; diff --git a/crates/tinymist-analysis/src/docs/tidy.rs b/crates/tinymist-analysis/src/docs/tidy.rs index 6058c656..957ef4bb 100644 --- a/crates/tinymist-analysis/src/docs/tidy.rs +++ b/crates/tinymist-analysis/src/docs/tidy.rs @@ -23,6 +23,13 @@ pub struct TidyModuleDocs { pub docs: EcoString, } +pub fn remove_list_annotations(s: &str) -> String { + static REG: std::sync::LazyLock = std::sync::LazyLock::new(|| { + regex::Regex::new(r"").unwrap() + }); + REG.replace_all(s, "").to_string() +} + pub fn identify_pat_docs(converted: &str) -> StrResult { let lines = converted.lines().collect::>(); @@ -120,7 +127,7 @@ pub fn identify_pat_docs(converted: &str) -> StrResult { name: param_line.0, types: param_line.1, default: None, - docs: buf.into_iter().join("\n").into(), + docs: remove_list_annotations(&buf.into_iter().join("\n")).into(), }); break_line = Some(line_width); @@ -129,8 +136,10 @@ pub fn identify_pat_docs(converted: &str) -> StrResult { } let docs = match break_line { - Some(line_no) => (lines[..line_no]).iter().copied().join("\n").into(), - None => converted.into(), + Some(line_no) => { + remove_list_annotations(&(lines[..line_no]).iter().copied().join("\n")).into() + } + None => remove_list_annotations(converted).into(), }; params.reverse(); @@ -142,7 +151,9 @@ pub fn identify_pat_docs(converted: &str) -> StrResult { } pub fn identify_tidy_module_docs(docs: EcoString) -> StrResult { - Ok(TidyModuleDocs { docs }) + Ok(TidyModuleDocs { + docs: remove_list_annotations(&docs).into(), + }) } fn match_brace(trim_start: &str) -> Option<(&str, &str)> { @@ -224,9 +235,9 @@ See show-module() for outputting the results of this function. -> string"###), @r" >> docs: These again are dictionaries with the keys - - `description` (optional): The description for the argument. - - `types` (optional): A list of accepted argument types. - - `default` (optional): Default value for this argument. + - `description` (optional): The description for the argument. + - `types` (optional): A list of accepted argument types. + - `default` (optional): Default value for this argument. See show-module() for outputting the results of this function. << docs @@ -273,7 +284,7 @@ See show-module() for outputting the results of this function. -> string"###), @r" >> docs: These again are dictionaries with the keys - - `description` (optional): The description for the argument. + - `description` (optional): The description for the argument. See show-module() for outputting the results of this function. << docs @@ -286,8 +297,8 @@ See show-module() for outputting the results of this function. >>arg label-prefix: auto, string The label-prefix for internal function references. If `auto`, the label-prefix name will be the module name. - - nested something - - nested something 2 + - nested something + - nested something 2 << arg "); } diff --git a/crates/tinymist-query/src/docs/package.rs b/crates/tinymist-query/src/docs/package.rs index 702a6aaa..d5b710fb 100644 --- a/crates/tinymist-query/src/docs/package.rs +++ b/crates/tinymist-query/src/docs/package.rs @@ -13,6 +13,8 @@ use crate::docs::{file_id_repr, module_docs, DefDocs, PackageDefInfo}; use crate::package::{get_manifest_id, PackageInfo}; use crate::LocalContext; +use tinymist_analysis::docs::tidy::remove_list_annotations; + /// Generate full documents in markdown format pub fn package_docs(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult { log::info!("generate_md_docs {spec:?}"); @@ -338,14 +340,6 @@ struct ConvertResult { errors: Vec, } -fn remove_list_annotations(s: &str) -> String { - let s = s.to_string(); - static REG: std::sync::LazyLock = std::sync::LazyLock::new(|| { - regex::Regex::new(r"").unwrap() - }); - REG.replace_all(&s, "").to_string() -} - #[cfg(test)] mod tests { use tinymist_world::package::{PackageRegistry, PackageSpec}; diff --git a/crates/tinymist-query/src/fixtures/hover/snaps/test@render_equation.typ.snap b/crates/tinymist-query/src/fixtures/hover/snaps/test@render_equation.typ.snap index 2bc1cc65..35932fb4 100644 --- a/crates/tinymist-query/src/fixtures/hover/snaps/test@render_equation.typ.snap +++ b/crates/tinymist-query/src/fixtures/hover/snaps/test@render_equation.typ.snap @@ -2,6 +2,7 @@ source: crates/tinymist-query/src/hover.rs expression: content input_file: crates/tinymist-query/src/fixtures/hover/render_equation.typ +snapshot_kind: text --- Range: 12:20:12:23 @@ -31,7 +32,7 @@ type: type ``` The type of the argument. - - It can be also regarded as the condition of the proposition. + - It can be also regarded as the condition of the proposition. ## B (positional) @@ -40,4 +41,4 @@ type: type ``` The type of the body. - - It can be also regarded as the conclusion of the proposition. + - It can be also regarded as the conclusion of the proposition.