From 11d6b9daddfa9275c507a5e246541c28a78023ab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Jan 2020 17:39:28 +0100 Subject: [PATCH] Only new-style classification --- crates/ra_ide/src/goto_definition.rs | 5 +++-- crates/ra_ide/src/hover.rs | 9 +++++---- crates/ra_ide/src/references.rs | 14 +++++++++----- crates/ra_ide/src/references/classify.rs | 15 +-------------- crates/ra_ide/src/syntax_highlighting.rs | 6 +++--- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 79d332e8cea..f2b5af32141 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{db::AstDatabase, InFile}; +use hir::{db::AstDatabase, InFile, SourceBinder}; use ra_syntax::{ ast::{self, DocCommentsOwner}, match_ast, AstNode, @@ -72,7 +72,8 @@ pub(crate) fn reference_definition( ) -> ReferenceResult { use self::ReferenceResult::*; - let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); + let mut sb = SourceBinder::new(db); + let name_kind = classify_name_ref(&mut sb, name_ref).map(|d| d.kind); match name_kind { Some(Macro(it)) => return Exact(it.to_nav(db)), Some(Field(it)) => return Exact(it.to_nav(db)), diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 5548681f179..6661e5cb22c 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{db::AstDatabase, Adt, HasSource, HirDisplay}; +use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, SourceBinder}; use ra_db::SourceDatabase; use ra_syntax::{ algo::find_covering_element, @@ -152,13 +152,14 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option { - classify_name_ref(db, token.with_value(&name_ref)).map(|d| (name_ref.syntax().text_range(), d.kind)) + classify_name_ref(&mut sb, token.with_value(&name_ref)).map(|d| (name_ref.syntax().text_range(), d.kind)) }, ast::Name(name) => { - classify_name(db, token.with_value(&name)).map(|d| (name.syntax().text_range(), d.kind)) + classify_name(&mut sb, token.with_value(&name)).map(|d| (name.syntax().text_range(), d.kind)) }, _ => None, } @@ -742,7 +743,7 @@ macro_rules! id { } fn foo(bar:u32) { let a = id!(ba<|>r); - } + } ", &["u32"], ); diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 2b74d76538e..b0e5fddcccd 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -14,7 +14,7 @@ mod rename; mod search_scope; -use hir::InFile; +use hir::{InFile, SourceBinder}; use once_cell::unsync::Lazy; use ra_db::{SourceDatabase, SourceDatabaseExt}; use ra_prof::profile; @@ -29,7 +29,7 @@ }; pub(crate) use self::{ - classify::{classify_name, classify_name2, classify_name_ref, classify_name_ref2}, + classify::{classify_name, classify_name_ref}, name_definition::{NameDefinition, NameKind}, rename::rename, }; @@ -171,13 +171,14 @@ fn find_name( syntax: &SyntaxNode, position: FilePosition, ) -> Option> { + let mut sb = SourceBinder::new(db); if let Some(name) = find_node_at_offset::(&syntax, position.offset) { - let def = classify_name(db, InFile::new(position.file_id.into(), &name))?; + let def = classify_name(&mut sb, InFile::new(position.file_id.into(), &name))?; let range = name.syntax().text_range(); return Some(RangeInfo::new(range, (name.text().to_string(), def))); } let name_ref = find_node_at_offset::(&syntax, position.offset)?; - let def = classify_name_ref(db, InFile::new(position.file_id.into(), &name_ref))?; + let def = classify_name_ref(&mut sb, InFile::new(position.file_id.into(), &name_ref))?; let range = name_ref.syntax().text_range(); Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) } @@ -209,7 +210,10 @@ fn process_definition( continue; } } - if let Some(d) = classify_name_ref(db, InFile::new(file_id.into(), &name_ref)) { + // FIXME: reuse sb + let mut sb = SourceBinder::new(db); + if let Some(d) = classify_name_ref(&mut sb, InFile::new(file_id.into(), &name_ref)) + { if d == def { let kind = if name_ref .syntax() diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 9778ca53651..4a6e11e27ec 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs @@ -11,12 +11,7 @@ }; use crate::db::RootDatabase; -pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Option { - let mut sb = SourceBinder::new(db); - classify_name2(&mut sb, name) -} - -pub(crate) fn classify_name2( +pub(crate) fn classify_name( sb: &mut SourceBinder, name: InFile<&ast::Name>, ) -> Option { @@ -132,14 +127,6 @@ pub(crate) fn classify_name2( } pub(crate) fn classify_name_ref( - db: &RootDatabase, - name_ref: InFile<&ast::NameRef>, -) -> Option { - let mut sb = SourceBinder::new(db); - classify_name_ref2(&mut sb, name_ref) -} - -pub(crate) fn classify_name_ref2( sb: &mut SourceBinder, name_ref: InFile<&ast::NameRef>, ) -> Option { diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 0cacc58d453..e514f9a2c17 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -10,7 +10,7 @@ use crate::{ db::RootDatabase, references::{ - classify_name2, classify_name_ref2, + classify_name, classify_name_ref, NameKind::{self, *}, }, FileId, @@ -110,7 +110,7 @@ fn hash(x: T) -> u64 { NAME_REF if node.ancestors().any(|it| it.kind() == ATTR) => continue, NAME_REF => { let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); - let name_kind = classify_name_ref2(&mut sb, InFile::new(file_id.into(), &name_ref)) + let name_kind = classify_name_ref(&mut sb, InFile::new(file_id.into(), &name_ref)) .map(|d| d.kind); match name_kind { Some(name_kind) => { @@ -131,7 +131,7 @@ fn hash(x: T) -> u64 { NAME => { let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap(); let name_kind = - classify_name2(&mut sb, InFile::new(file_id.into(), &name)).map(|d| d.kind); + classify_name(&mut sb, InFile::new(file_id.into(), &name)).map(|d| d.kind); if let Some(Local(local)) = &name_kind { if let Some(name) = local.name(db) {