From 86aac4303f26281f72fbbacc0aaa8969a13ce7eb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Jul 2020 19:41:57 +0200 Subject: Reduce visibility --- crates/ra_ide/src/hover.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index eaba2b61e..0e9aa44de 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -77,10 +77,6 @@ impl HoverResult { Self::default() } - pub fn extend(&mut self, item: Option) { - self.results.extend(item); - } - pub fn is_empty(&self) -> bool { self.results.is_empty() } @@ -100,11 +96,6 @@ impl HoverResult { pub fn actions(&self) -> &[HoverAction] { &self.actions } - - pub fn push_action(&mut self, action: HoverAction) { - self.actions.push(action); - } - /// Returns the results converted into markup /// for displaying in a UI /// @@ -112,6 +103,13 @@ impl HoverResult { pub fn to_markup(&self) -> String { self.results.join("\n\n___\n") } + + fn extend(&mut self, item: Option) { + self.results.extend(item); + } + fn push_action(&mut self, action: HoverAction) { + self.actions.push(action); + } } // Feature: Hover -- cgit v1.2.3 From 7238acab787328e5c1bf9beada140173f34efae0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Jul 2020 19:54:50 +0200 Subject: Dead code --- crates/ra_ide/src/hover.rs | 50 ++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 0e9aa44de..96b564a96 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -85,14 +85,6 @@ impl HoverResult { self.results.len() } - pub fn first(&self) -> Option<&str> { - self.results.first().map(String::as_str) - } - - pub fn results(&self) -> &[String] { - &self.results - } - pub fn actions(&self) -> &[HoverAction] { &self.actions } @@ -403,10 +395,6 @@ mod tests { s.trim_start_matches("```rust\n").trim_end_matches("\n```") } - fn trim_markup_opt(s: Option<&str>) -> Option<&str> { - s.map(trim_markup) - } - fn assert_impl_action(action: &HoverAction, position: u32) { let offset = match action { HoverAction::Implementaion(pos) => pos.offset, @@ -418,7 +406,7 @@ mod tests { fn check_hover_result(ra_fixture: &str, expected: &[&str]) -> (String, Vec) { let (analysis, position) = analysis_and_position(ra_fixture); let hover = analysis.hover(position).unwrap().unwrap(); - let mut results = Vec::from(hover.info.results()); + let mut results = hover.info.results.clone(); results.sort(); for (markup, expected) in @@ -451,7 +439,7 @@ fn main() { ); let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(hover.range, TextRange::new(58.into(), 63.into())); - assert_eq!(trim_markup_opt(hover.info.first()), Some("u32")); + assert_eq!(trim_markup(&hover.info.results[0]), ("u32")); } #[test] @@ -650,7 +638,7 @@ fn main() { ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("Option\n```\n\n```rust\nSome")); + assert_eq!(trim_markup(&hover.info.results[0]), ("Option\n```\n\n```rust\nSome")); let (analysis, position) = analysis_and_position( " @@ -663,7 +651,7 @@ fn main() { ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("Option")); + assert_eq!(trim_markup(&hover.info.results[0]), ("Option")); } #[test] @@ -720,14 +708,14 @@ The Some variant fn hover_for_local_variable() { let (analysis, position) = analysis_and_position("fn func(foo: i32) { fo<|>o; }"); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(trim_markup(&hover.info.results[0]), "i32"); } #[test] fn hover_for_local_variable_pat() { let (analysis, position) = analysis_and_position("fn func(fo<|>o: i32) {}"); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(trim_markup(&hover.info.results[0]), "i32"); } #[test] @@ -738,14 +726,14 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(trim_markup(&hover.info.results[0]), "i32"); } #[test] fn hover_for_param_edge() { let (analysis, position) = analysis_and_position("fn func(<|>foo: i32) {}"); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(trim_markup(&hover.info.results[0]), "i32"); } #[test] @@ -766,7 +754,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); + assert_eq!(trim_markup(&hover.info.results[0]), ("Thing")); } #[test] @@ -790,8 +778,8 @@ fn func(foo: i32) { if true { <|>foo; }; } ); let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!( - trim_markup_opt(hover.info.first()), - Some("wrapper::Thing\n```\n\n```rust\nfn new() -> Thing") + trim_markup(&hover.info.results[0]), + ("wrapper::Thing\n```\n\n```rust\nfn new() -> Thing") ); } @@ -814,7 +802,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("const C: u32")); + assert_eq!(trim_markup(&hover.info.results[0]), ("const C: u32")); } #[test] @@ -830,7 +818,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); + assert_eq!(trim_markup(&hover.info.results[0]), ("Thing")); /* FIXME: revive these tests let (analysis, position) = analysis_and_position( @@ -845,7 +833,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); + assert_eq!(trim_markup(&hover.info.results[0]), ("Thing")); let (analysis, position) = analysis_and_position( " @@ -858,7 +846,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); + assert_eq!(trim_markup(&hover.info.results[0]), ("enum Thing")); let (analysis, position) = analysis_and_position( " @@ -870,7 +858,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); + assert_eq!(trim_markup(&hover.info.results[0]), ("enum Thing")); */ } @@ -887,7 +875,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(trim_markup(&hover.info.results[0]), "i32"); } #[test] @@ -904,7 +892,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo")); + assert_eq!(trim_markup(&hover.info.results[0]), ("macro_rules! foo")); } #[test] @@ -915,7 +903,7 @@ fn func(foo: i32) { if true { <|>foo; }; } ", ); let hover = analysis.hover(position).unwrap().unwrap(); - assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(trim_markup(&hover.info.results[0]), "i32"); } #[test] -- cgit v1.2.3 From d74a77efb19c5f3c45a09bd8ccd5b50d453927d1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Jul 2020 19:58:50 +0200 Subject: Minimize API --- crates/ra_ide/src/hover.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 96b564a96..98be22339 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -96,9 +96,6 @@ impl HoverResult { self.results.join("\n\n___\n") } - fn extend(&mut self, item: Option) { - self.results.extend(item); - } fn push_action(&mut self, action: HoverAction) { self.actions.push(action); } @@ -128,8 +125,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option Option Date: Wed, 8 Jul 2020 20:26:20 +0200 Subject: simplify --- crates/ra_ide/src/hover.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 98be22339..61359c770 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -113,31 +113,33 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - classify_name_ref(&sema, &name_ref).map(|d| (name_ref.syntax().clone(), d.definition())) + classify_name_ref(&sema, &name_ref).map(|d| d.definition()) }, ast::Name(name) => { - classify_name(&sema, &name).map(|d| (name.syntax().clone(), d.definition())) + classify_name(&sema, &name).map(|d| d.definition()) }, _ => None, } - } { + }; + if let Some(definition) = definition { let range = sema.original_range(&node).range; - if let Some(text) = hover_text_from_name_kind(db, name_kind) { + if let Some(text) = hover_text_from_name_kind(db, definition) { res.results.push(text); } if !res.is_empty() { - if let Some(action) = show_implementations_action(db, name_kind) { + if let Some(action) = show_implementations_action(db, definition) { res.push_action(action); } - if let Some(action) = runnable_action(&sema, name_kind, position.file_id) { + if let Some(action) = runnable_action(&sema, definition, position.file_id) { res.push_action(action); } - if let Some(action) = goto_type_action(db, name_kind) { + if let Some(action) = goto_type_action(db, definition) { res.push_action(action); } -- cgit v1.2.3