aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs11
-rw-r--r--crates/ra_ide_api/src/hover.rs5
-rw-r--r--crates/ra_ide_api/src/references.rs5
-rw-r--r--crates/ra_ide_api/src/references/classify.rs17
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs5
5 files changed, 22 insertions, 21 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 6c8387f6c..5b7fb3c15 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -1,5 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::Source;
3use ra_db::{FileId, SourceDatabase}; 4use ra_db::{FileId, SourceDatabase};
4use ra_syntax::{ 5use ra_syntax::{
5 algo::find_node_at_offset, 6 algo::find_node_at_offset,
@@ -21,7 +22,8 @@ pub(crate) fn goto_definition(
21 let parse = db.parse(position.file_id); 22 let parse = db.parse(position.file_id);
22 let syntax = parse.tree().syntax().clone(); 23 let syntax = parse.tree().syntax().clone();
23 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, position.offset) { 24 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, position.offset) {
24 let navs = reference_definition(db, position.file_id, &name_ref).to_vec(); 25 let navs =
26 reference_definition(db, Source::new(position.file_id.into(), &name_ref)).to_vec();
25 return Some(RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec())); 27 return Some(RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()));
26 } 28 }
27 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { 29 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) {
@@ -49,12 +51,11 @@ impl ReferenceResult {
49 51
50pub(crate) fn reference_definition( 52pub(crate) fn reference_definition(
51 db: &RootDatabase, 53 db: &RootDatabase,
52 file_id: FileId, 54 name_ref: Source<&ast::NameRef>,
53 name_ref: &ast::NameRef,
54) -> ReferenceResult { 55) -> ReferenceResult {
55 use self::ReferenceResult::*; 56 use self::ReferenceResult::*;
56 57
57 let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.kind); 58 let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind);
58 match name_kind { 59 match name_kind {
59 Some(Macro(mac)) => return Exact(mac.to_nav(db)), 60 Some(Macro(mac)) => return Exact(mac.to_nav(db)),
60 Some(Field(field)) => return Exact(field.to_nav(db)), 61 Some(Field(field)) => return Exact(field.to_nav(db)),
@@ -76,7 +77,7 @@ pub(crate) fn reference_definition(
76 }; 77 };
77 78
78 // Fallback index based approach: 79 // Fallback index based approach:
79 let navs = crate::symbol_index::index_resolve(db, name_ref) 80 let navs = crate::symbol_index::index_resolve(db, name_ref.ast)
80 .into_iter() 81 .into_iter()
81 .map(|s| s.to_nav(db)) 82 .map(|s| s.to_nav(db))
82 .collect(); 83 .collect();
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 92b4b1f79..cc25f4c37 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{Adt, HasSource, HirDisplay}; 3use hir::{Adt, HasSource, HirDisplay, Source};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5use ra_syntax::{ 5use ra_syntax::{
6 algo::{ancestors_at_offset, find_covering_element, find_node_at_offset}, 6 algo::{ancestors_at_offset, find_covering_element, find_node_at_offset},
@@ -171,7 +171,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
171 find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) 171 find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset)
172 { 172 {
173 let mut no_fallback = false; 173 let mut no_fallback = false;
174 if let Some(name_kind) = classify_name_ref(db, position.file_id, &name_ref).map(|d| d.kind) 174 if let Some(name_kind) =
175 classify_name_ref(db, Source::new(position.file_id.into(), &name_ref)).map(|d| d.kind)
175 { 176 {
176 res.extend(hover_text_from_name_kind(db, name_kind, &mut no_fallback)) 177 res.extend(hover_text_from_name_kind(db, name_kind, &mut no_fallback))
177 } 178 }
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index faa88d988..1af7e8a9f 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -14,6 +14,7 @@ mod name_definition;
14mod rename; 14mod rename;
15mod search_scope; 15mod search_scope;
16 16
17use hir::Source;
17use once_cell::unsync::Lazy; 18use once_cell::unsync::Lazy;
18use ra_db::{SourceDatabase, SourceDatabaseExt}; 19use ra_db::{SourceDatabase, SourceDatabaseExt};
19use ra_prof::profile; 20use ra_prof::profile;
@@ -114,7 +115,7 @@ fn find_name<'a>(
114 return Some(RangeInfo::new(range, (name.text().to_string(), def))); 115 return Some(RangeInfo::new(range, (name.text().to_string(), def)));
115 } 116 }
116 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?; 117 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
117 let def = classify_name_ref(db, position.file_id, &name_ref)?; 118 let def = classify_name_ref(db, Source::new(position.file_id.into(), &name_ref))?;
118 let range = name_ref.syntax().text_range(); 119 let range = name_ref.syntax().text_range();
119 Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) 120 Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
120} 121}
@@ -146,7 +147,7 @@ fn process_definition(
146 continue; 147 continue;
147 } 148 }
148 } 149 }
149 if let Some(d) = classify_name_ref(db, file_id, &name_ref) { 150 if let Some(d) = classify_name_ref(db, Source::new(file_id.into(), &name_ref)) {
150 if d == def { 151 if d == def {
151 refs.push(FileRange { file_id, range }); 152 refs.push(FileRange { file_id, range });
152 } 153 }
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index f12b58cb9..5ca9da15e 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -123,14 +123,12 @@ pub(crate) fn classify_name(
123 123
124pub(crate) fn classify_name_ref( 124pub(crate) fn classify_name_ref(
125 db: &RootDatabase, 125 db: &RootDatabase,
126 file_id: FileId, 126 name_ref: Source<&ast::NameRef>,
127 name_ref: &ast::NameRef,
128) -> Option<NameDefinition> { 127) -> Option<NameDefinition> {
129 let _p = profile("classify_name_ref"); 128 let _p = profile("classify_name_ref");
130 129
131 let parent = name_ref.syntax().parent()?; 130 let parent = name_ref.ast.syntax().parent()?;
132 let analyzer = 131 let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None);
133 SourceAnalyzer::new(db, hir::Source::new(file_id.into(), name_ref.syntax()), None);
134 132
135 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { 133 if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
136 tested_by!(goto_definition_works_for_methods); 134 tested_by!(goto_definition_works_for_methods);
@@ -150,17 +148,16 @@ pub(crate) fn classify_name_ref(
150 tested_by!(goto_definition_works_for_record_fields); 148 tested_by!(goto_definition_works_for_record_fields);
151 if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { 149 if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) {
152 let variant_def = analyzer.resolve_record_literal(&record_lit)?; 150 let variant_def = analyzer.resolve_record_literal(&record_lit)?;
153 let hir_path = Path::from_name_ref(name_ref); 151 let hir_path = Path::from_name_ref(name_ref.ast);
154 let hir_name = hir_path.as_ident()?; 152 let hir_name = hir_path.as_ident()?;
155 let field = variant_def.field(db, hir_name)?; 153 let field = variant_def.field(db, hir_name)?;
156 return Some(from_struct_field(db, field)); 154 return Some(from_struct_field(db, field));
157 } 155 }
158 } 156 }
159 157
160 let file_id = file_id.into(); 158 let ast = ModuleSource::from_child_node(db, name_ref.with_ast(&parent));
161 let ast = ModuleSource::from_child_node(db, Source::new(file_id, &parent));
162 // FIXME: find correct container and visibility for each case 159 // FIXME: find correct container and visibility for each case
163 let container = Module::from_definition(db, Source { file_id, ast })?; 160 let container = Module::from_definition(db, name_ref.with_ast(ast))?;
164 let visibility = None; 161 let visibility = None;
165 162
166 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 163 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
@@ -171,7 +168,7 @@ pub(crate) fn classify_name_ref(
171 } 168 }
172 } 169 }
173 170
174 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; 171 let path = name_ref.ast.syntax().ancestors().find_map(ast::Path::cast)?;
175 let resolved = analyzer.resolve_path(db, &path)?; 172 let resolved = analyzer.resolve_path(db, &path)?;
176 match resolved { 173 match resolved {
177 PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))), 174 PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))),
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index d53a759ee..584657ca2 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -2,7 +2,7 @@
2 2
3use rustc_hash::{FxHashMap, FxHashSet}; 3use rustc_hash::{FxHashMap, FxHashSet};
4 4
5use hir::{Mutability, Name}; 5use hir::{Mutability, Name, Source};
6use ra_db::SourceDatabase; 6use ra_db::SourceDatabase;
7use ra_prof::profile; 7use ra_prof::profile;
8use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T}; 8use ra_syntax::{ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T};
@@ -80,7 +80,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
80 } 80 }
81 81
82 let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); 82 let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap();
83 let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.kind); 83 let name_kind =
84 classify_name_ref(db, Source::new(file_id.into(), &name_ref)).map(|d| d.kind);
84 85
85 if let Some(Local(local)) = &name_kind { 86 if let Some(Local(local)) = &name_kind {
86 if let Some(name) = local.name(db) { 87 if let Some(name) = local.name(db) {