From 0bf02f5ccac99c91f10ef46bb06ff2ea316c382c Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 5 May 2020 14:29:07 +0200 Subject: do not truncate display for hover #4311 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/hover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 54d318858..df8451af2 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -208,7 +208,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option Date: Wed, 6 May 2020 11:08:50 +0200 Subject: do not truncate display for hover Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/hover.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index df8451af2..d52f22157 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -143,7 +143,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option from_def_source(db, it, mod_path), ModuleDef::BuiltinType(it) => Some(it.to_string()), }, - Definition::Local(it) => Some(rust_code_markup(&it.ty(db).display_truncated(db, None))), + Definition::Local(it) => Some(rust_code_markup(&it.ty(db).display(db))), Definition::TypeParam(_) | Definition::SelfType(_) => { // FIXME: Hover for generic param None @@ -279,6 +279,47 @@ mod tests { assert_eq!(trim_markup_opt(hover.info.first()), Some("u32")); } + #[test] + fn hover_shows_long_type_of_an_expression() { + check_hover_result( + r#" + //- /main.rs + struct Scan { + a: A, + b: B, + c: C, + } + + struct FakeIter { + inner: I, + } + + struct OtherStruct { + i: T, + } + + enum FakeOption { + Some(T), + None, + } + + fn scan(a: A, b: B, c: C) -> FakeIter, B, C>> { + FakeIter { inner: Scan { a, b, c } } + } + + fn main() { + let num: i32 = 55; + let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> FakeOption { + FakeOption::Some(*memo + value) + }; + let number = 5u32; + let mut iter<|> = scan(OtherStruct { i: num }, closure, number); + } + "#, + &["FakeIter>, |&mut u32, &u32, &mut u32| -> FakeOption, u32>>"], + ); + } + #[test] fn hover_shows_fn_signature() { // Single file with result -- cgit v1.2.3 From 1ec953f11744c708ba74c238737eac8e96a1c7b1 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Wed, 6 May 2020 11:33:43 +0200 Subject: do not truncate display for hover Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/ra_ide/src/hover.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index d52f22157..06d4f1c63 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -446,7 +446,7 @@ mod tests { } #[test] - fn hover_omits_default_generic_types() { + fn hover_default_generic_types() { check_hover_result( r#" //- /main.rs @@ -458,7 +458,7 @@ struct Test { fn main() { let zz<|> = Test { t: 23, k: 33 }; }"#, - &["Test"], + &["Test"], ); } -- cgit v1.2.3 From fdd4df97ba5ce1f59abf9e945052fc6f3e077c3a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 15:26:40 +0200 Subject: Use SourceChange for assists --- crates/ra_ide/src/assists.rs | 42 ------------------------------------------ crates/ra_ide/src/lib.rs | 31 ++++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 49 deletions(-) delete mode 100644 crates/ra_ide/src/assists.rs (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs deleted file mode 100644 index 389339a03..000000000 --- a/crates/ra_ide/src/assists.rs +++ /dev/null @@ -1,42 +0,0 @@ -//! FIXME: write short doc here - -use ra_assists::{resolved_assists, AssistAction}; -use ra_db::{FilePosition, FileRange}; -use ra_ide_db::RootDatabase; - -use crate::{FileId, SourceChange, SourceFileEdit}; - -pub use ra_assists::AssistId; - -#[derive(Debug)] -pub struct Assist { - pub id: AssistId, - pub label: String, - pub group_label: Option, - pub source_change: SourceChange, -} - -pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec { - resolved_assists(db, frange) - .into_iter() - .map(|assist| { - let file_id = frange.file_id; - Assist { - id: assist.label.id, - label: assist.label.label.clone(), - group_label: assist.label.group.map(|it| it.0), - source_change: action_to_edit(assist.action, file_id, assist.label.label.clone()), - } - }) - .collect() -} - -fn action_to_edit(action: AssistAction, file_id: FileId, label: String) -> SourceChange { - let file_id = match action.file { - ra_assists::AssistFile::TargetFile(it) => it, - _ => file_id, - }; - let file_edit = SourceFileEdit { file_id, edit: action.edit }; - SourceChange::source_file_edit(label, file_edit) - .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) -} diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 4ed02f60e..614029de4 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -31,7 +31,6 @@ mod syntax_highlighting; mod parent_module; mod references; mod impls; -mod assists; mod diagnostics; mod syntax_tree; mod folding_ranges; @@ -64,7 +63,6 @@ use ra_syntax::{SourceFile, TextRange, TextSize}; use crate::display::ToNav; pub use crate::{ - assists::{Assist, AssistId}, call_hierarchy::CallItem, completion::{ CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, @@ -84,6 +82,7 @@ pub use crate::{ }; pub use hir::Documentation; +pub use ra_assists::AssistId; pub use ra_db::{ Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, }; @@ -134,10 +133,12 @@ pub struct AnalysisHost { db: RootDatabase, } -impl Default for AnalysisHost { - fn default() -> AnalysisHost { - AnalysisHost::new(None) - } +#[derive(Debug)] +pub struct Assist { + pub id: AssistId, + pub label: String, + pub group_label: Option, + pub source_change: SourceChange, } impl AnalysisHost { @@ -187,6 +188,12 @@ impl AnalysisHost { } } +impl Default for AnalysisHost { + fn default() -> AnalysisHost { + AnalysisHost::new(None) + } +} + /// Analysis is a snapshot of a world state at a moment in time. It is the main /// entry point for asking semantic information about the world. When the world /// state is advanced using `AnalysisHost::apply_change` method, all existing @@ -464,7 +471,17 @@ impl Analysis { /// Computes assists (aka code actions aka intentions) for the given /// position. pub fn assists(&self, frange: FileRange) -> Cancelable> { - self.with_db(|db| assists::assists(db, frange)) + self.with_db(|db| { + ra_assists::resolved_assists(db, frange) + .into_iter() + .map(|assist| Assist { + id: assist.label.id, + label: assist.label.label, + group_label: assist.label.group.map(|it| it.0), + source_change: assist.action, + }) + .collect() + }) } /// Computes the set of diagnostics for the given file. -- cgit v1.2.3 From 0970c3454baa0164df81a9ff665430d486687331 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 16:01:47 +0200 Subject: Rename --- crates/ra_ide/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 614029de4..737f87109 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -478,7 +478,7 @@ impl Analysis { id: assist.label.id, label: assist.label.label, group_label: assist.label.group.map(|it| it.0), - source_change: assist.action, + source_change: assist.source_change, }) .collect() }) -- cgit v1.2.3 From 4d50709a96f92f3927b3ac59110d593b49c53008 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 16:05:43 +0200 Subject: Minor --- crates/ra_ide/src/completion/completion_item.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs index 383b23ac4..6021f7279 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs @@ -2,11 +2,12 @@ use std::fmt; -use super::completion_config::SnippetCap; use hir::Documentation; use ra_syntax::TextRange; use ra_text_edit::TextEdit; +use crate::completion::completion_config::SnippetCap; + /// `CompletionItem` describes a single completion variant in the editor pop-up. /// It is basically a POD with various properties. To construct a /// `CompletionItem`, use `new` method and the `Builder` struct. -- cgit v1.2.3 From bd9f1f7eb78843ddd91d259a04e988b0681a5db4 Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Wed, 6 May 2020 17:17:35 +0300 Subject: Fix rename of enum variant visible from module --- crates/ra_ide/src/references/rename.rs | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 0398d53bc..2cbb82c1a 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -712,6 +712,68 @@ mod tests { "###); } + #[test] + fn test_enum_variant_from_module_1() { + test_rename( + r#" + mod foo { + pub enum Foo { + Bar<|>, + } + } + + fn func(f: foo::Foo) { + match f { + foo::Foo::Bar => {} + } + } + "#, + "Baz", + r#" + mod foo { + pub enum Foo { + Baz, + } + } + + fn func(f: foo::Foo) { + match f { + foo::Foo::Baz => {} + } + } + "#, + ); + } + + #[test] + fn test_enum_variant_from_module_2() { + test_rename( + r#" + mod foo { + pub struct Foo { + pub bar<|>: uint, + } + } + + fn foo(f: foo::Foo) { + let _ = f.bar; + } + "#, + "baz", + r#" + mod foo { + pub struct Foo { + pub baz: uint, + } + } + + fn foo(f: foo::Foo) { + let _ = f.baz; + } + "#, + ); + } + fn test_rename(text: &str, new_name: &str, expected: &str) { let (analysis, position) = single_file_with_position(text); let source_change = analysis.rename(position, new_name).unwrap(); -- cgit v1.2.3 From 43cedecf68a6686b61fbd244b76c592726d1f211 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 14:29:01 +0200 Subject: Fix panic in FunctionSignature --- crates/ra_ide/src/display/function_signature.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index db3907fe6..f16d42276 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -1,5 +1,7 @@ //! FIXME: write short doc here +// FIXME: this modules relies on strings and AST way too much, and it should be +// rewritten (matklad 2020-05-07) use std::{ convert::From, fmt::{self, Display}, @@ -202,7 +204,11 @@ impl From<&'_ ast::FnDef> for FunctionSignature { res.extend(param_list.params().map(|param| param.syntax().text().to_string())); res_types.extend(param_list.params().map(|param| { - param.syntax().text().to_string().split(':').nth(1).unwrap()[1..].to_string() + let param_text = param.syntax().text().to_string(); + match param_text.split(':').nth(1) { + Some(it) => it[1..].to_string(), + None => param_text, + } })); } (has_self_param, res, res_types) -- cgit v1.2.3 From c6b81bc013b5278b917d109b723405e0df413323 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 17:09:59 +0200 Subject: Rename AssitLabel -> Assist --- crates/ra_ide/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 737f87109..0e15f1ccd 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -475,9 +475,9 @@ impl Analysis { ra_assists::resolved_assists(db, frange) .into_iter() .map(|assist| Assist { - id: assist.label.id, - label: assist.label.label, - group_label: assist.label.group.map(|it| it.0), + id: assist.assist.id, + label: assist.assist.label, + group_label: assist.assist.group.map(|it| it.0), source_change: assist.source_change, }) .collect() -- cgit v1.2.3 From 28fcff125a73ab2fc4aeaa100fc472af5178db20 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 17:29:23 +0200 Subject: Nicer API --- crates/ra_ide/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 0e15f1ccd..915199bd8 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -472,7 +472,7 @@ impl Analysis { /// position. pub fn assists(&self, frange: FileRange) -> Cancelable> { self.with_db(|db| { - ra_assists::resolved_assists(db, frange) + ra_assists::Assist::resolved(db, frange) .into_iter() .map(|assist| Assist { id: assist.assist.id, -- cgit v1.2.3