aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/display
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/display')
-rw-r--r--crates/ide/src/display/navigation_target.rs105
1 files changed, 50 insertions, 55 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 5dc3f4128..1fb26c226 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -211,12 +211,12 @@ impl TryToNav for Definition {
211 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { 211 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
212 match self { 212 match self {
213 Definition::Macro(it) => it.try_to_nav(db), 213 Definition::Macro(it) => it.try_to_nav(db),
214 Definition::Field(it) => Some(it.to_nav(db)), 214 Definition::Field(it) => it.try_to_nav(db),
215 Definition::ModuleDef(it) => it.try_to_nav(db), 215 Definition::ModuleDef(it) => it.try_to_nav(db),
216 Definition::SelfType(it) => Some(it.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) => Some(it.to_nav(db)), 218 Definition::TypeParam(it) => it.try_to_nav(db),
219 Definition::LifetimeParam(it) => Some(it.to_nav(db)), 219 Definition::LifetimeParam(it) => it.try_to_nav(db),
220 Definition::Label(it) => Some(it.to_nav(db)), 220 Definition::Label(it) => Some(it.to_nav(db)),
221 Definition::ConstParam(it) => Some(it.to_nav(db)), 221 Definition::ConstParam(it) => Some(it.to_nav(db)),
222 } 222 }
@@ -225,18 +225,17 @@ impl TryToNav for Definition {
225 225
226impl TryToNav for hir::ModuleDef { 226impl TryToNav for hir::ModuleDef {
227 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { 227 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
228 let res = match self { 228 match self {
229 hir::ModuleDef::Module(it) => it.to_nav(db), 229 hir::ModuleDef::Module(it) => Some(it.to_nav(db)),
230 hir::ModuleDef::Function(it) => it.to_nav(db), 230 hir::ModuleDef::Function(it) => it.try_to_nav(db),
231 hir::ModuleDef::Adt(it) => it.to_nav(db), 231 hir::ModuleDef::Adt(it) => it.try_to_nav(db),
232 hir::ModuleDef::Variant(it) => it.to_nav(db), 232 hir::ModuleDef::Variant(it) => it.try_to_nav(db),
233 hir::ModuleDef::Const(it) => it.to_nav(db), 233 hir::ModuleDef::Const(it) => it.try_to_nav(db),
234 hir::ModuleDef::Static(it) => it.to_nav(db), 234 hir::ModuleDef::Static(it) => it.try_to_nav(db),
235 hir::ModuleDef::Trait(it) => it.to_nav(db), 235 hir::ModuleDef::Trait(it) => it.try_to_nav(db),
236 hir::ModuleDef::TypeAlias(it) => it.to_nav(db), 236 hir::ModuleDef::TypeAlias(it) => it.try_to_nav(db),
237 hir::ModuleDef::BuiltinType(_) => return None, 237 hir::ModuleDef::BuiltinType(_) => None,
238 }; 238 }
239 Some(res)
240 } 239 }
241} 240}
242 241
@@ -271,14 +270,13 @@ impl ToNavFromAst for hir::Trait {
271 const KIND: SymbolKind = SymbolKind::Trait; 270 const KIND: SymbolKind = SymbolKind::Trait;
272} 271}
273 272
274impl<D> ToNav for D 273impl<D> TryToNav for D
275where 274where
276 D: HasSource + ToNavFromAst + Copy + HasAttrs, 275 D: HasSource + ToNavFromAst + Copy + HasAttrs,
277 D::Ast: ast::NameOwner + ShortLabel, 276 D::Ast: ast::NameOwner + ShortLabel,
278{ 277{
279 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 278 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
280 #[allow(deprecated)] 279 let src = self.source(db)?;
281 let src = self.source_old(db);
282 let mut res = NavigationTarget::from_named( 280 let mut res = NavigationTarget::from_named(
283 db, 281 db,
284 src.as_ref().map(|it| it as &dyn ast::NameOwner), 282 src.as_ref().map(|it| it as &dyn ast::NameOwner),
@@ -286,7 +284,7 @@ where
286 ); 284 );
287 res.docs = self.docs(db); 285 res.docs = self.docs(db);
288 res.description = src.value.short_label(); 286 res.description = src.value.short_label();
289 res 287 Some(res)
290 } 288 }
291} 289}
292 290
@@ -305,10 +303,9 @@ impl ToNav for hir::Module {
305 } 303 }
306} 304}
307 305
308impl ToNav for hir::Impl { 306impl TryToNav for hir::Impl {
309 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 307 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
310 #[allow(deprecated)] 308 let src = self.source(db)?;
311 let src = self.source_old(db);
312 let derive_attr = self.is_builtin_derive(db); 309 let derive_attr = self.is_builtin_derive(db);
313 let frange = if let Some(item) = &derive_attr { 310 let frange = if let Some(item) = &derive_attr {
314 item.syntax().original_file_range(db) 311 item.syntax().original_file_range(db)
@@ -321,22 +318,21 @@ impl ToNav for hir::Impl {
321 src.value.self_ty().map(|ty| src.with_value(ty.syntax()).original_file_range(db).range) 318 src.value.self_ty().map(|ty| src.with_value(ty.syntax()).original_file_range(db).range)
322 }; 319 };
323 320
324 NavigationTarget::from_syntax( 321 Some(NavigationTarget::from_syntax(
325 frange.file_id, 322 frange.file_id,
326 "impl".into(), 323 "impl".into(),
327 focus_range, 324 focus_range,
328 frange.range, 325 frange.range,
329 SymbolKind::Impl, 326 SymbolKind::Impl,
330 ) 327 ))
331 } 328 }
332} 329}
333 330
334impl ToNav for hir::Field { 331impl TryToNav for hir::Field {
335 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 332 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
336 #[allow(deprecated)] 333 let src = self.source(db)?;
337 let src = self.source_old(db);
338 334
339 match &src.value { 335 let field_source = match &src.value {
340 FieldSource::Named(it) => { 336 FieldSource::Named(it) => {
341 let mut res = 337 let mut res =
342 NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field); 338 NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field);
@@ -354,7 +350,8 @@ impl ToNav for hir::Field {
354 SymbolKind::Field, 350 SymbolKind::Field,
355 ) 351 )
356 } 352 }
357 } 353 };
354 Some(field_source)
358 } 355 }
359} 356}
360 357
@@ -372,22 +369,22 @@ impl TryToNav for hir::MacroDef {
372 } 369 }
373} 370}
374 371
375impl ToNav for hir::Adt { 372impl TryToNav for hir::Adt {
376 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 373 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
377 match self { 374 match self {
378 hir::Adt::Struct(it) => it.to_nav(db), 375 hir::Adt::Struct(it) => it.try_to_nav(db),
379 hir::Adt::Union(it) => it.to_nav(db), 376 hir::Adt::Union(it) => it.try_to_nav(db),
380 hir::Adt::Enum(it) => it.to_nav(db), 377 hir::Adt::Enum(it) => it.try_to_nav(db),
381 } 378 }
382 } 379 }
383} 380}
384 381
385impl ToNav for hir::AssocItem { 382impl TryToNav for hir::AssocItem {
386 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 383 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
387 match self { 384 match self {
388 AssocItem::Function(it) => it.to_nav(db), 385 AssocItem::Function(it) => it.try_to_nav(db),
389 AssocItem::Const(it) => it.to_nav(db), 386 AssocItem::Const(it) => it.try_to_nav(db),
390 AssocItem::TypeAlias(it) => it.to_nav(db), 387 AssocItem::TypeAlias(it) => it.try_to_nav(db),
391 } 388 }
392 } 389 }
393} 390}
@@ -441,10 +438,9 @@ impl ToNav for hir::Label {
441 } 438 }
442} 439}
443 440
444impl ToNav for hir::TypeParam { 441impl TryToNav for hir::TypeParam {
445 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 442 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
446 #[allow(deprecated)] 443 let src = self.source(db)?;
447 let src = self.source_old(db);
448 let full_range = match &src.value { 444 let full_range = match &src.value {
449 Either::Left(it) => it.syntax().text_range(), 445 Either::Left(it) => it.syntax().text_range(),
450 Either::Right(it) => it.syntax().text_range(), 446 Either::Right(it) => it.syntax().text_range(),
@@ -453,7 +449,7 @@ impl ToNav for hir::TypeParam {
453 Either::Left(_) => None, 449 Either::Left(_) => None,
454 Either::Right(it) => it.name().map(|it| it.syntax().text_range()), 450 Either::Right(it) => it.name().map(|it| it.syntax().text_range()),
455 }; 451 };
456 NavigationTarget { 452 Some(NavigationTarget {
457 file_id: src.file_id.original_file(db), 453 file_id: src.file_id.original_file(db),
458 name: self.name(db).to_string().into(), 454 name: self.name(db).to_string().into(),
459 kind: Some(SymbolKind::TypeParam), 455 kind: Some(SymbolKind::TypeParam),
@@ -462,16 +458,15 @@ impl ToNav for hir::TypeParam {
462 container_name: None, 458 container_name: None,
463 description: None, 459 description: None,
464 docs: None, 460 docs: None,
465 } 461 })
466 } 462 }
467} 463}
468 464
469impl ToNav for hir::LifetimeParam { 465impl TryToNav for hir::LifetimeParam {
470 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 466 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
471 #[allow(deprecated)] 467 let src = self.source(db)?;
472 let src = self.source_old(db);
473 let full_range = src.value.syntax().text_range(); 468 let full_range = src.value.syntax().text_range();
474 NavigationTarget { 469 Some(NavigationTarget {
475 file_id: src.file_id.original_file(db), 470 file_id: src.file_id.original_file(db),
476 name: self.name(db).to_string().into(), 471 name: self.name(db).to_string().into(),
477 kind: Some(SymbolKind::LifetimeParam), 472 kind: Some(SymbolKind::LifetimeParam),
@@ -480,7 +475,7 @@ impl ToNav for hir::LifetimeParam {
480 container_name: None, 475 container_name: None,
481 description: None, 476 description: None,
482 docs: None, 477 docs: None,
483 } 478 })
484 } 479 }
485} 480}
486 481