mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Only new-style classification
This commit is contained in:
parent
35bfeaf4af
commit
11d6b9dadd
5 changed files with 21 additions and 28 deletions
|
@ -1,6 +1,6 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use hir::{db::AstDatabase, InFile};
|
use hir::{db::AstDatabase, InFile, SourceBinder};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
ast::{self, DocCommentsOwner},
|
ast::{self, DocCommentsOwner},
|
||||||
match_ast, AstNode,
|
match_ast, AstNode,
|
||||||
|
@ -72,7 +72,8 @@ pub(crate) fn reference_definition(
|
||||||
) -> ReferenceResult {
|
) -> ReferenceResult {
|
||||||
use self::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 {
|
match name_kind {
|
||||||
Some(Macro(it)) => return Exact(it.to_nav(db)),
|
Some(Macro(it)) => return Exact(it.to_nav(db)),
|
||||||
Some(Field(it)) => return Exact(it.to_nav(db)),
|
Some(Field(it)) => return Exact(it.to_nav(db)),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! FIXME: write short doc here
|
//! 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_db::SourceDatabase;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
algo::find_covering_element,
|
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 res = HoverResult::new();
|
||||||
|
|
||||||
|
let mut sb = SourceBinder::new(db);
|
||||||
if let Some((range, name_kind)) = match_ast! {
|
if let Some((range, name_kind)) = match_ast! {
|
||||||
match (token.value.parent()) {
|
match (token.value.parent()) {
|
||||||
ast::NameRef(name_ref) => {
|
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) => {
|
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,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
@ -742,7 +743,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
||||||
}
|
}
|
||||||
fn foo(bar:u32) {
|
fn foo(bar:u32) {
|
||||||
let a = id!(ba<|>r);
|
let a = id!(ba<|>r);
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
&["u32"],
|
&["u32"],
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,7 +14,7 @@ mod name_definition;
|
||||||
mod rename;
|
mod rename;
|
||||||
mod search_scope;
|
mod search_scope;
|
||||||
|
|
||||||
use hir::InFile;
|
use hir::{InFile, SourceBinder};
|
||||||
use once_cell::unsync::Lazy;
|
use once_cell::unsync::Lazy;
|
||||||
use ra_db::{SourceDatabase, SourceDatabaseExt};
|
use ra_db::{SourceDatabase, SourceDatabaseExt};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
|
@ -29,7 +29,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use self::{
|
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},
|
name_definition::{NameDefinition, NameKind},
|
||||||
rename::rename,
|
rename::rename,
|
||||||
};
|
};
|
||||||
|
@ -171,13 +171,14 @@ fn find_name(
|
||||||
syntax: &SyntaxNode,
|
syntax: &SyntaxNode,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Option<RangeInfo<(String, NameDefinition)>> {
|
) -> Option<RangeInfo<(String, NameDefinition)>> {
|
||||||
|
let mut sb = SourceBinder::new(db);
|
||||||
if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) {
|
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();
|
let range = name.syntax().text_range();
|
||||||
return Some(RangeInfo::new(range, (name.text().to_string(), def)));
|
return Some(RangeInfo::new(range, (name.text().to_string(), def)));
|
||||||
}
|
}
|
||||||
let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
|
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();
|
let range = name_ref.syntax().text_range();
|
||||||
Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
|
Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
|
||||||
}
|
}
|
||||||
|
@ -209,7 +210,10 @@ fn process_definition(
|
||||||
continue;
|
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 {
|
if d == def {
|
||||||
let kind = if name_ref
|
let kind = if name_ref
|
||||||
.syntax()
|
.syntax()
|
||||||
|
|
|
@ -11,12 +11,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use crate::db::RootDatabase;
|
use crate::db::RootDatabase;
|
||||||
|
|
||||||
pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Option<NameDefinition> {
|
pub(crate) fn classify_name(
|
||||||
let mut sb = SourceBinder::new(db);
|
|
||||||
classify_name2(&mut sb, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn classify_name2(
|
|
||||||
sb: &mut SourceBinder<RootDatabase>,
|
sb: &mut SourceBinder<RootDatabase>,
|
||||||
name: InFile<&ast::Name>,
|
name: InFile<&ast::Name>,
|
||||||
) -> Option<NameDefinition> {
|
) -> Option<NameDefinition> {
|
||||||
|
@ -132,14 +127,6 @@ pub(crate) fn classify_name2(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn classify_name_ref(
|
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>,
|
sb: &mut SourceBinder<RootDatabase>,
|
||||||
name_ref: InFile<&ast::NameRef>,
|
name_ref: InFile<&ast::NameRef>,
|
||||||
) -> Option<NameDefinition> {
|
) -> Option<NameDefinition> {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::
|
||||||
use crate::{
|
use crate::{
|
||||||
db::RootDatabase,
|
db::RootDatabase,
|
||||||
references::{
|
references::{
|
||||||
classify_name2, classify_name_ref2,
|
classify_name, classify_name_ref,
|
||||||
NameKind::{self, *},
|
NameKind::{self, *},
|
||||||
},
|
},
|
||||||
FileId,
|
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 if node.ancestors().any(|it| it.kind() == ATTR) => continue,
|
||||||
NAME_REF => {
|
NAME_REF => {
|
||||||
let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap();
|
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);
|
.map(|d| d.kind);
|
||||||
match name_kind {
|
match name_kind {
|
||||||
Some(name_kind) => {
|
Some(name_kind) => {
|
||||||
|
@ -131,7 +131,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
||||||
NAME => {
|
NAME => {
|
||||||
let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap();
|
let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap();
|
||||||
let name_kind =
|
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(Local(local)) = &name_kind {
|
||||||
if let Some(name) = local.name(db) {
|
if let Some(name) = local.name(db) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue