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') 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 d1a01aa2f8ca9eff9ba2321f2f113623742e212c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Dec 2019 18:54:18 +0100 Subject: Gotodef for TypeParameters --- crates/ra_ide/src/goto_definition.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index d3c198813..64c0cbad4 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -64,9 +64,11 @@ pub(crate) fn reference_definition( let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); match name_kind { - Some(Macro(mac)) => return Exact(mac.to_nav(db)), - Some(Field(field)) => return Exact(field.to_nav(db)), - Some(AssocItem(assoc)) => return Exact(assoc.to_nav(db)), + Some(Macro(it)) => return Exact(it.to_nav(db)), + Some(Field(it)) => return Exact(it.to_nav(db)), + Some(GenericParam(it)) => return Exact(it.to_nav(db)), + Some(AssocItem(it)) => return Exact(it.to_nav(db)), + Some(Local(it)) => return Exact(it.to_nav(db)), Some(Def(def)) => match NavigationTarget::from_def(db, def) { Some(nav) => return Exact(nav), None => return Approximate(vec![]), @@ -77,10 +79,6 @@ pub(crate) fn reference_definition( // us to the actual type return Exact(imp.to_nav(db)); } - Some(Local(local)) => return Exact(local.to_nav(db)), - Some(GenericParam(_)) => { - // FIXME: go to the generic param def - } None => {} }; @@ -723,4 +721,17 @@ mod tests { "foo FN_DEF FileId(1) [359; 376) [362; 365)", ); } + + #[test] + fn goto_for_type_param() { + check_goto( + " + //- /lib.rs + struct Foo { + t: <|>T, + } + ", + "T TYPE_PARAM FileId(1) [11; 12)", + ); + } } -- cgit v1.2.3 From 7d2080a0311cab62388f416beeb360695dbc5ded Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Dec 2019 19:52:09 +0100 Subject: Classify name works for TypeParams --- crates/ra_ide/src/references/classify.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index b716d32e5..65df2e335 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -110,6 +110,15 @@ pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Opti kind: NameKind::Macro(def), }) }, + ast::TypeParam(it) => { + let src = name.with_value(it); + let def = hir::GenericParam::from_source(db, src)?; + Some(NameDefinition { + visibility: None, + container: def.module(db), + kind: NameKind::GenericParam(def), + }) + }, _ => None, } } -- cgit v1.2.3 From f4f8b8147426b0096d4b5126e487caaa13d13c27 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 7 Dec 2019 20:05:08 +0100 Subject: Get the right analyzer for impls --- crates/ra_ide/src/references/classify.rs | 1 - crates/ra_ide/src/snapshots/highlighting.html | 9 +++++++++ crates/ra_ide/src/syntax_highlighting.rs | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 65df2e335..ed98dbc13 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -178,7 +178,6 @@ pub(crate) fn classify_name_ref( Some(NameDefinition { kind, container, visibility: None }) } PathResolution::GenericParam(par) => { - // FIXME: get generic param def let kind = NameKind::GenericParam(par); Some(NameDefinition { kind, container, visibility }) } diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index b39c4d371..4166a8f90 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html @@ -9,6 +9,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .parameter { color: #94BFF3; } .builtin { color: #DD6718; } .text { color: #DCDCCC; } +.type { color: #7CB8BB; } .attribute { color: #94BFF3; } .literal { color: #BFEBBF; } .macro { color: #94BFF3; } @@ -45,4 +46,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd let z = &y; y; +} + +enum E<X> { + V(X) +} + +impl<X> E<X> { + fn new<T>() -> E<T> {} } \ No newline at end of file diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index e6a79541f..20eefeb57 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -255,6 +255,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .parameter { color: #94BFF3; } .builtin { color: #DD6718; } .text { color: #DCDCCC; } +.type { color: #7CB8BB; } .attribute { color: #94BFF3; } .literal { color: #BFEBBF; } .macro { color: #94BFF3; } @@ -303,6 +304,14 @@ fn main() { y; } + +enum E { + V(X) +} + +impl E { + fn new() -> E {} +} "# .trim(), ); -- 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 +- crates/ra_ide/src/goto_definition.rs | 2 +- crates/ra_ide/src/hover.rs | 2 +- crates/ra_ide/src/references.rs | 2 +- crates/ra_ide/src/references/classify.rs | 8 ++++---- crates/ra_ide/src/references/name_definition.rs | 6 +++--- crates/ra_ide/src/snapshots/rainbow_highlighting.html | 1 + crates/ra_ide/src/syntax_highlighting.rs | 3 +-- 8 files changed, 13 insertions(+), 13 deletions(-) (limited to 'crates/ra_ide') 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 { diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 64c0cbad4..1b968134d 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -66,7 +66,7 @@ pub(crate) fn reference_definition( match name_kind { Some(Macro(it)) => return Exact(it.to_nav(db)), Some(Field(it)) => return Exact(it.to_nav(db)), - Some(GenericParam(it)) => return Exact(it.to_nav(db)), + Some(TypeParam(it)) => return Exact(it.to_nav(db)), Some(AssocItem(it)) => return Exact(it.to_nav(db)), Some(Local(it)) => return Exact(it.to_nav(db)), Some(Def(def)) => match NavigationTarget::from_def(db, def) { diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index d8185c688..d372ca758 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -138,7 +138,7 @@ fn hover_text_from_name_kind( *no_fallback = true; None } - GenericParam(_) | SelfType(_) => { + TypeParam(_) | SelfType(_) => { // FIXME: Hover for generic param None } diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 3e7bfd872..e3ecde50d 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -85,7 +85,7 @@ pub(crate) fn find_all_refs( NameKind::Def(def) => NavigationTarget::from_def(db, def)?, NameKind::SelfType(imp) => imp.to_nav(db), NameKind::Local(local) => local.to_nav(db), - NameKind::GenericParam(_) => return None, + NameKind::TypeParam(_) => return None, }; let search_scope = { diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index ed98dbc13..c1f091ec0 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -112,11 +112,11 @@ pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Opti }, ast::TypeParam(it) => { let src = name.with_value(it); - let def = hir::GenericParam::from_source(db, src)?; + let def = hir::TypeParam::from_source(db, src)?; Some(NameDefinition { visibility: None, container: def.module(db), - kind: NameKind::GenericParam(def), + kind: NameKind::TypeParam(def), }) }, _ => None, @@ -177,8 +177,8 @@ pub(crate) fn classify_name_ref( let kind = NameKind::Local(local); Some(NameDefinition { kind, container, visibility: None }) } - PathResolution::GenericParam(par) => { - let kind = NameKind::GenericParam(par); + PathResolution::TypeParam(par) => { + let kind = NameKind::TypeParam(par); Some(NameDefinition { kind, container, visibility }) } PathResolution::Macro(def) => { diff --git a/crates/ra_ide/src/references/name_definition.rs b/crates/ra_ide/src/references/name_definition.rs index 10d3a2364..8c67c8863 100644 --- a/crates/ra_ide/src/references/name_definition.rs +++ b/crates/ra_ide/src/references/name_definition.rs @@ -4,8 +4,8 @@ //! Note that the reference search is possible for not all of the classified items. use hir::{ - Adt, AssocItem, GenericParam, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, - StructField, VariantDef, + Adt, AssocItem, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, StructField, + TypeParam, VariantDef, }; use ra_syntax::{ast, ast::VisibilityOwner}; @@ -19,7 +19,7 @@ pub enum NameKind { Def(ModuleDef), SelfType(ImplBlock), Local(Local), - GenericParam(GenericParam), + TypeParam(TypeParam), } #[derive(PartialEq, Eq)] diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html index 79f11ea80..9dfbc8047 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html @@ -9,6 +9,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .parameter { color: #94BFF3; } .builtin { color: #DD6718; } .text { color: #DCDCCC; } +.type { color: #7CB8BB; } .attribute { color: #94BFF3; } .literal { color: #BFEBBF; } .macro { color: #94BFF3; } diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 20eefeb57..7ecb1a027 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -225,8 +225,7 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { Def(hir::ModuleDef::Trait(_)) => "type", Def(hir::ModuleDef::TypeAlias(_)) => "type", Def(hir::ModuleDef::BuiltinType(_)) => "type", - SelfType(_) => "type", - GenericParam(_) => "type", + SelfType(_) | TypeParam(_) => "type", Local(local) => { if local.is_mut(db) { "variable.mut" -- cgit v1.2.3