aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-01-14 16:39:28 +0000
committerAleksey Kladov <[email protected]>2020-01-15 15:52:28 +0000
commit11d6b9daddfa9275c507a5e246541c28a78023ab (patch)
tree1284a6dd8fe99e549c2bdba4198665b6e350910a /crates/ra_ide
parent35bfeaf4af4bcccf355f1e0e1a38547a2982a251 (diff)
Only new-style classification
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/goto_definition.rs5
-rw-r--r--crates/ra_ide/src/hover.rs9
-rw-r--r--crates/ra_ide/src/references.rs14
-rw-r--r--crates/ra_ide/src/references/classify.rs15
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs6
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 79d332e8c..f2b5af321 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{db::AstDatabase, InFile}; 3use hir::{db::AstDatabase, InFile, SourceBinder};
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, DocCommentsOwner}, 5 ast::{self, DocCommentsOwner},
6 match_ast, AstNode, 6 match_ast, AstNode,
@@ -72,7 +72,8 @@ pub(crate) fn reference_definition(
72) -> ReferenceResult { 72) -> ReferenceResult {
73 use self::ReferenceResult::*; 73 use self::ReferenceResult::*;
74 74
75 let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); 75 let mut sb = SourceBinder::new(db);
76 let name_kind = classify_name_ref(&mut sb, name_ref).map(|d| d.kind);
76 match name_kind { 77 match name_kind {
77 Some(Macro(it)) => return Exact(it.to_nav(db)), 78 Some(Macro(it)) => return Exact(it.to_nav(db)),
78 Some(Field(it)) => return Exact(it.to_nav(db)), 79 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 5548681f1..6661e5cb2 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{db::AstDatabase, Adt, HasSource, HirDisplay}; 3use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, SourceBinder};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5use ra_syntax::{ 5use ra_syntax::{
6 algo::find_covering_element, 6 algo::find_covering_element,
@@ -152,13 +152,14 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
152 152
153 let mut res = HoverResult::new(); 153 let mut res = HoverResult::new();
154 154
155 let mut sb = SourceBinder::new(db);
155 if let Some((range, name_kind)) = match_ast! { 156 if let Some((range, name_kind)) = match_ast! {
156 match (token.value.parent()) { 157 match (token.value.parent()) {
157 ast::NameRef(name_ref) => { 158 ast::NameRef(name_ref) => {
158 classify_name_ref(db, token.with_value(&name_ref)).map(|d| (name_ref.syntax().text_range(), d.kind)) 159 classify_name_ref(&mut sb, token.with_value(&name_ref)).map(|d| (name_ref.syntax().text_range(), d.kind))
159 }, 160 },
160 ast::Name(name) => { 161 ast::Name(name) => {
161 classify_name(db, token.with_value(&name)).map(|d| (name.syntax().text_range(), d.kind)) 162 classify_name(&mut sb, token.with_value(&name)).map(|d| (name.syntax().text_range(), d.kind))
162 }, 163 },
163 _ => None, 164 _ => None,
164 } 165 }
@@ -742,7 +743,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
742 } 743 }
743 fn foo(bar:u32) { 744 fn foo(bar:u32) {
744 let a = id!(ba<|>r); 745 let a = id!(ba<|>r);
745 } 746 }
746 ", 747 ",
747 &["u32"], 748 &["u32"],
748 ); 749 );
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 2b74d7653..b0e5fddcc 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -14,7 +14,7 @@ mod name_definition;
14mod rename; 14mod rename;
15mod search_scope; 15mod search_scope;
16 16
17use hir::InFile; 17use hir::{InFile, SourceBinder};
18use once_cell::unsync::Lazy; 18use once_cell::unsync::Lazy;
19use ra_db::{SourceDatabase, SourceDatabaseExt}; 19use ra_db::{SourceDatabase, SourceDatabaseExt};
20use ra_prof::profile; 20use ra_prof::profile;
@@ -29,7 +29,7 @@ use crate::{
29}; 29};
30 30
31pub(crate) use self::{ 31pub(crate) use self::{
32 classify::{classify_name, classify_name2, classify_name_ref, classify_name_ref2}, 32 classify::{classify_name, classify_name_ref},
33 name_definition::{NameDefinition, NameKind}, 33 name_definition::{NameDefinition, NameKind},
34 rename::rename, 34 rename::rename,
35}; 35};
@@ -171,13 +171,14 @@ fn find_name(
171 syntax: &SyntaxNode, 171 syntax: &SyntaxNode,
172 position: FilePosition, 172 position: FilePosition,
173) -> Option<RangeInfo<(String, NameDefinition)>> { 173) -> Option<RangeInfo<(String, NameDefinition)>> {
174 let mut sb = SourceBinder::new(db);
174 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { 175 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) {
175 let def = classify_name(db, InFile::new(position.file_id.into(), &name))?; 176 let def = classify_name(&mut sb, InFile::new(position.file_id.into(), &name))?;
176 let range = name.syntax().text_range(); 177 let range = name.syntax().text_range();
177 return Some(RangeInfo::new(range, (name.text().to_string(), def))); 178 return Some(RangeInfo::new(range, (name.text().to_string(), def)));
178 } 179 }
179 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?; 180 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
180 let def = classify_name_ref(db, InFile::new(position.file_id.into(), &name_ref))?; 181 let def = classify_name_ref(&mut sb, InFile::new(position.file_id.into(), &name_ref))?;
181 let range = name_ref.syntax().text_range(); 182 let range = name_ref.syntax().text_range();
182 Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) 183 Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
183} 184}
@@ -209,7 +210,10 @@ fn process_definition(
209 continue; 210 continue;
210 } 211 }
211 } 212 }
212 if let Some(d) = classify_name_ref(db, InFile::new(file_id.into(), &name_ref)) { 213 // FIXME: reuse sb
214 let mut sb = SourceBinder::new(db);
215 if let Some(d) = classify_name_ref(&mut sb, InFile::new(file_id.into(), &name_ref))
216 {
213 if d == def { 217 if d == def {
214 let kind = if name_ref 218 let kind = if name_ref
215 .syntax() 219 .syntax()
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
index 9778ca536..4a6e11e27 100644
--- a/crates/ra_ide/src/references/classify.rs
+++ b/crates/ra_ide/src/references/classify.rs
@@ -11,12 +11,7 @@ use super::{
11}; 11};
12use crate::db::RootDatabase; 12use crate::db::RootDatabase;
13 13
14pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Option<NameDefinition> { 14pub(crate) fn classify_name(
15 let mut sb = SourceBinder::new(db);
16 classify_name2(&mut sb, name)
17}
18
19pub(crate) fn classify_name2(
20 sb: &mut SourceBinder<RootDatabase>, 15 sb: &mut SourceBinder<RootDatabase>,
21 name: InFile<&ast::Name>, 16 name: InFile<&ast::Name>,
22) -> Option<NameDefinition> { 17) -> Option<NameDefinition> {
@@ -132,14 +127,6 @@ pub(crate) fn classify_name2(
132} 127}
133 128
134pub(crate) fn classify_name_ref( 129pub(crate) fn classify_name_ref(
135 db: &RootDatabase,
136 name_ref: InFile<&ast::NameRef>,
137) -> Option<NameDefinition> {
138 let mut sb = SourceBinder::new(db);
139 classify_name_ref2(&mut sb, name_ref)
140}
141
142pub(crate) fn classify_name_ref2(
143 sb: &mut SourceBinder<RootDatabase>, 130 sb: &mut SourceBinder<RootDatabase>,
144 name_ref: InFile<&ast::NameRef>, 131 name_ref: InFile<&ast::NameRef>,
145) -> Option<NameDefinition> { 132) -> Option<NameDefinition> {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 0cacc58d4..e514f9a2c 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -10,7 +10,7 @@ use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::
10use crate::{ 10use crate::{
11 db::RootDatabase, 11 db::RootDatabase,
12 references::{ 12 references::{
13 classify_name2, classify_name_ref2, 13 classify_name, classify_name_ref,
14 NameKind::{self, *}, 14 NameKind::{self, *},
15 }, 15 },
16 FileId, 16 FileId,
@@ -110,7 +110,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
110 NAME_REF if node.ancestors().any(|it| it.kind() == ATTR) => continue, 110 NAME_REF if node.ancestors().any(|it| it.kind() == ATTR) => continue,
111 NAME_REF => { 111 NAME_REF => {
112 let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); 112 let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap();
113 let name_kind = classify_name_ref2(&mut sb, InFile::new(file_id.into(), &name_ref)) 113 let name_kind = classify_name_ref(&mut sb, InFile::new(file_id.into(), &name_ref))
114 .map(|d| d.kind); 114 .map(|d| d.kind);
115 match name_kind { 115 match name_kind {
116 Some(name_kind) => { 116 Some(name_kind) => {
@@ -131,7 +131,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
131 NAME => { 131 NAME => {
132 let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap(); 132 let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap();
133 let name_kind = 133 let name_kind =
134 classify_name2(&mut sb, InFile::new(file_id.into(), &name)).map(|d| d.kind); 134 classify_name(&mut sb, InFile::new(file_id.into(), &name)).map(|d| d.kind);
135 135
136 if let Some(Local(local)) = &name_kind { 136 if let Some(Local(local)) = &name_kind {
137 if let Some(name) = local.name(db) { 137 if let Some(name) = local.name(db) {