mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
ra_ide: remove dead code in HoverResult
This commit is contained in:
parent
bf0c3ec67e
commit
4fd07a02a2
1 changed files with 5 additions and 41 deletions
|
@ -1,4 +1,5 @@
|
||||||
//! FIXME: write short doc here
|
//! Logic for computing info that is displayed when the user hovers over any
|
||||||
|
//! source code items (e.g. function call, struct field, variable symbol...)
|
||||||
|
|
||||||
use hir::{
|
use hir::{
|
||||||
Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef,
|
Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef,
|
||||||
|
@ -24,35 +25,20 @@ use itertools::Itertools;
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
|
|
||||||
/// Contains the results when hovering over an item
|
/// Contains the results when hovering over an item
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Default)]
|
||||||
pub struct HoverResult {
|
pub struct HoverResult {
|
||||||
results: Vec<String>,
|
results: Vec<String>,
|
||||||
exact: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for HoverResult {
|
|
||||||
fn default() -> Self {
|
|
||||||
HoverResult::new()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HoverResult {
|
impl HoverResult {
|
||||||
pub fn new() -> HoverResult {
|
pub fn new() -> HoverResult {
|
||||||
HoverResult {
|
Self::default()
|
||||||
results: Vec::new(),
|
|
||||||
// We assume exact by default
|
|
||||||
exact: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend(&mut self, item: Option<String>) {
|
pub fn extend(&mut self, item: Option<String>) {
|
||||||
self.results.extend(item);
|
self.results.extend(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_exact(&self) -> bool {
|
|
||||||
self.exact
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.results.is_empty()
|
self.results.is_empty()
|
||||||
}
|
}
|
||||||
|
@ -72,20 +58,7 @@ impl HoverResult {
|
||||||
/// Returns the results converted into markup
|
/// Returns the results converted into markup
|
||||||
/// for displaying in a UI
|
/// for displaying in a UI
|
||||||
pub fn to_markup(&self) -> String {
|
pub fn to_markup(&self) -> String {
|
||||||
let mut markup = if !self.exact {
|
self.results.join("\n\n---\n")
|
||||||
let mut msg = String::from("Failed to exactly resolve the symbol. This is probably because rust_analyzer does not yet support traits.");
|
|
||||||
if !self.results.is_empty() {
|
|
||||||
msg.push_str(" \nThese items were found instead:");
|
|
||||||
}
|
|
||||||
msg.push_str("\n\n---\n");
|
|
||||||
msg
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
markup.push_str(&self.results.join("\n\n---\n"));
|
|
||||||
|
|
||||||
markup
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,7 +568,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("wrapper::Thing\nfn new() -> Thing"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("wrapper::Thing\nfn new() -> Thing"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -618,7 +590,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("const C: u32"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("const C: u32"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -635,7 +606,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
|
|
||||||
/* FIXME: revive these tests
|
/* FIXME: revive these tests
|
||||||
let (analysis, position) = single_file_with_position(
|
let (analysis, position) = single_file_with_position(
|
||||||
|
@ -651,7 +621,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
|
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
|
|
||||||
let (analysis, position) = single_file_with_position(
|
let (analysis, position) = single_file_with_position(
|
||||||
"
|
"
|
||||||
|
@ -665,7 +634,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
|
|
||||||
let (analysis, position) = single_file_with_position(
|
let (analysis, position) = single_file_with_position(
|
||||||
"
|
"
|
||||||
|
@ -678,7 +646,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +663,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -714,7 +680,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -726,7 +691,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
);
|
);
|
||||||
let hover = analysis.hover(position).unwrap().unwrap();
|
let hover = analysis.hover(position).unwrap().unwrap();
|
||||||
assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
|
assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
|
||||||
assert_eq!(hover.info.is_exact(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue