mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-23 20:56:42 +00:00
fix: correct hover docs generated by typlite (#1761)
* fix: annotate fn * fix(typlite): duplicate docs description (#1799) * fix: avoid duplicate docs description * fix: clippy error * test: flat repr of hover snapshots * g * test: update snapshots --------- Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com> * test: update snapshot --------- Co-authored-by: Hong Jiarong <me@jrhim.com>
This commit is contained in:
parent
ae99016cd9
commit
3d24320674
42 changed files with 1386 additions and 217 deletions
|
|
@ -242,7 +242,7 @@ fn match_by_pos(mut n: LinkedNode, prev: bool, ident: bool) -> usize {
|
|||
.find(|n| matches!(n.kind(), SyntaxKind::Ident))
|
||||
.unwrap();
|
||||
} else {
|
||||
n = n.children().last().unwrap();
|
||||
n = n.children().next_back().unwrap();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -331,6 +331,25 @@ impl JsonRepr {
|
|||
let s = serde_json::to_value(v).unwrap();
|
||||
Self(rm.redact(s))
|
||||
}
|
||||
|
||||
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());
|
||||
let v = REG.replace_all(v, |_captures: ®ex::Captures| {
|
||||
"data:image-hash/svg+xml;base64,redacted"
|
||||
});
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
pub fn range(v: impl serde::Serialize) -> String {
|
||||
let t = serde_json::to_value(v).unwrap();
|
||||
Self::range_(&t)
|
||||
}
|
||||
|
||||
pub fn range_(t: &Value) -> String {
|
||||
format!("{}:{}", pos(&t["start"]), pos(&t["end"]))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for JsonRepr {
|
||||
|
|
@ -370,8 +389,6 @@ fn pos(v: &Value) -> String {
|
|||
|
||||
impl Redact for RedactFields {
|
||||
fn redact(&self, json_val: Value) -> Value {
|
||||
static REG: LazyLock<regex::Regex> =
|
||||
LazyLock::new(|| regex::Regex::new(r#"data:image/svg\+xml;base64,([^"]+)"#).unwrap());
|
||||
match json_val {
|
||||
Value::Object(mut map) => {
|
||||
for (_, val) in map.iter_mut() {
|
||||
|
|
@ -400,18 +417,11 @@ impl Redact for RedactFields {
|
|||
| "originSelectionRange"
|
||||
| "targetRange"
|
||||
| "targetSelectionRange" => {
|
||||
map.insert(
|
||||
key.to_owned(),
|
||||
format!("{}:{}", pos(&t["start"]), pos(&t["end"])).into(),
|
||||
);
|
||||
map.insert(key.to_owned(), JsonRepr::range_(&t).into());
|
||||
}
|
||||
"contents" => {
|
||||
let res = t.as_str().unwrap();
|
||||
let res = REG.replace_all(res, |_captures: ®ex::Captures| {
|
||||
"data:image-hash/svg+xml;base64,redacted"
|
||||
});
|
||||
|
||||
map.insert(key.to_owned(), res.into());
|
||||
map.insert(key.to_owned(), JsonRepr::md_content(res).into());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -442,8 +452,8 @@ pub(crate) fn file_path_(uri: &lsp_types::Url) -> String {
|
|||
};
|
||||
let uri = uri.to_file_path().unwrap();
|
||||
let abs_path = Path::new(&uri).strip_prefix(root).map(|p| p.to_owned());
|
||||
let rel_path =
|
||||
abs_path.unwrap_or_else(|_| Path::new("-").join(Path::new(&uri).iter().last().unwrap()));
|
||||
let rel_path = abs_path
|
||||
.unwrap_or_else(|_| Path::new("-").join(Path::new(&uri).iter().next_back().unwrap()));
|
||||
|
||||
unix_slash(&rel_path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue