From ccd1b0800a5de5e046e6e9a4b6f49030c1ce3639 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 28 Nov 2019 12:50:26 +0300 Subject: Rename Source -> InFile --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/display/navigation_target.rs') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 6ac60722b..61dca14ac 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource, Source}; +use hir::{AssocItem, Either, FieldSource, HasSource, InFile, ModuleSource}; use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, @@ -141,7 +141,7 @@ impl NavigationTarget { /// Allows `NavigationTarget` to be created from a `NameOwner` pub(crate) fn from_named( db: &RootDatabase, - node: Source<&dyn ast::NameOwner>, + node: InFile<&dyn ast::NameOwner>, docs: Option, description: Option, ) -> NavigationTarget { -- cgit v1.2.3 From 009437f5d9949d2276aa26040e03af0ab328acf3 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 3 Dec 2019 11:07:56 -0500 Subject: Replace `ra_hir_expand::either` with crate --- crates/ra_ide/src/display/navigation_target.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/display/navigation_target.rs') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 61dca14ac..f920d3db6 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -1,6 +1,7 @@ //! FIXME: write short doc here -use hir::{AssocItem, Either, FieldSource, HasSource, InFile, ModuleSource}; +use either::Either; +use hir::{AssocItem, FieldSource, HasSource, InFile, ModuleSource}; use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, @@ -342,10 +343,10 @@ impl ToNav for hir::Local { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.source(db); let (full_range, focus_range) = match src.value { - Either::A(it) => { + Either::Left(it) => { (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) } - Either::B(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())), + Either::Right(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())), }; let name = match self.name(db) { Some(it) => it.to_string().into(), -- cgit v1.2.3 From 38853459e3d964cc7f635829cdc66f5faee33d85 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 3 Dec 2019 15:24:02 -0500 Subject: Add `ModuleSource::Block` --- crates/ra_ide/src/display/navigation_target.rs | 43 +++++++++----------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'crates/ra_ide/src/display/navigation_target.rs') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index f920d3db6..b376fcdae 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -231,34 +231,21 @@ impl ToNav for hir::Module { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.definition_source(db); let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); - match &src.value { - ModuleSource::SourceFile(node) => { - let frange = original_range(db, src.with_value(node.syntax())); - - NavigationTarget::from_syntax( - frange.file_id, - name, - None, - frange.range, - node.syntax().kind(), - None, - None, - ) - } - ModuleSource::Module(node) => { - let frange = original_range(db, src.with_value(node.syntax())); - - NavigationTarget::from_syntax( - frange.file_id, - name, - None, - frange.range, - node.syntax().kind(), - node.doc_comment_text(), - node.short_label(), - ) - } - } + let syntax = match &src.value { + ModuleSource::SourceFile(node) => node.syntax(), + ModuleSource::Module(node) => node.syntax(), + ModuleSource::Block(node) => node.syntax(), + }; + let frange = original_range(db, src.with_value(syntax)); + NavigationTarget::from_syntax( + frange.file_id, + name, + None, + frange.range, + syntax.kind(), + None, + None, + ) } } -- cgit v1.2.3 From 088f50c0ab351d5ac072547a47c1ce7eeae029f3 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 4 Dec 2019 13:35:24 -0500 Subject: No block at the moment --- crates/ra_ide/src/display/navigation_target.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_ide/src/display/navigation_target.rs') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index b376fcdae..add11fbc3 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -234,7 +234,6 @@ impl ToNav for hir::Module { let syntax = match &src.value { ModuleSource::SourceFile(node) => node.syntax(), ModuleSource::Module(node) => node.syntax(), - ModuleSource::Block(node) => node.syntax(), }; let frange = original_range(db, src.with_value(syntax)); NavigationTarget::from_syntax( -- cgit v1.2.3 From 1692f07393dba4f5c122df1a609d5b18751bf406 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Dec 2019 18:48:35 +0100 Subject: ToNav for GenericParam --- crates/ra_ide/src/display/navigation_target.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/display/navigation_target.rs') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index add11fbc3..e8c3d980f 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -6,7 +6,7 @@ use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, match_ast, AstNode, SmolStr, - SyntaxKind::{self, BIND_PAT}, + SyntaxKind::{self, BIND_PAT, TYPE_PARAM}, TextRange, }; @@ -351,6 +351,26 @@ impl ToNav for hir::Local { } } +impl ToNav for hir::GenericParam { + fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { + let src = self.source(db); + let range = match src.value { + Either::Left(it) => it.syntax().text_range(), + Either::Right(it) => it.syntax().text_range(), + }; + NavigationTarget { + file_id: src.file_id.original_file(db), + name: self.name(db).to_string().into(), + kind: TYPE_PARAM, + full_range: range, + focus_range: None, + container_name: None, + description: None, + docs: None, + } + } +} + pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option { let parse = db.parse(symbol.file_id); let node = symbol.ptr.to_node(parse.tree().syntax()); -- cgit v1.2.3 From 88c5b1282a5770097c6c768b24bedfc3a6944e08 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Dec 2019 20:09:53 +0100 Subject: Rename GenericParam -> TypeParam We don't have LifetimeParam yet, but they are planned! --- crates/ra_ide/src/display/navigation_target.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/display/navigation_target.rs') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index e8c3d980f..6a6b49afd 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -351,7 +351,7 @@ impl ToNav for hir::Local { } } -impl ToNav for hir::GenericParam { +impl ToNav for hir::TypeParam { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.source(db); let range = match src.value { -- cgit v1.2.3 From 7c25224f0522cb828c4aa2d791562b84ee2995f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 18 Dec 2019 16:25:15 +0100 Subject: Don't bother with focus range for navigation to locals --- crates/ra_ide/src/display/navigation_target.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide/src/display/navigation_target.rs') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 6a6b49afd..b9ae67828 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -328,22 +328,23 @@ impl ToNav for hir::AssocItem { impl ToNav for hir::Local { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.source(db); - let (full_range, focus_range) = match src.value { - Either::Left(it) => { - (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) + let node = match &src.value { + Either::Left(bind_pat) => { + bind_pat.name().map_or_else(|| bind_pat.syntax().clone(), |it| it.syntax().clone()) } - Either::Right(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())), + Either::Right(it) => it.syntax().clone(), }; + let full_range = original_range(db, src.with_value(&node)); let name = match self.name(db) { Some(it) => it.to_string().into(), None => "".into(), }; NavigationTarget { - file_id: src.file_id.original_file(db), + file_id: full_range.file_id, name, kind: BIND_PAT, - full_range, - focus_range, + full_range: full_range.range, + focus_range: None, container_name: None, description: None, docs: None, -- cgit v1.2.3