Reduce API

This commit is contained in:
Aleksey Kladov 2020-07-09 10:03:28 +02:00
parent 22269c67b8
commit 3a26752c66
2 changed files with 8 additions and 13 deletions

View file

@ -93,9 +93,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
};
if let Some(definition) = definition {
if let Some(text) = hover_for_definition(db, definition) {
res.markup.push_section(&text);
}
if !res.markup.is_empty() {
res.markup = text.into();
if let Some(action) = show_implementations_action(db, definition) {
res.actions.push(action);
}
@ -128,7 +126,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
}
};
res.markup.push_section(&rust_code_markup(&ty.display(db)));
res.markup = rust_code_markup(&ty.display(db)).into();
let range = sema.original_range(&node).range;
Some(RangeInfo::new(range, res))
}

View file

@ -16,6 +16,12 @@ impl From<Markup> for String {
}
}
impl From<String> for Markup {
fn from(text: String) -> Self {
Markup { text }
}
}
impl fmt::Display for Markup {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.text, f)
@ -26,13 +32,4 @@ impl Markup {
pub fn as_str(&self) -> &str {
self.text.as_str()
}
pub fn is_empty(&self) -> bool {
self.text.is_empty()
}
pub fn push_section(&mut self, section: &str) {
if !self.text.is_empty() {
self.text.push_str("\n\n___\n");
}
self.text.push_str(section);
}
}