mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-23 12:45:04 +00:00
fix: dedent documentation correctly (#132)
This commit is contained in:
parent
c32e6e3097
commit
b76e80bad3
3 changed files with 36 additions and 2 deletions
11
crates/tinymist-query/src/fixtures/docs/raw.typ
Normal file
11
crates/tinymist-query/src/fixtures/docs/raw.typ
Normal file
|
@ -0,0 +1,11 @@
|
|||
/// Docs for f.
|
||||
///
|
||||
/// ```typst
|
||||
/// #show raw: it => it {
|
||||
/// it
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
#let /* ident after */ f(a) = {
|
||||
show it: it => it;
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/analysis.rs
|
||||
expression: result
|
||||
input_file: crates/tinymist-query/src/fixtures/docs/raw.typ
|
||||
---
|
||||
Docs for f.
|
||||
|
||||
```typst
|
||||
#show raw: it => it {
|
||||
it
|
||||
}
|
||||
```
|
|
@ -38,7 +38,7 @@ fn extract_document_between(node: &LinkedNode, rng: Range<usize>) -> Option<Stri
|
|||
// comments.push(n.text().strip_prefix("//")?.trim().to_owned());
|
||||
// strip all slash prefix
|
||||
let text = n.text().trim_start_matches('/');
|
||||
comments.push(text.trim().to_owned());
|
||||
comments.push(text.to_owned());
|
||||
continue;
|
||||
}
|
||||
SyntaxKind::BlockComment => {
|
||||
|
@ -61,7 +61,18 @@ fn extract_document_between(node: &LinkedNode, rng: Range<usize>) -> Option<Stri
|
|||
return None;
|
||||
}
|
||||
|
||||
Some(comments.join("\n"))
|
||||
let dedent = comments.iter().fold(usize::MAX, |acc, c| {
|
||||
let indent = c.chars().take_while(|c| c.is_whitespace()).count();
|
||||
acc.min(indent)
|
||||
});
|
||||
|
||||
let docs = comments
|
||||
.iter()
|
||||
.map(|c| c.chars().skip(dedent).collect::<String>())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
Some(docs)
|
||||
}
|
||||
|
||||
pub fn find_document_before(src: &Source, cursor: usize) -> Option<String> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue