aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs22
-rw-r--r--crates/ra_ide/src/goto_definition.rs25
-rw-r--r--crates/ra_ide/src/hover.rs2
-rw-r--r--crates/ra_ide/src/references.rs2
-rw-r--r--crates/ra_ide/src/references/classify.rs14
-rw-r--r--crates/ra_ide/src/references/name_definition.rs6
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html9
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html1
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs12
9 files changed, 75 insertions, 18 deletions
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index add11fbc3..6a6b49afd 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};
6use ra_syntax::{ 6use ra_syntax::{
7 ast::{self, DocCommentsOwner, NameOwner}, 7 ast::{self, DocCommentsOwner, NameOwner},
8 match_ast, AstNode, SmolStr, 8 match_ast, AstNode, SmolStr,
9 SyntaxKind::{self, BIND_PAT}, 9 SyntaxKind::{self, BIND_PAT, TYPE_PARAM},
10 TextRange, 10 TextRange,
11}; 11};
12 12
@@ -351,6 +351,26 @@ impl ToNav for hir::Local {
351 } 351 }
352} 352}
353 353
354impl ToNav for hir::TypeParam {
355 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
356 let src = self.source(db);
357 let range = match src.value {
358 Either::Left(it) => it.syntax().text_range(),
359 Either::Right(it) => it.syntax().text_range(),
360 };
361 NavigationTarget {
362 file_id: src.file_id.original_file(db),
363 name: self.name(db).to_string().into(),
364 kind: TYPE_PARAM,
365 full_range: range,
366 focus_range: None,
367 container_name: None,
368 description: None,
369 docs: None,
370 }
371 }
372}
373
354pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { 374pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
355 let parse = db.parse(symbol.file_id); 375 let parse = db.parse(symbol.file_id);
356 let node = symbol.ptr.to_node(parse.tree().syntax()); 376 let node = symbol.ptr.to_node(parse.tree().syntax());
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index d3c198813..1b968134d 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(
64 64
65 let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); 65 let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind);
66 match name_kind { 66 match name_kind {
67 Some(Macro(mac)) => return Exact(mac.to_nav(db)), 67 Some(Macro(it)) => return Exact(it.to_nav(db)),
68 Some(Field(field)) => return Exact(field.to_nav(db)), 68 Some(Field(it)) => return Exact(it.to_nav(db)),
69 Some(AssocItem(assoc)) => return Exact(assoc.to_nav(db)), 69 Some(TypeParam(it)) => return Exact(it.to_nav(db)),
70 Some(AssocItem(it)) => return Exact(it.to_nav(db)),
71 Some(Local(it)) => return Exact(it.to_nav(db)),
70 Some(Def(def)) => match NavigationTarget::from_def(db, def) { 72 Some(Def(def)) => match NavigationTarget::from_def(db, def) {
71 Some(nav) => return Exact(nav), 73 Some(nav) => return Exact(nav),
72 None => return Approximate(vec![]), 74 None => return Approximate(vec![]),
@@ -77,10 +79,6 @@ pub(crate) fn reference_definition(
77 // us to the actual type 79 // us to the actual type
78 return Exact(imp.to_nav(db)); 80 return Exact(imp.to_nav(db));
79 } 81 }
80 Some(Local(local)) => return Exact(local.to_nav(db)),
81 Some(GenericParam(_)) => {
82 // FIXME: go to the generic param def
83 }
84 None => {} 82 None => {}
85 }; 83 };
86 84
@@ -723,4 +721,17 @@ mod tests {
723 "foo FN_DEF FileId(1) [359; 376) [362; 365)", 721 "foo FN_DEF FileId(1) [359; 376) [362; 365)",
724 ); 722 );
725 } 723 }
724
725 #[test]
726 fn goto_for_type_param() {
727 check_goto(
728 "
729 //- /lib.rs
730 struct Foo<T> {
731 t: <|>T,
732 }
733 ",
734 "T TYPE_PARAM FileId(1) [11; 12)",
735 );
736 }
726} 737}
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(
138 *no_fallback = true; 138 *no_fallback = true;
139 None 139 None
140 } 140 }
141 GenericParam(_) | SelfType(_) => { 141 TypeParam(_) | SelfType(_) => {
142 // FIXME: Hover for generic param 142 // FIXME: Hover for generic param
143 None 143 None
144 } 144 }
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(
85 NameKind::Def(def) => NavigationTarget::from_def(db, def)?, 85 NameKind::Def(def) => NavigationTarget::from_def(db, def)?,
86 NameKind::SelfType(imp) => imp.to_nav(db), 86 NameKind::SelfType(imp) => imp.to_nav(db),
87 NameKind::Local(local) => local.to_nav(db), 87 NameKind::Local(local) => local.to_nav(db),
88 NameKind::GenericParam(_) => return None, 88 NameKind::TypeParam(_) => return None,
89 }; 89 };
90 90
91 let search_scope = { 91 let search_scope = {
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index b716d32e5..c1f091ec0 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
110 kind: NameKind::Macro(def), 110 kind: NameKind::Macro(def),
111 }) 111 })
112 }, 112 },
113 ast::TypeParam(it) => {
114 let src = name.with_value(it);
115 let def = hir::TypeParam::from_source(db, src)?;
116 Some(NameDefinition {
117 visibility: None,
118 container: def.module(db),
119 kind: NameKind::TypeParam(def),
120 })
121 },
113 _ => None, 122 _ => None,
114 } 123 }
115 } 124 }
@@ -168,9 +177,8 @@ pub(crate) fn classify_name_ref(
168 let kind = NameKind::Local(local); 177 let kind = NameKind::Local(local);
169 Some(NameDefinition { kind, container, visibility: None }) 178 Some(NameDefinition { kind, container, visibility: None })
170 } 179 }
171 PathResolution::GenericParam(par) => { 180 PathResolution::TypeParam(par) => {
172 // FIXME: get generic param def 181 let kind = NameKind::TypeParam(par);
173 let kind = NameKind::GenericParam(par);
174 Some(NameDefinition { kind, container, visibility }) 182 Some(NameDefinition { kind, container, visibility })
175 } 183 }
176 PathResolution::Macro(def) => { 184 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 @@
4//! Note that the reference search is possible for not all of the classified items. 4//! Note that the reference search is possible for not all of the classified items.
5 5
6use hir::{ 6use hir::{
7 Adt, AssocItem, GenericParam, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, 7 Adt, AssocItem, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, StructField,
8 StructField, VariantDef, 8 TypeParam, VariantDef,
9}; 9};
10use ra_syntax::{ast, ast::VisibilityOwner}; 10use ra_syntax::{ast, ast::VisibilityOwner};
11 11
@@ -19,7 +19,7 @@ pub enum NameKind {
19 Def(ModuleDef), 19 Def(ModuleDef),
20 SelfType(ImplBlock), 20 SelfType(ImplBlock),
21 Local(Local), 21 Local(Local),
22 GenericParam(GenericParam), 22 TypeParam(TypeParam),
23} 23}
24 24
25#[derive(PartialEq, Eq)] 25#[derive(PartialEq, Eq)]
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
9.parameter { color: #94BFF3; } 9.parameter { color: #94BFF3; }
10.builtin { color: #DD6718; } 10.builtin { color: #DD6718; }
11.text { color: #DCDCCC; } 11.text { color: #DCDCCC; }
12.type { color: #7CB8BB; }
12.attribute { color: #94BFF3; } 13.attribute { color: #94BFF3; }
13.literal { color: #BFEBBF; } 14.literal { color: #BFEBBF; }
14.macro { color: #94BFF3; } 15.macro { color: #94BFF3; }
@@ -45,4 +46,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
45 <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>; 46 <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>;
46 47
47 <span class="variable.mut">y</span>; 48 <span class="variable.mut">y</span>;
49}
50
51<span class="keyword">enum</span> <span class="type">E</span>&lt;<span class="type">X</span>&gt; {
52 <span class="constant">V</span>(<span class="type">X</span>)
53}
54
55<span class="keyword">impl</span>&lt;<span class="type">X</span>&gt; <span class="type">E</span>&lt;<span class="type">X</span>&gt; {
56 <span class="keyword">fn</span> <span class="function">new</span>&lt;<span class="type">T</span>&gt;() -&gt; <span class="type">E</span>&lt;<span class="type">T</span>&gt; {}
48}</code></pre> \ No newline at end of file 57}</code></pre> \ No newline at end of file
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
9.parameter { color: #94BFF3; } 9.parameter { color: #94BFF3; }
10.builtin { color: #DD6718; } 10.builtin { color: #DD6718; }
11.text { color: #DCDCCC; } 11.text { color: #DCDCCC; }
12.type { color: #7CB8BB; }
12.attribute { color: #94BFF3; } 13.attribute { color: #94BFF3; }
13.literal { color: #BFEBBF; } 14.literal { color: #BFEBBF; }
14.macro { color: #94BFF3; } 15.macro { color: #94BFF3; }
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index e6a79541f..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 {
225 Def(hir::ModuleDef::Trait(_)) => "type", 225 Def(hir::ModuleDef::Trait(_)) => "type",
226 Def(hir::ModuleDef::TypeAlias(_)) => "type", 226 Def(hir::ModuleDef::TypeAlias(_)) => "type",
227 Def(hir::ModuleDef::BuiltinType(_)) => "type", 227 Def(hir::ModuleDef::BuiltinType(_)) => "type",
228 SelfType(_) => "type", 228 SelfType(_) | TypeParam(_) => "type",
229 GenericParam(_) => "type",
230 Local(local) => { 229 Local(local) => {
231 if local.is_mut(db) { 230 if local.is_mut(db) {
232 "variable.mut" 231 "variable.mut"
@@ -255,6 +254,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
255.parameter { color: #94BFF3; } 254.parameter { color: #94BFF3; }
256.builtin { color: #DD6718; } 255.builtin { color: #DD6718; }
257.text { color: #DCDCCC; } 256.text { color: #DCDCCC; }
257.type { color: #7CB8BB; }
258.attribute { color: #94BFF3; } 258.attribute { color: #94BFF3; }
259.literal { color: #BFEBBF; } 259.literal { color: #BFEBBF; }
260.macro { color: #94BFF3; } 260.macro { color: #94BFF3; }
@@ -303,6 +303,14 @@ fn main() {
303 303
304 y; 304 y;
305} 305}
306
307enum E<X> {
308 V(X)
309}
310
311impl<X> E<X> {
312 fn new<T>() -> E<T> {}
313}
306"# 314"#
307 .trim(), 315 .trim(),
308 ); 316 );