aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs2
-rw-r--r--crates/ra_ide_api/src/references/classify.rs20
-rw-r--r--crates/ra_ide_api/src/references/name_definition.rs8
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs3
4 files changed, 18 insertions, 15 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 1b4ad3a59..582617286 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -54,7 +54,7 @@ pub(crate) fn reference_definition(
54) -> ReferenceResult { 54) -> ReferenceResult {
55 use self::ReferenceResult::*; 55 use self::ReferenceResult::*;
56 56
57 let name_kind = classify_name_ref(db, file_id, &name_ref).and_then(|d| Some(d.item)); 57 let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.item);
58 match name_kind { 58 match name_kind {
59 Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)), 59 Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)),
60 Some(Field(field)) => return Exact(NavigationTarget::from_field(db, field)), 60 Some(Field(field)) => return Exact(NavigationTarget::from_field(db, field)),
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index 2ba1cf71c..5cb194c0e 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -32,32 +32,32 @@ pub(crate) fn classify_name(
32 let ast = hir::ModuleSource::Module(it); 32 let ast = hir::ModuleSource::Module(it);
33 let src = hir::Source { file_id, ast }; 33 let src = hir::Source { file_id, ast };
34 let def = hir::Module::from_definition(db, src)?; 34 let def = hir::Module::from_definition(db, src)?;
35 Some(from_module_def(db, def.into())) 35 Some(from_module_def(db, def.into(), None))
36 }, 36 },
37 ast::StructDef(it) => { 37 ast::StructDef(it) => {
38 let src = hir::Source { file_id, ast: it }; 38 let src = hir::Source { file_id, ast: it };
39 let def = hir::Struct::from_source(db, src)?; 39 let def = hir::Struct::from_source(db, src)?;
40 Some(from_module_def(db, def.into())) 40 Some(from_module_def(db, def.into(), None))
41 }, 41 },
42 ast::EnumDef(it) => { 42 ast::EnumDef(it) => {
43 let src = hir::Source { file_id, ast: it }; 43 let src = hir::Source { file_id, ast: it };
44 let def = hir::Enum::from_source(db, src)?; 44 let def = hir::Enum::from_source(db, src)?;
45 Some(from_module_def(db, def.into())) 45 Some(from_module_def(db, def.into(), None))
46 }, 46 },
47 ast::TraitDef(it) => { 47 ast::TraitDef(it) => {
48 let src = hir::Source { file_id, ast: it }; 48 let src = hir::Source { file_id, ast: it };
49 let def = hir::Trait::from_source(db, src)?; 49 let def = hir::Trait::from_source(db, src)?;
50 Some(from_module_def(db, def.into())) 50 Some(from_module_def(db, def.into(), None))
51 }, 51 },
52 ast::StaticDef(it) => { 52 ast::StaticDef(it) => {
53 let src = hir::Source { file_id, ast: it }; 53 let src = hir::Source { file_id, ast: it };
54 let def = hir::Static::from_source(db, src)?; 54 let def = hir::Static::from_source(db, src)?;
55 Some(from_module_def(db, def.into())) 55 Some(from_module_def(db, def.into(), None))
56 }, 56 },
57 ast::EnumVariant(it) => { 57 ast::EnumVariant(it) => {
58 let src = hir::Source { file_id, ast: it }; 58 let src = hir::Source { file_id, ast: it };
59 let def = hir::EnumVariant::from_source(db, src)?; 59 let def = hir::EnumVariant::from_source(db, src)?;
60 Some(from_module_def(db, def.into())) 60 Some(from_module_def(db, def.into(), None))
61 }, 61 },
62 ast::FnDef(it) => { 62 ast::FnDef(it) => {
63 let src = hir::Source { file_id, ast: it }; 63 let src = hir::Source { file_id, ast: it };
@@ -65,7 +65,7 @@ pub(crate) fn classify_name(
65 if parent.parent().and_then(ast::ItemList::cast).is_some() { 65 if parent.parent().and_then(ast::ItemList::cast).is_some() {
66 Some(from_assoc_item(db, def.into())) 66 Some(from_assoc_item(db, def.into()))
67 } else { 67 } else {
68 Some(from_module_def(db, def.into())) 68 Some(from_module_def(db, def.into(), None))
69 } 69 }
70 }, 70 },
71 ast::ConstDef(it) => { 71 ast::ConstDef(it) => {
@@ -74,7 +74,7 @@ pub(crate) fn classify_name(
74 if parent.parent().and_then(ast::ItemList::cast).is_some() { 74 if parent.parent().and_then(ast::ItemList::cast).is_some() {
75 Some(from_assoc_item(db, def.into())) 75 Some(from_assoc_item(db, def.into()))
76 } else { 76 } else {
77 Some(from_module_def(db, def.into())) 77 Some(from_module_def(db, def.into(), None))
78 } 78 }
79 }, 79 },
80 ast::TypeAliasDef(it) => { 80 ast::TypeAliasDef(it) => {
@@ -83,7 +83,7 @@ pub(crate) fn classify_name(
83 if parent.parent().and_then(ast::ItemList::cast).is_some() { 83 if parent.parent().and_then(ast::ItemList::cast).is_some() {
84 Some(from_assoc_item(db, def.into())) 84 Some(from_assoc_item(db, def.into()))
85 } else { 85 } else {
86 Some(from_module_def(db, def.into())) 86 Some(from_module_def(db, def.into(), None))
87 } 87 }
88 }, 88 },
89 _ => None, 89 _ => None,
@@ -143,7 +143,7 @@ pub(crate) fn classify_name_ref(
143 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; 143 let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
144 let resolved = analyzer.resolve_path(db, &path)?; 144 let resolved = analyzer.resolve_path(db, &path)?;
145 match resolved { 145 match resolved {
146 Def(def) => Some(from_module_def(db, def)), 146 Def(def) => Some(from_module_def(db, def, Some(container))),
147 AssocItem(item) => Some(from_assoc_item(db, item)), 147 AssocItem(item) => Some(from_assoc_item(db, item)),
148 LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat), 148 LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat),
149 LocalBinding(Either::B(par)) => { 149 LocalBinding(Either::B(par)) => {
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs
index 19702eba0..58baf3686 100644
--- a/crates/ra_ide_api/src/references/name_definition.rs
+++ b/crates/ra_ide_api/src/references/name_definition.rs
@@ -77,7 +77,11 @@ pub(super) fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDe
77 NameDefinition { item, container, visibility } 77 NameDefinition { item, container, visibility }
78} 78}
79 79
80pub(super) fn from_module_def(db: &RootDatabase, def: ModuleDef) -> NameDefinition { 80pub(super) fn from_module_def(
81 db: &RootDatabase,
82 def: ModuleDef,
83 module: Option<Module>,
84) -> NameDefinition {
81 let item = NameKind::Def(def); 85 let item = NameKind::Def(def);
82 let (container, visibility) = match def { 86 let (container, visibility) = match def {
83 ModuleDef::Module(it) => { 87 ModuleDef::Module(it) => {
@@ -98,7 +102,7 @@ pub(super) fn from_module_def(db: &RootDatabase, def: ModuleDef) -> NameDefiniti
98 ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).ast.visibility()), 102 ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).ast.visibility()),
99 ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).ast.visibility()), 103 ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).ast.visibility()),
100 ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).ast.visibility()), 104 ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).ast.visibility()),
101 ModuleDef::BuiltinType(..) => unreachable!(), 105 ModuleDef::BuiltinType(..) => (module.unwrap(), None),
102 }; 106 };
103 NameDefinition { item, container, visibility } 107 NameDefinition { item, container, visibility }
104} 108}
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index a27d9f367..9254327f6 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -101,8 +101,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
101 continue; 101 continue;
102 } 102 }
103 if let Some(name_ref) = node.as_node().cloned().and_then(ast::NameRef::cast) { 103 if let Some(name_ref) = node.as_node().cloned().and_then(ast::NameRef::cast) {
104 let name_kind = 104 let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.item);
105 classify_name_ref(db, file_id, &name_ref).and_then(|d| Some(d.item));
106 match name_kind { 105 match name_kind {
107 Some(Macro(_)) => "macro", 106 Some(Macro(_)) => "macro",
108 Some(Field(_)) => "field", 107 Some(Field(_)) => "field",