From 91c120ccea4f0cfef20fd4d918154c8152f83816 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 02:34:34 +0300 Subject: introduce Source struct --- crates/ra_ide_api/src/hover.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index fbabeb194..80445761c 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -136,8 +136,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ModuleDef::Union(it) => { let it = it.source(db).1; @@ -176,8 +176,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text( + src.ast.doc_comment_text(), + src.ast.short_label(), + )) } hir::AdtDef::Union(it) => { let it = it.source(db).1; -- cgit v1.2.3 From 2a1fe26b6d354dbbd1b3843d288d56e74fa00557 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 03:17:29 +0300 Subject: use Source more --- crates/ra_ide_api/src/hover.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 80445761c..ee0f2dde8 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -144,12 +144,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ModuleDef::EnumVariant(it) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ModuleDef::Const(it) => { let it = it.source(db).1; @@ -187,8 +187,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text( + src.ast.doc_comment_text(), + src.ast.short_label(), + )) } } } -- cgit v1.2.3 From 4f94af3c4aaa57ebb4cb01f7e4edfb3a0821b09b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 16:49:56 +0300 Subject: use Source for Function --- crates/ra_ide_api/src/hover.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index ee0f2dde8..4dd3c1b9f 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -96,8 +96,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())); + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())); } Some(Macro(it)) => { let it = it.source(db).1; @@ -111,8 +111,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option match it { hir::ImplItem::Method(it) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ImplItem::Const(it) => { let it = it.source(db).1; @@ -132,8 +132,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ModuleDef::Struct(it) => { let src = it.source(db); -- cgit v1.2.3 From 46bc8675edd403ffcd8963e4f26447b283e9d09e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:13:20 +0300 Subject: use Source for statics and consts --- crates/ra_ide_api/src/hover.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 4dd3c1b9f..fe108a589 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -115,8 +115,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ImplItem::TypeAlias(it) => { let it = it.source(db).1; @@ -152,12 +152,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ModuleDef::Static(it) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } hir::ModuleDef::Trait(it) => { let it = it.source(db).1; -- cgit v1.2.3 From 647c8f3df8e5f798f940ce0b93e5e0ccd59b0e7f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:22:14 +0300 Subject: reduce duplication in hover --- crates/ra_ide_api/src/hover.rs | 80 +++++++++++++----------------------------- 1 file changed, 24 insertions(+), 56 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index fe108a589..0f68cacca 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -1,6 +1,7 @@ use ra_db::SourceDatabase; use ra_syntax::{ - AstNode, ast::{self, DocCommentsOwner}, + AstNode, TreeArc, + ast::{self, DocCommentsOwner}, algo::{find_covering_element, find_node_at_offset, ancestors_at_offset, visit::{visitor, Visitor}}, }; use hir::HirDisplay; @@ -95,10 +96,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())); - } + Some(Method(it)) => res.extend(from_def_source(db, it)), Some(Macro(it)) => { let it = it.source(db).1; res.extend(hover_text(it.doc_comment_text(), None)); @@ -110,14 +108,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option match it { - hir::ImplItem::Method(it) => { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } - hir::ImplItem::Const(it) => { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } + hir::ImplItem::Method(it) => res.extend(from_def_source(db, it)), + hir::ImplItem::Const(it) => res.extend(from_def_source(db, it)), hir::ImplItem::TypeAlias(it) => { let it = it.source(db).1; res.extend(hover_text(it.doc_comment_text(), it.short_label())) @@ -131,34 +123,16 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } - hir::ModuleDef::Struct(it) => { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } - hir::ModuleDef::Union(it) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) - } - hir::ModuleDef::Enum(it) => { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } + hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::EnumVariant(it) => { let src = it.source(db); res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) } - hir::ModuleDef::Const(it) => { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } - hir::ModuleDef::Static(it) => { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } + hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Trait(it) => { let it = it.source(db).1; res.extend(hover_text(it.doc_comment_text(), it.short_label())) @@ -175,24 +149,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { if let Some((adt_def, _)) = ty.as_adt() { match adt_def { - hir::AdtDef::Struct(it) => { - let src = it.source(db); - res.extend(hover_text( - src.ast.doc_comment_text(), - src.ast.short_label(), - )) - } - hir::AdtDef::Union(it) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) - } - hir::AdtDef::Enum(it) => { - let src = it.source(db); - res.extend(hover_text( - src.ast.doc_comment_text(), - src.ast.short_label(), - )) - } + hir::AdtDef::Struct(it) => res.extend(from_def_source(db, it)), + hir::AdtDef::Union(it) => res.extend(from_def_source(db, it)), + hir::AdtDef::Enum(it) => res.extend(from_def_source(db, it)), } } } @@ -276,7 +235,16 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option(db: &RootDatabase, def: D) -> Option + where + D: hir::HasSource>, + A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, + { + let src = def.source(db); + hover_text(src.ast.doc_comment_text(), src.ast.short_label()) + } } pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option { -- cgit v1.2.3 From f2ccc54468348af96d6167da5971749ef0f4ab5e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:25:55 +0300 Subject: use Source for TypeAlias --- crates/ra_ide_api/src/hover.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 0f68cacca..c4826e515 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -107,14 +107,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option match it { - hir::ImplItem::Method(it) => res.extend(from_def_source(db, it)), - hir::ImplItem::Const(it) => res.extend(from_def_source(db, it)), - hir::ImplItem::TypeAlias(it) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) - } - }, + Some(AssocItem(it)) => res.extend(match it { + hir::ImplItem::Method(it) => from_def_source(db, it), + hir::ImplItem::Const(it) => from_def_source(db, it), + hir::ImplItem::TypeAlias(it) => from_def_source(db, it), + }), Some(Def(it)) => { match it { hir::ModuleDef::Module(it) => { @@ -137,10 +134,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) - } + hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::BuiltinType(_) => { // FIXME: hover for builtin Type ? } -- cgit v1.2.3 From 5e6213b516ab5c9be62c499ba0ea9eb399d68389 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:26:36 +0300 Subject: simplify --- crates/ra_ide_api/src/hover.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index c4826e515..237e1f4a1 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -142,11 +142,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { if let Some((adt_def, _)) = ty.as_adt() { - match adt_def { - hir::AdtDef::Struct(it) => res.extend(from_def_source(db, it)), - hir::AdtDef::Union(it) => res.extend(from_def_source(db, it)), - hir::AdtDef::Enum(it) => res.extend(from_def_source(db, it)), - } + res.extend(match adt_def { + hir::AdtDef::Struct(it) => from_def_source(db, it), + hir::AdtDef::Union(it) => from_def_source(db, it), + hir::AdtDef::Enum(it) => from_def_source(db, it), + }) } } Some(Pat(_)) => { -- cgit v1.2.3 From f411c2988d40bbdebc5c9a63ce4bfb883a2fbca1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:34:01 +0300 Subject: use Source for Trait --- crates/ra_ide_api/src/hover.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 237e1f4a1..c4004435c 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -124,16 +124,10 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option res.extend(from_def_source(db, it)), hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::EnumVariant(it) => { - let src = it.source(db); - res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) - } + hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Trait(it) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), it.short_label())) - } + hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::BuiltinType(_) => { // FIXME: hover for builtin Type ? -- cgit v1.2.3 From 8b94b429e5a76a0518b07111f8faf0dca7457948 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:40:18 +0300 Subject: use Source for MacroDef --- crates/ra_ide_api/src/hover.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index c4004435c..72328a72b 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -98,8 +98,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option res.extend(from_def_source(db, it)), Some(Macro(it)) => { - let it = it.source(db).1; - res.extend(hover_text(it.doc_comment_text(), None)); + let src = it.source(db); + res.extend(hover_text(src.ast.doc_comment_text(), None)); } Some(FieldAccess(it)) => { let it = it.source(db).1; -- cgit v1.2.3 From 178d8e96b5c810f40e7dd282ab06bb25d1fc8a2a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:43:36 +0300 Subject: use Source for StructField --- crates/ra_ide_api/src/hover.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 72328a72b..e43c1d8e5 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -102,8 +102,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - let it = it.source(db).1; - if let hir::FieldSource::Named(it) = it { + let src = it.source(db); + if let hir::FieldSource::Named(it) = src.ast { res.extend(hover_text(it.doc_comment_text(), it.short_label())); } } -- cgit v1.2.3 From 0145d06515d990f8b7bf45e261674c265c52d858 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:47:24 +0300 Subject: use Source for module, part 1 --- crates/ra_ide_api/src/hover.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index e43c1d8e5..77657607b 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -115,8 +115,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { match it { hir::ModuleDef::Module(it) => { - let it = it.definition_source(db).1; - if let hir::ModuleSource::Module(it) = it { + if let hir::ModuleSource::Module(it) = it.definition_source(db).ast { res.extend(hover_text(it.doc_comment_text(), it.short_label())) } } -- cgit v1.2.3 From c4512fadb1b332b13bb41b0aa8a28aa964664842 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 11 Jun 2019 17:54:51 +0300 Subject: remove inherent source impls --- crates/ra_ide_api/src/hover.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api/src/hover.rs') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 77657607b..ad00abe49 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -4,7 +4,7 @@ use ra_syntax::{ ast::{self, DocCommentsOwner}, algo::{find_covering_element, find_node_at_offset, ancestors_at_offset, visit::{visitor, Visitor}}, }; -use hir::HirDisplay; +use hir::{HirDisplay, HasSource}; use crate::{ db::RootDatabase, @@ -226,7 +226,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option(db: &RootDatabase, def: D) -> Option where - D: hir::HasSource>, + D: HasSource>, A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, { let src = def.source(db); -- cgit v1.2.3