feat: pretty errors in docstrings (#1876)
Some checks are pending
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Blocked by required conditions
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-2022) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Blocked by required conditions
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / build-binary (push) Blocked by required conditions
tinymist::ci / build-vsc-assets (push) Blocked by required conditions
tinymist::ci / build-vscode (push) Blocked by required conditions
tinymist::ci / build-vscode-others (push) Blocked by required conditions
tinymist::ci / publish-vscode (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run

* feat: print doc errors

* fix: test errors on windows

* fix: tests on windows again

* fix: tests on windows again 2

* Revert "fix: tests on windows again 2"

This reverts commit 63973dcc1f.

* fix: tests on windows again 3
This commit is contained in:
Myriad-Dreamin 2025-07-06 19:40:02 +08:00 committed by GitHub
parent 9787432029
commit 4426b31ed7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 488 additions and 132 deletions

View file

@ -8,6 +8,7 @@ use std::{
path::{Path, PathBuf},
};
use regex::{Regex, Replacer};
use serde_json::{ser::PrettyFormatter, Serializer, Value};
use tinymist_project::{LspCompileSnapshot, LspComputeGraph};
use tinymist_std::path::unix_slash;
@ -333,13 +334,14 @@ impl JsonRepr {
}
pub fn md_content(v: &str) -> Cow<'_, str> {
static REG: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r#"data:image/svg\+xml;base64,([^"]+)"#).unwrap());
static REG: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"data:image/svg\+xml;base64,([^"]+)"#).unwrap());
static REG2: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"C:\\?\\dummy-root\\?\\"#).unwrap());
let v = REG.replace_all(v, |_captures: &regex::Captures| {
"data:image-hash/svg+xml;base64,redacted"
});
v
REG2.replace_all_cow(v, "/dummy-root/")
}
pub fn range(v: impl serde::Serialize) -> String {
@ -360,8 +362,7 @@ impl fmt::Display for JsonRepr {
let res = String::from_utf8(ser.into_inner().into_inner().unwrap()).unwrap();
// replace Span(number) to Span(..)
static REG: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r#"Span\((\d+)\)"#).unwrap());
static REG: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"Span\((\d+)\)"#).unwrap());
let res = REG.replace_all(&res, "Span(..)");
f.write_str(&res)
}
@ -470,3 +471,18 @@ impl fmt::Display for HashRepr<JsonRepr> {
write!(f, "sha256:{}", hex::encode(hash))
}
}
/// Extension methods for `Regex` that operate on `Cow<str>` instead of `&str`.
pub trait RegexCowExt {
/// [`Regex::replace_all`], but taking text as `Cow<str>` instead of `&str`.
fn replace_all_cow<'t, R: Replacer>(&self, text: Cow<'t, str>, rep: R) -> Cow<'t, str>;
}
impl RegexCowExt for Regex {
fn replace_all_cow<'t, R: Replacer>(&self, text: Cow<'t, str>, rep: R) -> Cow<'t, str> {
match self.replace_all(&text, rep) {
Cow::Owned(result) => Cow::Owned(result),
Cow::Borrowed(_) => text,
}
}
}