From 8b7f853cc19d0940ec542e10bc23aa78455bbb3b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 10 Nov 2019 00:32:00 +0300 Subject: Add hir::Local --- .../ra_ide_api/src/references/name_definition.rs | 38 ++-------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'crates/ra_ide_api/src/references/name_definition.rs') diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index 4580bc789..450f7ea9b 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs @@ -4,10 +4,9 @@ //! Note that the reference search is possible for not all of the classified items. use hir::{ - db::AstDatabase, Adt, AssocItem, DefWithBody, FromSource, HasSource, HirFileId, MacroDef, - Module, ModuleDef, StructField, Ty, VariantDef, + Adt, AssocItem, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, VariantDef, }; -use ra_syntax::{ast, ast::VisibilityOwner, match_ast, AstNode, AstPtr}; +use ra_syntax::{ast, ast::VisibilityOwner}; use crate::db::RootDatabase; @@ -18,8 +17,7 @@ pub enum NameKind { AssocItem(AssocItem), Def(ModuleDef), SelfType(Ty), - Pat((DefWithBody, AstPtr)), - SelfParam(AstPtr), + Local(Local), GenericParam(u32), } @@ -30,36 +28,6 @@ pub(crate) struct NameDefinition { pub kind: NameKind, } -pub(super) fn from_pat( - db: &RootDatabase, - file_id: HirFileId, - pat: AstPtr, -) -> Option { - let root = db.parse_or_expand(file_id)?; - let def = pat.to_node(&root).syntax().ancestors().find_map(|node| { - match_ast! { - match node { - ast::FnDef(it) => { - let src = hir::Source { file_id, ast: it }; - Some(hir::Function::from_source(db, src)?.into()) - }, - ast::ConstDef(it) => { - let src = hir::Source { file_id, ast: it }; - Some(hir::Const::from_source(db, src)?.into()) - }, - ast::StaticDef(it) => { - let src = hir::Source { file_id, ast: it }; - Some(hir::Static::from_source(db, src)?.into()) - }, - _ => None, - } - } - })?; - let kind = NameKind::Pat((def, pat)); - let container = def.module(db); - Some(NameDefinition { kind, container, visibility: None }) -} - pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { let container = item.module(db); let visibility = match item { -- cgit v1.2.3