From 42e3f97c300c24b6ff9ff96ad0c24d386d3a253b Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 23 Dec 2020 17:15:01 +0100 Subject: Support labels in reference search --- crates/ide/src/display/navigation_target.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'crates/ide/src/display/navigation_target.rs') diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index cd8ec54fa..6431e7d6d 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -5,7 +5,7 @@ use std::fmt; use either::Either; use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource}; use ide_db::{ - base_db::{FileId, SourceDatabase}, + base_db::{FileId, FileRange, SourceDatabase}, symbol_index::FileSymbolKind, }; use ide_db::{defs::Definition, RootDatabase}; @@ -28,6 +28,7 @@ pub enum SymbolKind { ValueParam, SelfParam, Local, + Label, Function, Const, Static, @@ -223,6 +224,7 @@ impl TryToNav for Definition { Definition::Local(it) => Some(it.to_nav(db)), Definition::TypeParam(it) => Some(it.to_nav(db)), Definition::LifetimeParam(it) => Some(it.to_nav(db)), + Definition::Label(it) => Some(it.to_nav(db)), } } } @@ -421,6 +423,27 @@ impl ToNav for hir::Local { } } +impl ToNav for hir::Label { + fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { + let src = self.source(db); + let node = src.value.syntax(); + let FileRange { file_id, range } = src.with_value(node).original_file_range(db); + let focus_range = + src.value.lifetime().and_then(|lt| lt.lifetime_ident_token()).map(|lt| lt.text_range()); + let name = self.name(db).to_string().into(); + NavigationTarget { + file_id, + name, + kind: Some(SymbolKind::Label), + full_range: range, + focus_range, + container_name: None, + description: None, + docs: None, + } + } +} + impl ToNav for hir::TypeParam { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.source(db); -- cgit v1.2.3