diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-08 23:11:52 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-08 23:11:52 +0100 |
commit | a61c8481571f8d8e6e08df9024d8dad5efc883de (patch) | |
tree | 0b873401a6c76260c30f34a4de583294aa9cdcc6 /crates/ra_ide/src/markup.rs | |
parent | 39182dbc733aa85f210f880fe364ea7d7ec47181 (diff) | |
parent | abbb539f973ee4558f6ea7922794887962128987 (diff) |
Merge #5273
5273: Refactor hover tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/markup.rs')
-rw-r--r-- | crates/ra_ide/src/markup.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/crates/ra_ide/src/markup.rs b/crates/ra_ide/src/markup.rs new file mode 100644 index 000000000..2f2b3cc25 --- /dev/null +++ b/crates/ra_ide/src/markup.rs | |||
@@ -0,0 +1,38 @@ | |||
1 | //! Markdown formatting. | ||
2 | //! | ||
3 | //! Sometimes, we want to display a "rich text" in the UI. At the moment, we use | ||
4 | //! markdown for this purpose. It doesn't feel like a right option, but that's | ||
5 | //! what is used by LSP, so let's keep it simple. | ||
6 | use std::fmt; | ||
7 | |||
8 | #[derive(Default, Debug)] | ||
9 | pub struct Markup { | ||
10 | text: String, | ||
11 | } | ||
12 | |||
13 | impl From<Markup> for String { | ||
14 | fn from(markup: Markup) -> Self { | ||
15 | markup.text | ||
16 | } | ||
17 | } | ||
18 | |||
19 | impl fmt::Display for Markup { | ||
20 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
21 | fmt::Display::fmt(&self.text, f) | ||
22 | } | ||
23 | } | ||
24 | |||
25 | impl Markup { | ||
26 | pub fn as_str(&self) -> &str { | ||
27 | self.text.as_str() | ||
28 | } | ||
29 | pub fn is_empty(&self) -> bool { | ||
30 | self.text.is_empty() | ||
31 | } | ||
32 | pub fn push_section(&mut self, section: &str) { | ||
33 | if !self.text.is_empty() { | ||
34 | self.text.push_str("\n\n___\n"); | ||
35 | } | ||
36 | self.text.push_str(section); | ||
37 | } | ||
38 | } | ||