aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/completion/src/completions/attribute.rs14
-rw-r--r--crates/hir/src/code_model.rs18
-rw-r--r--crates/ide/src/display/navigation_target.rs14
-rw-r--r--crates/ide/src/doc_links.rs4
-rw-r--r--crates/ide/src/goto_definition.rs4
-rw-r--r--crates/ide/src/hover.rs20
-rw-r--r--crates/ide/src/references.rs5
-rw-r--r--crates/ide/src/runnables.rs75
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs8
-rw-r--r--crates/ide/src/syntax_highlighting/highlights.rs12
-rw-r--r--crates/ide/src/syntax_highlighting/injector.rs3
-rw-r--r--crates/ide_db/src/defs.rs36
-rw-r--r--crates/ide_db/src/search.rs2
-rw-r--r--crates/stdx/src/lib.rs4
14 files changed, 125 insertions, 94 deletions
diff --git a/crates/completion/src/completions/attribute.rs b/crates/completion/src/completions/attribute.rs
index 3a29b5203..a52ca107e 100644
--- a/crates/completion/src/completions/attribute.rs
+++ b/crates/completion/src/completions/attribute.rs
@@ -21,15 +21,17 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
21 21
22 let attribute = ctx.attribute_under_caret.as_ref()?; 22 let attribute = ctx.attribute_under_caret.as_ref()?;
23 match (attribute.path(), attribute.token_tree()) { 23 match (attribute.path(), attribute.token_tree()) {
24 (Some(path), Some(token_tree)) => match path.to_string().as_str() { 24 (Some(path), Some(token_tree)) => {
25 "derive" => complete_derive(acc, ctx, token_tree), 25 let path = path.syntax().text();
26 "feature" => complete_lint(acc, ctx, token_tree, FEATURES), 26 if path == "derive" {
27 "allow" | "warn" | "deny" | "forbid" => { 27 complete_derive(acc, ctx, token_tree)
28 } else if path == "feature" {
29 complete_lint(acc, ctx, token_tree, FEATURES)
30 } else if path == "allow" || path == "warn" || path == "deny" || path == "forbid" {
28 complete_lint(acc, ctx, token_tree.clone(), DEFAULT_LINT_COMPLETIONS); 31 complete_lint(acc, ctx, token_tree.clone(), DEFAULT_LINT_COMPLETIONS);
29 complete_lint(acc, ctx, token_tree, CLIPPY_LINTS); 32 complete_lint(acc, ctx, token_tree, CLIPPY_LINTS);
30 } 33 }
31 _ => {} 34 }
32 },
33 (_, Some(_token_tree)) => {} 35 (_, Some(_token_tree)) => {}
34 _ => complete_attribute_start(acc, ctx, attribute), 36 _ => complete_attribute_start(acc, ctx, attribute),
35 } 37 }
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index cc1938333..6cbf5cecf 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -1263,6 +1263,24 @@ pub enum GenericParam {
1263} 1263}
1264impl_from!(TypeParam, LifetimeParam, ConstParam for GenericParam); 1264impl_from!(TypeParam, LifetimeParam, ConstParam for GenericParam);
1265 1265
1266impl GenericParam {
1267 pub fn module(self, db: &dyn HirDatabase) -> Module {
1268 match self {
1269 GenericParam::TypeParam(it) => it.module(db),
1270 GenericParam::LifetimeParam(it) => it.module(db),
1271 GenericParam::ConstParam(it) => it.module(db),
1272 }
1273 }
1274
1275 pub fn name(self, db: &dyn HirDatabase) -> Name {
1276 match self {
1277 GenericParam::TypeParam(it) => it.name(db),
1278 GenericParam::LifetimeParam(it) => it.name(db),
1279 GenericParam::ConstParam(it) => it.name(db),
1280 }
1281 }
1282}
1283
1266#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 1284#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1267pub struct TypeParam { 1285pub struct TypeParam {
1268 pub(crate) id: TypeParamId, 1286 pub(crate) id: TypeParamId,
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index e24c78301..4eecae697 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -215,10 +215,8 @@ impl TryToNav for Definition {
215 Definition::ModuleDef(it) => it.try_to_nav(db), 215 Definition::ModuleDef(it) => it.try_to_nav(db),
216 Definition::SelfType(it) => it.try_to_nav(db), 216 Definition::SelfType(it) => it.try_to_nav(db),
217 Definition::Local(it) => Some(it.to_nav(db)), 217 Definition::Local(it) => Some(it.to_nav(db)),
218 Definition::TypeParam(it) => it.try_to_nav(db), 218 Definition::GenericParam(it) => it.try_to_nav(db),
219 Definition::LifetimeParam(it) => it.try_to_nav(db),
220 Definition::Label(it) => Some(it.to_nav(db)), 219 Definition::Label(it) => Some(it.to_nav(db)),
221 Definition::ConstParam(it) => it.try_to_nav(db),
222 } 220 }
223 } 221 }
224} 222}
@@ -389,6 +387,16 @@ impl TryToNav for hir::AssocItem {
389 } 387 }
390} 388}
391 389
390impl TryToNav for hir::GenericParam {
391 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
392 match self {
393 hir::GenericParam::TypeParam(it) => it.try_to_nav(db),
394 hir::GenericParam::ConstParam(it) => it.try_to_nav(db),
395 hir::GenericParam::LifetimeParam(it) => it.try_to_nav(db),
396 }
397 }
398}
399
392impl ToNav for hir::Local { 400impl ToNav for hir::Local {
393 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 401 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
394 let src = self.source(db); 402 let src = self.source(db);
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 678d22d03..91f4241f9 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -216,9 +216,7 @@ fn rewrite_intra_doc_link(
216 Definition::Field(it) => it.resolve_doc_path(db, link, ns), 216 Definition::Field(it) => it.resolve_doc_path(db, link, ns),
217 Definition::SelfType(_) 217 Definition::SelfType(_)
218 | Definition::Local(_) 218 | Definition::Local(_)
219 | Definition::TypeParam(_) 219 | Definition::GenericParam(_)
220 | Definition::ConstParam(_)
221 | Definition::LifetimeParam(_)
222 | Definition::Label(_) => return None, 220 | Definition::Label(_) => return None,
223 }?; 221 }?;
224 let krate = resolved.module(db)?.krate(); 222 let krate = resolved.module(db)?.krate();
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 227f20943..c20185b16 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -111,9 +111,7 @@ fn def_for_doc_comment(
111 Definition::Field(it) => it.resolve_doc_path(db, link, ns), 111 Definition::Field(it) => it.resolve_doc_path(db, link, ns),
112 Definition::SelfType(_) 112 Definition::SelfType(_)
113 | Definition::Local(_) 113 | Definition::Local(_)
114 | Definition::TypeParam(_) 114 | Definition::GenericParam(_)
115 | Definition::LifetimeParam(_)
116 | Definition::ConstParam(_)
117 | Definition::Label(_) => return None, 115 | Definition::Label(_) => return None,
118 } 116 }
119} 117}
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 8cb4a51d8..e331f8886 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -1,6 +1,6 @@
1use hir::{ 1use hir::{
2 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasAttrs, HasSource, HirDisplay, Module, 2 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource,
3 ModuleDef, ModuleSource, Semantics, 3 HirDisplay, Module, ModuleDef, ModuleSource, Semantics,
4}; 4};
5use ide_db::base_db::SourceDatabase; 5use ide_db::base_db::SourceDatabase;
6use ide_db::{ 6use ide_db::{
@@ -17,7 +17,7 @@ use crate::{
17 doc_links::{remove_links, rewrite_links}, 17 doc_links::{remove_links, rewrite_links},
18 markdown_remove::remove_markdown, 18 markdown_remove::remove_markdown,
19 markup::Markup, 19 markup::Markup,
20 runnables::{runnable, runnable_fn}, 20 runnables::{runnable_fn, runnable_mod},
21 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, 21 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
22}; 22};
23 23
@@ -192,7 +192,7 @@ fn runnable_action(
192 Definition::ModuleDef(it) => match it { 192 Definition::ModuleDef(it) => match it {
193 ModuleDef::Module(it) => match it.definition_source(sema.db).value { 193 ModuleDef::Module(it) => match it.definition_source(sema.db).value {
194 ModuleSource::Module(it) => { 194 ModuleSource::Module(it) => {
195 runnable(&sema, it.syntax().clone()).map(|it| HoverAction::Runnable(it)) 195 runnable_mod(&sema, it).map(|it| HoverAction::Runnable(it))
196 } 196 }
197 _ => None, 197 _ => None,
198 }, 198 },
@@ -220,12 +220,12 @@ fn goto_type_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
220 } 220 }
221 }; 221 };
222 222
223 if let Definition::TypeParam(it) = def { 223 if let Definition::GenericParam(GenericParam::TypeParam(it)) = def {
224 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into())); 224 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
225 } else { 225 } else {
226 let ty = match def { 226 let ty = match def {
227 Definition::Local(it) => it.ty(db), 227 Definition::Local(it) => it.ty(db),
228 Definition::ConstParam(it) => it.ty(db), 228 Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db),
229 _ => return None, 229 _ => return None,
230 }; 230 };
231 231
@@ -357,9 +357,11 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
357 }) 357 })
358 } 358 }
359 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), 359 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
360 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), 360 Definition::GenericParam(it) => match it {
361 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))), 361 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
362 Definition::ConstParam(it) => from_def_source(db, it, None), 362 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
363 GenericParam::ConstParam(it) => from_def_source(db, it, None),
364 },
363 }; 365 };
364 366
365 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> 367 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index c95ed669c..0d5cd5f9a 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -130,7 +130,10 @@ pub(crate) fn find_all_refs(
130 kind = ReferenceKind::FieldShorthandForLocal; 130 kind = ReferenceKind::FieldShorthandForLocal;
131 } 131 }
132 } 132 }
133 } else if matches!(def, Definition::LifetimeParam(_) | Definition::Label(_)) { 133 } else if matches!(
134 def,
135 Definition::GenericParam(hir::GenericParam::LifetimeParam(_)) | Definition::Label(_)
136 ) {
134 kind = ReferenceKind::Lifetime; 137 kind = ReferenceKind::Lifetime;
135 }; 138 };
136 139
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index 557563d7e..3a1e204db 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -96,21 +96,23 @@ impl Runnable {
96pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { 96pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
97 let sema = Semantics::new(db); 97 let sema = Semantics::new(db);
98 let source_file = sema.parse(file_id); 98 let source_file = sema.parse(file_id);
99 source_file.syntax().descendants().filter_map(|i| runnable(&sema, i)).collect() 99 source_file
100} 100 .syntax()
101 101 .descendants()
102pub(crate) fn runnable(sema: &Semantics<RootDatabase>, item: SyntaxNode) -> Option<Runnable> { 102 .filter_map(|item| {
103 let runnable_item = match_ast! { 103 let runnable = match_ast! {
104 match (item.clone()) { 104 match item {
105 ast::Fn(func) => { 105 ast::Fn(func) => {
106 let def = sema.to_def(&func)?; 106 let def = sema.to_def(&func)?;
107 runnable_fn(sema, def) 107 runnable_fn(&sema, def)
108 }, 108 },
109 ast::Module(it) => runnable_mod(sema, it), 109 ast::Module(it) => runnable_mod(&sema, it),
110 _ => None, 110 _ => None,
111 } 111 }
112 }; 112 };
113 runnable_item.or_else(|| runnable_doctest(sema, item)) 113 runnable.or_else(|| runnable_doctest(&sema, item))
114 })
115 .collect()
114} 116}
115 117
116pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) -> Option<Runnable> { 118pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) -> Option<Runnable> {
@@ -145,6 +147,29 @@ pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) ->
145 Some(Runnable { nav, kind, cfg }) 147 Some(Runnable { nav, kind, cfg })
146} 148}
147 149
150pub(crate) fn runnable_mod(
151 sema: &Semantics<RootDatabase>,
152 module: ast::Module,
153) -> Option<Runnable> {
154 if !has_test_function_or_multiple_test_submodules(&module) {
155 return None;
156 }
157 let module_def = sema.to_def(&module)?;
158
159 let path = module_def
160 .path_to_root(sema.db)
161 .into_iter()
162 .rev()
163 .filter_map(|it| it.name(sema.db))
164 .join("::");
165
166 let def = sema.to_def(&module)?;
167 let attrs = def.attrs(sema.db);
168 let cfg = attrs.cfg();
169 let nav = module_def.to_nav(sema.db);
170 Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg })
171}
172
148fn runnable_doctest(sema: &Semantics<RootDatabase>, item: SyntaxNode) -> Option<Runnable> { 173fn runnable_doctest(sema: &Semantics<RootDatabase>, item: SyntaxNode) -> Option<Runnable> {
149 match_ast! { 174 match_ast! {
150 match item { 175 match item {
@@ -253,26 +278,6 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
253 }) 278 })
254} 279}
255 280
256fn runnable_mod(sema: &Semantics<RootDatabase>, module: ast::Module) -> Option<Runnable> {
257 if !has_test_function_or_multiple_test_submodules(&module) {
258 return None;
259 }
260 let module_def = sema.to_def(&module)?;
261
262 let path = module_def
263 .path_to_root(sema.db)
264 .into_iter()
265 .rev()
266 .filter_map(|it| it.name(sema.db))
267 .join("::");
268
269 let def = sema.to_def(&module)?;
270 let attrs = def.attrs(sema.db);
271 let cfg = attrs.cfg();
272 let nav = module_def.to_nav(sema.db);
273 Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg })
274}
275
276// We could create runnables for modules with number_of_test_submodules > 0, 281// We could create runnables for modules with number_of_test_submodules > 0,
277// but that bloats the runnables for no real benefit, since all tests can be run by the submodule already 282// but that bloats the runnables for no real benefit, since all tests can be run by the submodule already
278fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { 283fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool {
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index 0cb58d589..34bae49a8 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -339,8 +339,11 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
339 } 339 }
340 }, 340 },
341 Definition::SelfType(_) => HlTag::Symbol(SymbolKind::Impl), 341 Definition::SelfType(_) => HlTag::Symbol(SymbolKind::Impl),
342 Definition::TypeParam(_) => HlTag::Symbol(SymbolKind::TypeParam), 342 Definition::GenericParam(it) => match it {
343 Definition::ConstParam(_) => HlTag::Symbol(SymbolKind::ConstParam), 343 hir::GenericParam::TypeParam(_) => HlTag::Symbol(SymbolKind::TypeParam),
344 hir::GenericParam::ConstParam(_) => HlTag::Symbol(SymbolKind::ConstParam),
345 hir::GenericParam::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam),
346 },
344 Definition::Local(local) => { 347 Definition::Local(local) => {
345 let tag = if local.is_param(db) { 348 let tag = if local.is_param(db) {
346 HlTag::Symbol(SymbolKind::ValueParam) 349 HlTag::Symbol(SymbolKind::ValueParam)
@@ -356,7 +359,6 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
356 } 359 }
357 return h; 360 return h;
358 } 361 }
359 Definition::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam),
360 Definition::Label(_) => HlTag::Symbol(SymbolKind::Label), 362 Definition::Label(_) => HlTag::Symbol(SymbolKind::Label),
361 } 363 }
362 .into() 364 .into()
diff --git a/crates/ide/src/syntax_highlighting/highlights.rs b/crates/ide/src/syntax_highlighting/highlights.rs
index 11c11ed28..c6f0417ec 100644
--- a/crates/ide/src/syntax_highlighting/highlights.rs
+++ b/crates/ide/src/syntax_highlighting/highlights.rs
@@ -51,18 +51,20 @@ impl Node {
51 } 51 }
52 } 52 }
53 53
54 let (start, len) = 54 let overlapping =
55 equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range)); 55 equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range));
56 56
57 if len == 1 && self.nested[start].hl_range.range.contains_range(hl_range.range) { 57 if overlapping.len() == 1
58 return self.nested[start].add(hl_range); 58 && self.nested[overlapping.start].hl_range.range.contains_range(hl_range.range)
59 {
60 return self.nested[overlapping.start].add(hl_range);
59 } 61 }
60 62
61 let nested = self 63 let nested = self
62 .nested 64 .nested
63 .splice(start..start + len, iter::once(Node::new(hl_range))) 65 .splice(overlapping.clone(), iter::once(Node::new(hl_range)))
64 .collect::<Vec<_>>(); 66 .collect::<Vec<_>>();
65 self.nested[start].nested = nested; 67 self.nested[overlapping.start].nested = nested;
66 } 68 }
67 69
68 fn flatten(&self, acc: &mut Vec<HlRange>) { 70 fn flatten(&self, acc: &mut Vec<HlRange>) {
diff --git a/crates/ide/src/syntax_highlighting/injector.rs b/crates/ide/src/syntax_highlighting/injector.rs
index e8f17eb69..fd4025694 100644
--- a/crates/ide/src/syntax_highlighting/injector.rs
+++ b/crates/ide/src/syntax_highlighting/injector.rs
@@ -33,8 +33,7 @@ impl Injector {
33 &self.buf 33 &self.buf
34 } 34 }
35 pub(super) fn map_range_up(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ { 35 pub(super) fn map_range_up(&self, range: TextRange) -> impl Iterator<Item = TextRange> + '_ {
36 let (start, len) = equal_range_by(&self.ranges, |&(r, _)| ordering(r, range)); 36 equal_range_by(&self.ranges, |&(r, _)| ordering(r, range)).filter_map(move |i| {
37 (start..start + len).filter_map(move |i| {
38 let (target_range, delta) = self.ranges[i]; 37 let (target_range, delta) = self.ranges[i];
39 let intersection = target_range.intersect(range).unwrap(); 38 let intersection = target_range.intersect(range).unwrap();
40 Some(intersection + delta?) 39 Some(intersection + delta?)
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs
index be1c64b03..d68fe42b0 100644
--- a/crates/ide_db/src/defs.rs
+++ b/crates/ide_db/src/defs.rs
@@ -6,8 +6,8 @@
6// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). 6// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06).
7 7
8use hir::{ 8use hir::{
9 db::HirDatabase, ConstParam, Crate, Field, HasVisibility, Impl, Label, LifetimeParam, Local, 9 db::HirDatabase, Crate, Field, GenericParam, HasVisibility, Impl, Label, Local, MacroDef,
10 MacroDef, Module, ModuleDef, Name, PathResolution, Semantics, TypeParam, Visibility, 10 Module, ModuleDef, Name, PathResolution, Semantics, Visibility,
11}; 11};
12use syntax::{ 12use syntax::{
13 ast::{self, AstNode}, 13 ast::{self, AstNode},
@@ -24,9 +24,7 @@ pub enum Definition {
24 ModuleDef(ModuleDef), 24 ModuleDef(ModuleDef),
25 SelfType(Impl), 25 SelfType(Impl),
26 Local(Local), 26 Local(Local),
27 TypeParam(TypeParam), 27 GenericParam(GenericParam),
28 LifetimeParam(LifetimeParam),
29 ConstParam(ConstParam),
30 Label(Label), 28 Label(Label),
31} 29}
32 30
@@ -38,9 +36,7 @@ impl Definition {
38 Definition::ModuleDef(it) => it.module(db), 36 Definition::ModuleDef(it) => it.module(db),
39 Definition::SelfType(it) => Some(it.module(db)), 37 Definition::SelfType(it) => Some(it.module(db)),
40 Definition::Local(it) => Some(it.module(db)), 38 Definition::Local(it) => Some(it.module(db)),
41 Definition::TypeParam(it) => Some(it.module(db)), 39 Definition::GenericParam(it) => Some(it.module(db)),
42 Definition::LifetimeParam(it) => Some(it.module(db)),
43 Definition::ConstParam(it) => Some(it.module(db)),
44 Definition::Label(it) => Some(it.module(db)), 40 Definition::Label(it) => Some(it.module(db)),
45 } 41 }
46 } 42 }
@@ -52,9 +48,7 @@ impl Definition {
52 Definition::ModuleDef(def) => def.definition_visibility(db), 48 Definition::ModuleDef(def) => def.definition_visibility(db),
53 Definition::SelfType(_) => None, 49 Definition::SelfType(_) => None,
54 Definition::Local(_) => None, 50 Definition::Local(_) => None,
55 Definition::TypeParam(_) => None, 51 Definition::GenericParam(_) => None,
56 Definition::LifetimeParam(_) => None,
57 Definition::ConstParam(_) => None,
58 Definition::Label(_) => None, 52 Definition::Label(_) => None,
59 } 53 }
60 } 54 }
@@ -80,9 +74,7 @@ impl Definition {
80 }, 74 },
81 Definition::SelfType(_) => return None, 75 Definition::SelfType(_) => return None,
82 Definition::Local(it) => it.name(db)?, 76 Definition::Local(it) => it.name(db)?,
83 Definition::TypeParam(it) => it.name(db), 77 Definition::GenericParam(it) => it.name(db),
84 Definition::LifetimeParam(it) => it.name(db),
85 Definition::ConstParam(it) => it.name(db),
86 Definition::Label(it) => it.name(db), 78 Definition::Label(it) => it.name(db),
87 }; 79 };
88 Some(name) 80 Some(name)
@@ -235,11 +227,11 @@ impl NameClass {
235 }, 227 },
236 ast::TypeParam(it) => { 228 ast::TypeParam(it) => {
237 let def = sema.to_def(&it)?; 229 let def = sema.to_def(&it)?;
238 Some(NameClass::Definition(Definition::TypeParam(def))) 230 Some(NameClass::Definition(Definition::GenericParam(def.into())))
239 }, 231 },
240 ast::ConstParam(it) => { 232 ast::ConstParam(it) => {
241 let def = sema.to_def(&it)?; 233 let def = sema.to_def(&it)?;
242 Some(NameClass::Definition(Definition::ConstParam(def))) 234 Some(NameClass::Definition(Definition::GenericParam(def.into())))
243 }, 235 },
244 _ => None, 236 _ => None,
245 } 237 }
@@ -257,7 +249,7 @@ impl NameClass {
257 match parent { 249 match parent {
258 ast::LifetimeParam(it) => { 250 ast::LifetimeParam(it) => {
259 let def = sema.to_def(&it)?; 251 let def = sema.to_def(&it)?;
260 Some(NameClass::Definition(Definition::LifetimeParam(def))) 252 Some(NameClass::Definition(Definition::GenericParam(def.into())))
261 }, 253 },
262 ast::Label(it) => { 254 ast::Label(it) => {
263 let def = sema.to_def(&it)?; 255 let def = sema.to_def(&it)?;
@@ -393,7 +385,8 @@ impl NameRefClass {
393 | SyntaxKind::WHERE_PRED 385 | SyntaxKind::WHERE_PRED
394 | SyntaxKind::REF_TYPE => sema 386 | SyntaxKind::REF_TYPE => sema
395 .resolve_lifetime_param(lifetime) 387 .resolve_lifetime_param(lifetime)
396 .map(Definition::LifetimeParam) 388 .map(GenericParam::LifetimeParam)
389 .map(Definition::GenericParam)
397 .map(NameRefClass::Definition), 390 .map(NameRefClass::Definition),
398 // lifetime bounds, as in the 'b in 'a: 'b aren't wrapped in TypeBound nodes so we gotta check 391 // lifetime bounds, as in the 'b in 'a: 'b aren't wrapped in TypeBound nodes so we gotta check
399 // if our lifetime is in a LifetimeParam without being the constrained lifetime 392 // if our lifetime is in a LifetimeParam without being the constrained lifetime
@@ -401,7 +394,8 @@ impl NameRefClass {
401 != Some(lifetime) => 394 != Some(lifetime) =>
402 { 395 {
403 sema.resolve_lifetime_param(lifetime) 396 sema.resolve_lifetime_param(lifetime)
404 .map(Definition::LifetimeParam) 397 .map(GenericParam::LifetimeParam)
398 .map(Definition::GenericParam)
405 .map(NameRefClass::Definition) 399 .map(NameRefClass::Definition)
406 } 400 }
407 _ => None, 401 _ => None,
@@ -422,10 +416,10 @@ impl From<PathResolution> for Definition {
422 Definition::ModuleDef(def) 416 Definition::ModuleDef(def)
423 } 417 }
424 PathResolution::Local(local) => Definition::Local(local), 418 PathResolution::Local(local) => Definition::Local(local),
425 PathResolution::TypeParam(par) => Definition::TypeParam(par), 419 PathResolution::TypeParam(par) => Definition::GenericParam(par.into()),
426 PathResolution::Macro(def) => Definition::Macro(def), 420 PathResolution::Macro(def) => Definition::Macro(def),
427 PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), 421 PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def),
428 PathResolution::ConstParam(par) => Definition::ConstParam(par), 422 PathResolution::ConstParam(par) => Definition::GenericParam(par.into()),
429 } 423 }
430 } 424 }
431} 425}
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 37b06027c..773bfbc2c 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -136,7 +136,7 @@ impl Definition {
136 return SearchScope::new(res); 136 return SearchScope::new(res);
137 } 137 }
138 138
139 if let Definition::LifetimeParam(param) = self { 139 if let Definition::GenericParam(hir::GenericParam::LifetimeParam(param)) = self {
140 let range = match param.parent(db) { 140 let range = match param.parent(db) {
141 hir::GenericDef::Function(it) => { 141 hir::GenericDef::Function(it) => {
142 it.source(db).and_then(|src| Some(src.value.syntax().text_range())) 142 it.source(db).and_then(|src| Some(src.value.syntax().text_range()))
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 5aacdb16e..13aab1451 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -152,13 +152,13 @@ where
152 left 152 left
153} 153}
154 154
155pub fn equal_range_by<T, F>(slice: &[T], mut key: F) -> (usize, usize) 155pub fn equal_range_by<T, F>(slice: &[T], mut key: F) -> ops::Range<usize>
156where 156where
157 F: FnMut(&T) -> Ordering, 157 F: FnMut(&T) -> Ordering,
158{ 158{
159 let start = partition_point(slice, |it| key(it) == Ordering::Less); 159 let start = partition_point(slice, |it| key(it) == Ordering::Less);
160 let len = partition_point(&slice[start..], |it| key(it) == Ordering::Equal); 160 let len = partition_point(&slice[start..], |it| key(it) == Ordering::Equal);
161 (start, len) 161 start..start + len
162} 162}
163 163
164pub struct JodChild(pub process::Child); 164pub struct JodChild(pub process::Child);