From 2023af53f09ed9466c6d7442d6830276eba19b45 Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Tue, 9 Jun 2020 15:43:57 +1200 Subject: Hover doc link rewriting --- crates/ra_syntax/src/ast/test.txt | 15 +++++++++++++++ crates/ra_syntax/src/ast/traits.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 crates/ra_syntax/src/ast/test.txt (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/test.txt b/crates/ra_syntax/src/ast/test.txt new file mode 100644 index 000000000..f746bf1e7 --- /dev/null +++ b/crates/ra_syntax/src/ast/test.txt @@ -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 diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index a8f2454fd..323d78bbc 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -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()); + } +} -- cgit v1.2.3