diff options
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/display/navigation_target.rs | 14 | ||||
-rw-r--r-- | crates/ide/src/doc_links.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/goto_definition.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 16 | ||||
-rw-r--r-- | crates/ide/src/references.rs | 5 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlights.rs | 12 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/injector.rs | 3 |
8 files changed, 39 insertions, 27 deletions
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 | ||
390 | impl 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 | |||
392 | impl ToNav for hir::Local { | 400 | impl 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 939efa43f..e331f8886 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use hir::{ | 1 | use 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 | }; |
5 | use ide_db::base_db::SourceDatabase; | 5 | use ide_db::base_db::SourceDatabase; |
6 | use ide_db::{ | 6 | use ide_db::{ |
@@ -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/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 1a88975d2..20eccf3c6 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs | |||
@@ -328,8 +328,11 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
328 | } | 328 | } |
329 | }, | 329 | }, |
330 | Definition::SelfType(_) => HlTag::Symbol(SymbolKind::Impl), | 330 | Definition::SelfType(_) => HlTag::Symbol(SymbolKind::Impl), |
331 | Definition::TypeParam(_) => HlTag::Symbol(SymbolKind::TypeParam), | 331 | Definition::GenericParam(it) => match it { |
332 | Definition::ConstParam(_) => HlTag::Symbol(SymbolKind::ConstParam), | 332 | hir::GenericParam::TypeParam(_) => HlTag::Symbol(SymbolKind::TypeParam), |
333 | hir::GenericParam::ConstParam(_) => HlTag::Symbol(SymbolKind::ConstParam), | ||
334 | hir::GenericParam::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam), | ||
335 | }, | ||
333 | Definition::Local(local) => { | 336 | Definition::Local(local) => { |
334 | let tag = if local.is_param(db) { | 337 | let tag = if local.is_param(db) { |
335 | HlTag::Symbol(SymbolKind::ValueParam) | 338 | HlTag::Symbol(SymbolKind::ValueParam) |
@@ -345,7 +348,6 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
345 | } | 348 | } |
346 | return h; | 349 | return h; |
347 | } | 350 | } |
348 | Definition::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam), | ||
349 | Definition::Label(_) => HlTag::Symbol(SymbolKind::Label), | 351 | Definition::Label(_) => HlTag::Symbol(SymbolKind::Label), |
350 | } | 352 | } |
351 | .into() | 353 | .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?) |