aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/hover.rs4
-rw-r--r--crates/ra_ide_api/src/references.rs2
-rw-r--r--crates/ra_ide_api/src/references/classify.rs38
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs3
4 files changed, 22 insertions, 25 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index cc25f4c37..c6d678c0c 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -193,7 +193,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
193 None 193 None
194 } 194 }
195 } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) { 195 } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) {
196 if let Some(name_kind) = classify_name(db, position.file_id, &name).map(|d| d.kind) { 196 if let Some(name_kind) =
197 classify_name(db, Source::new(position.file_id.into(), &name)).map(|d| d.kind)
198 {
197 let mut _b: bool = true; 199 let mut _b: bool = true;
198 res.extend(hover_text_from_name_kind(db, name_kind, &mut _b)); 200 res.extend(hover_text_from_name_kind(db, name_kind, &mut _b));
199 } 201 }
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index 1af7e8a9f..cb343e59a 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -110,7 +110,7 @@ fn find_name<'a>(
110 position: FilePosition, 110 position: FilePosition,
111) -> Option<RangeInfo<(String, NameDefinition)>> { 111) -> Option<RangeInfo<(String, NameDefinition)>> {
112 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { 112 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) {
113 let def = classify_name(db, position.file_id, &name)?; 113 let def = classify_name(db, Source::new(position.file_id.into(), &name))?;
114 let range = name.syntax().text_range(); 114 let range = name.syntax().text_range();
115 return Some(RangeInfo::new(range, (name.text().to_string(), def))); 115 return Some(RangeInfo::new(range, (name.text().to_string(), def)));
116 } 116 }
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index 5ca9da15e..ea9d20e71 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -1,7 +1,6 @@
1//! Functions that are used to classify an element from its definition or reference. 1//! Functions that are used to classify an element from its definition or reference.
2 2
3use hir::{FromSource, Module, ModuleSource, Path, PathResolution, Source, SourceAnalyzer}; 3use hir::{FromSource, Module, ModuleSource, Path, PathResolution, Source, SourceAnalyzer};
4use ra_db::FileId;
5use ra_prof::profile; 4use ra_prof::profile;
6use ra_syntax::{ast, match_ast, AstNode}; 5use ra_syntax::{ast, match_ast, AstNode};
7use test_utils::tested_by; 6use test_utils::tested_by;
@@ -12,19 +11,14 @@ use super::{
12}; 11};
13use crate::db::RootDatabase; 12use crate::db::RootDatabase;
14 13
15pub(crate) fn classify_name( 14pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> {
16 db: &RootDatabase,
17 file_id: FileId,
18 name: &ast::Name,
19) -> Option<NameDefinition> {
20 let _p = profile("classify_name"); 15 let _p = profile("classify_name");
21 let parent = name.syntax().parent()?; 16 let parent = name.ast.syntax().parent()?;
22 let file_id = file_id.into();
23 17
24 match_ast! { 18 match_ast! {
25 match parent { 19 match parent {
26 ast::BindPat(it) => { 20 ast::BindPat(it) => {
27 let src = hir::Source { file_id, ast: it }; 21 let src = name.with_ast(it);
28 let local = hir::Local::from_source(db, src)?; 22 let local = hir::Local::from_source(db, src)?;
29 Some(NameDefinition { 23 Some(NameDefinition {
30 visibility: None, 24 visibility: None,
@@ -34,7 +28,7 @@ pub(crate) fn classify_name(
34 }, 28 },
35 ast::RecordFieldDef(it) => { 29 ast::RecordFieldDef(it) => {
36 let ast = hir::FieldSource::Named(it); 30 let ast = hir::FieldSource::Named(it);
37 let src = hir::Source { file_id, ast }; 31 let src = name.with_ast(ast);
38 let field = hir::StructField::from_source(db, src)?; 32 let field = hir::StructField::from_source(db, src)?;
39 Some(from_struct_field(db, field)) 33 Some(from_struct_field(db, field))
40 }, 34 },
@@ -42,42 +36,42 @@ pub(crate) fn classify_name(
42 let def = { 36 let def = {
43 if !it.has_semi() { 37 if !it.has_semi() {
44 let ast = hir::ModuleSource::Module(it); 38 let ast = hir::ModuleSource::Module(it);
45 let src = hir::Source { file_id, ast }; 39 let src = name.with_ast(ast);
46 hir::Module::from_definition(db, src) 40 hir::Module::from_definition(db, src)
47 } else { 41 } else {
48 let src = hir::Source { file_id, ast: it }; 42 let src = name.with_ast(it);
49 hir::Module::from_declaration(db, src) 43 hir::Module::from_declaration(db, src)
50 } 44 }
51 }?; 45 }?;
52 Some(from_module_def(db, def.into(), None)) 46 Some(from_module_def(db, def.into(), None))
53 }, 47 },
54 ast::StructDef(it) => { 48 ast::StructDef(it) => {
55 let src = hir::Source { file_id, ast: it }; 49 let src = name.with_ast(it);
56 let def = hir::Struct::from_source(db, src)?; 50 let def = hir::Struct::from_source(db, src)?;
57 Some(from_module_def(db, def.into(), None)) 51 Some(from_module_def(db, def.into(), None))
58 }, 52 },
59 ast::EnumDef(it) => { 53 ast::EnumDef(it) => {
60 let src = hir::Source { file_id, ast: it }; 54 let src = name.with_ast(it);
61 let def = hir::Enum::from_source(db, src)?; 55 let def = hir::Enum::from_source(db, src)?;
62 Some(from_module_def(db, def.into(), None)) 56 Some(from_module_def(db, def.into(), None))
63 }, 57 },
64 ast::TraitDef(it) => { 58 ast::TraitDef(it) => {
65 let src = hir::Source { file_id, ast: it }; 59 let src = name.with_ast(it);
66 let def = hir::Trait::from_source(db, src)?; 60 let def = hir::Trait::from_source(db, src)?;
67 Some(from_module_def(db, def.into(), None)) 61 Some(from_module_def(db, def.into(), None))
68 }, 62 },
69 ast::StaticDef(it) => { 63 ast::StaticDef(it) => {
70 let src = hir::Source { file_id, ast: it }; 64 let src = name.with_ast(it);
71 let def = hir::Static::from_source(db, src)?; 65 let def = hir::Static::from_source(db, src)?;
72 Some(from_module_def(db, def.into(), None)) 66 Some(from_module_def(db, def.into(), None))
73 }, 67 },
74 ast::EnumVariant(it) => { 68 ast::EnumVariant(it) => {
75 let src = hir::Source { file_id, ast: it }; 69 let src = name.with_ast(it);
76 let def = hir::EnumVariant::from_source(db, src)?; 70 let def = hir::EnumVariant::from_source(db, src)?;
77 Some(from_module_def(db, def.into(), None)) 71 Some(from_module_def(db, def.into(), None))
78 }, 72 },
79 ast::FnDef(it) => { 73 ast::FnDef(it) => {
80 let src = hir::Source { file_id, ast: it }; 74 let src = name.with_ast(it);
81 let def = hir::Function::from_source(db, src)?; 75 let def = hir::Function::from_source(db, src)?;
82 if parent.parent().and_then(ast::ItemList::cast).is_some() { 76 if parent.parent().and_then(ast::ItemList::cast).is_some() {
83 Some(from_assoc_item(db, def.into())) 77 Some(from_assoc_item(db, def.into()))
@@ -86,7 +80,7 @@ pub(crate) fn classify_name(
86 } 80 }
87 }, 81 },
88 ast::ConstDef(it) => { 82 ast::ConstDef(it) => {
89 let src = hir::Source { file_id, ast: it }; 83 let src = name.with_ast(it);
90 let def = hir::Const::from_source(db, src)?; 84 let def = hir::Const::from_source(db, src)?;
91 if parent.parent().and_then(ast::ItemList::cast).is_some() { 85 if parent.parent().and_then(ast::ItemList::cast).is_some() {
92 Some(from_assoc_item(db, def.into())) 86 Some(from_assoc_item(db, def.into()))
@@ -95,7 +89,7 @@ pub(crate) fn classify_name(
95 } 89 }
96 }, 90 },
97 ast::TypeAliasDef(it) => { 91 ast::TypeAliasDef(it) => {
98 let src = hir::Source { file_id, ast: it }; 92 let src = name.with_ast(it);
99 let def = hir::TypeAlias::from_source(db, src)?; 93 let def = hir::TypeAlias::from_source(db, src)?;
100 if parent.parent().and_then(ast::ItemList::cast).is_some() { 94 if parent.parent().and_then(ast::ItemList::cast).is_some() {
101 Some(from_assoc_item(db, def.into())) 95 Some(from_assoc_item(db, def.into()))
@@ -104,11 +98,11 @@ pub(crate) fn classify_name(
104 } 98 }
105 }, 99 },
106 ast::MacroCall(it) => { 100 ast::MacroCall(it) => {
107 let src = hir::Source { file_id, ast: it}; 101 let src = name.with_ast(it);
108 let def = hir::MacroDef::from_source(db, src.clone())?; 102 let def = hir::MacroDef::from_source(db, src.clone())?;
109 103
110 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 104 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
111 let module = Module::from_definition(db, Source::new(file_id, module_src))?; 105 let module = Module::from_definition(db, src.with_ast(module_src))?;
112 106
113 Some(NameDefinition { 107 Some(NameDefinition {
114 visibility: None, 108 visibility: None,
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 584657ca2..2b653fe8f 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -94,7 +94,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
94 } 94 }
95 NAME => { 95 NAME => {
96 let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap(); 96 let name = node.as_node().cloned().and_then(ast::Name::cast).unwrap();
97 let name_kind = classify_name(db, file_id, &name).map(|d| d.kind); 97 let name_kind =
98 classify_name(db, Source::new(file_id.into(), &name)).map(|d| d.kind);
98 99
99 if let Some(Local(local)) = &name_kind { 100 if let Some(Local(local)) = &name_kind {
100 if let Some(name) = local.name(db) { 101 if let Some(name) = local.name(db) {