mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Hover doc link rewriting
This commit is contained in:
parent
2bd7171399
commit
2023af53f0
7 changed files with 383 additions and 18 deletions
15
crates/ra_syntax/src/ast/test.txt
Normal file
15
crates/ra_syntax/src/ast/test.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
The context is a general utility struct provided on event dispatches, which
|
||||
helps with dealing with the current "context" of the event dispatch.
|
||||
The context also acts as a general high-level interface over the associated
|
||||
[`Shard`] which received the event, or the low-level [`http`] module.
|
||||
|
||||
The context contains "shortcuts", like for interacting with the shard.
|
||||
Methods like [`set_activity`] will unlock the shard and perform an update for
|
||||
you to save a bit of work.
|
||||
|
||||
A context will only live for the event it was dispatched for. After the
|
||||
event handler finished, it is destroyed and will not be re-used.
|
||||
|
||||
[`Shard`]: ../gateway/struct.Shard.html
|
||||
[`http`]: ../http/index.html
|
||||
[`set_activity`]: #method.set_activity
|
|
@ -146,3 +146,39 @@ impl Iterator for CommentIter {
|
|||
self.iter.by_ref().find_map(|el| el.into_token().and_then(ast::Comment::cast))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use comrak::{parse_document,format_commonmark, ComrakOptions, Arena};
|
||||
use comrak::nodes::{AstNode, NodeValue};
|
||||
|
||||
fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F)
|
||||
where F : Fn(&'a AstNode<'a>) {
|
||||
f(node);
|
||||
for c in node.children() {
|
||||
iter_nodes(c, f);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[test]
|
||||
fn test_link_rewrite() {
|
||||
let src = include_str!("./test.txt");
|
||||
|
||||
let arena = Arena::new();
|
||||
let doc = parse_document(&arena, src, &ComrakOptions::default());
|
||||
|
||||
iter_nodes(doc, &|node| {
|
||||
match &mut node.data.borrow_mut().value {
|
||||
&mut NodeValue::Link(ref mut link) => {
|
||||
link.url = "https://www.google.com".as_bytes().to_vec();
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
});
|
||||
|
||||
let mut out = Vec::new();
|
||||
format_commonmark(doc, &ComrakOptions::default(), &mut out);
|
||||
panic!("{}", String::from_utf8(out).unwrap());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue