Only new-style classification

This commit is contained in:
Aleksey Kladov 2020-01-14 17:39:28 +01:00
parent 35bfeaf4af
commit 11d6b9dadd
5 changed files with 21 additions and 28 deletions

View File

@ -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)),

View File

@ -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<RangeIn
let mut res = HoverResult::new();
let mut sb = SourceBinder::new(db);
if let Some((range, name_kind)) = match_ast! {
match (token.value.parent()) {
ast::NameRef(name_ref) => {
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 @@ fn func(foo: i32) { if true { <|>foo; }; }
}
fn foo(bar:u32) {
let a = id!(ba<|>r);
}
}
",
&["u32"],
);

View File

@ -14,7 +14,7 @@ mod name_definition;
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 @@ use crate::{
};
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<RangeInfo<(String, NameDefinition)>> {
let mut sb = SourceBinder::new(db);
if let Some(name) = find_node_at_offset::<ast::Name>(&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::<ast::NameRef>(&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()

View File

@ -11,12 +11,7 @@ use super::{
};
use crate::db::RootDatabase;
pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Option<NameDefinition> {
let mut sb = SourceBinder::new(db);
classify_name2(&mut sb, name)
}
pub(crate) fn classify_name2(
pub(crate) fn classify_name(
sb: &mut SourceBinder<RootDatabase>,
name: InFile<&ast::Name>,
) -> Option<NameDefinition> {
@ -132,14 +127,6 @@ pub(crate) fn classify_name2(
}
pub(crate) fn classify_name_ref(
db: &RootDatabase,
name_ref: InFile<&ast::NameRef>,
) -> Option<NameDefinition> {
let mut sb = SourceBinder::new(db);
classify_name_ref2(&mut sb, name_ref)
}
pub(crate) fn classify_name_ref2(
sb: &mut SourceBinder<RootDatabase>,
name_ref: InFile<&ast::NameRef>,
) -> Option<NameDefinition> {

View File

@ -10,7 +10,7 @@ use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::
use crate::{
db::RootDatabase,
references::{
classify_name2, classify_name_ref2,
classify_name, classify_name_ref,
NameKind::{self, *},
},
FileId,
@ -110,7 +110,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
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 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
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) {