diff options
Diffstat (limited to 'crates/ra_ide_db/src')
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 59 | ||||
-rw-r--r-- | crates/ra_ide_db/src/search.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_db/src/symbol_index.rs | 16 |
3 files changed, 45 insertions, 36 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index e06b189a0..df56f2d9e 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -119,7 +119,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option | |||
119 | 119 | ||
120 | match_ast! { | 120 | match_ast! { |
121 | match parent { | 121 | match parent { |
122 | ast::Alias(it) => { | 122 | ast::Rename(it) => { |
123 | let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?; | 123 | let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?; |
124 | let path = use_tree.path()?; | 124 | let path = use_tree.path()?; |
125 | let path_segment = path.segment()?; | 125 | let path_segment = path.segment()?; |
@@ -142,7 +142,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option | |||
142 | 142 | ||
143 | Some(NameClass::Definition(Definition::Local(local))) | 143 | Some(NameClass::Definition(Definition::Local(local))) |
144 | }, | 144 | }, |
145 | ast::RecordFieldDef(it) => { | 145 | ast::RecordField(it) => { |
146 | let field: hir::Field = sema.to_def(&it)?; | 146 | let field: hir::Field = sema.to_def(&it)?; |
147 | Some(NameClass::Definition(Definition::Field(field))) | 147 | Some(NameClass::Definition(Definition::Field(field))) |
148 | }, | 148 | }, |
@@ -150,39 +150,39 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option | |||
150 | let def = sema.to_def(&it)?; | 150 | let def = sema.to_def(&it)?; |
151 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 151 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
152 | }, | 152 | }, |
153 | ast::StructDef(it) => { | 153 | ast::Struct(it) => { |
154 | let def: hir::Struct = sema.to_def(&it)?; | 154 | let def: hir::Struct = sema.to_def(&it)?; |
155 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 155 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
156 | }, | 156 | }, |
157 | ast::UnionDef(it) => { | 157 | ast::Union(it) => { |
158 | let def: hir::Union = sema.to_def(&it)?; | 158 | let def: hir::Union = sema.to_def(&it)?; |
159 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 159 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
160 | }, | 160 | }, |
161 | ast::EnumDef(it) => { | 161 | ast::Enum(it) => { |
162 | let def: hir::Enum = sema.to_def(&it)?; | 162 | let def: hir::Enum = sema.to_def(&it)?; |
163 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 163 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
164 | }, | 164 | }, |
165 | ast::TraitDef(it) => { | 165 | ast::Trait(it) => { |
166 | let def: hir::Trait = sema.to_def(&it)?; | 166 | let def: hir::Trait = sema.to_def(&it)?; |
167 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 167 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
168 | }, | 168 | }, |
169 | ast::StaticDef(it) => { | 169 | ast::Static(it) => { |
170 | let def: hir::Static = sema.to_def(&it)?; | 170 | let def: hir::Static = sema.to_def(&it)?; |
171 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 171 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
172 | }, | 172 | }, |
173 | ast::EnumVariant(it) => { | 173 | ast::Variant(it) => { |
174 | let def: hir::EnumVariant = sema.to_def(&it)?; | 174 | let def: hir::EnumVariant = sema.to_def(&it)?; |
175 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 175 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
176 | }, | 176 | }, |
177 | ast::FnDef(it) => { | 177 | ast::Fn(it) => { |
178 | let def: hir::Function = sema.to_def(&it)?; | 178 | let def: hir::Function = sema.to_def(&it)?; |
179 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 179 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
180 | }, | 180 | }, |
181 | ast::ConstDef(it) => { | 181 | ast::Const(it) => { |
182 | let def: hir::Const = sema.to_def(&it)?; | 182 | let def: hir::Const = sema.to_def(&it)?; |
183 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 183 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
184 | }, | 184 | }, |
185 | ast::TypeAliasDef(it) => { | 185 | ast::TypeAlias(it) => { |
186 | let def: hir::TypeAlias = sema.to_def(&it)?; | 186 | let def: hir::TypeAlias = sema.to_def(&it)?; |
187 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 187 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
188 | }, | 188 | }, |
@@ -236,7 +236,7 @@ pub fn classify_name_ref( | |||
236 | } | 236 | } |
237 | } | 237 | } |
238 | 238 | ||
239 | if let Some(record_field) = ast::RecordField::for_field_name(name_ref) { | 239 | if let Some(record_field) = ast::RecordExprField::for_field_name(name_ref) { |
240 | if let Some((field, local)) = sema.resolve_record_field(&record_field) { | 240 | if let Some((field, local)) = sema.resolve_record_field(&record_field) { |
241 | let field = Definition::Field(field); | 241 | let field = Definition::Field(field); |
242 | let res = match local { | 242 | let res = match local { |
@@ -290,20 +290,25 @@ pub fn classify_name_ref( | |||
290 | 290 | ||
291 | let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; | 291 | let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; |
292 | let resolved = sema.resolve_path(&path)?; | 292 | let resolved = sema.resolve_path(&path)?; |
293 | let res = match resolved { | 293 | Some(NameRefClass::Definition(resolved.into())) |
294 | PathResolution::Def(def) => Definition::ModuleDef(def), | 294 | } |
295 | PathResolution::AssocItem(item) => { | 295 | |
296 | let def = match item { | 296 | impl From<PathResolution> for Definition { |
297 | hir::AssocItem::Function(it) => it.into(), | 297 | fn from(path_resolution: PathResolution) -> Self { |
298 | hir::AssocItem::Const(it) => it.into(), | 298 | match path_resolution { |
299 | hir::AssocItem::TypeAlias(it) => it.into(), | 299 | PathResolution::Def(def) => Definition::ModuleDef(def), |
300 | }; | 300 | PathResolution::AssocItem(item) => { |
301 | Definition::ModuleDef(def) | 301 | let def = match item { |
302 | hir::AssocItem::Function(it) => it.into(), | ||
303 | hir::AssocItem::Const(it) => it.into(), | ||
304 | hir::AssocItem::TypeAlias(it) => it.into(), | ||
305 | }; | ||
306 | Definition::ModuleDef(def) | ||
307 | } | ||
308 | PathResolution::Local(local) => Definition::Local(local), | ||
309 | PathResolution::TypeParam(par) => Definition::TypeParam(par), | ||
310 | PathResolution::Macro(def) => Definition::Macro(def), | ||
311 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), | ||
302 | } | 312 | } |
303 | PathResolution::Local(local) => Definition::Local(local), | 313 | } |
304 | PathResolution::TypeParam(par) => Definition::TypeParam(par), | ||
305 | PathResolution::Macro(def) => Definition::Macro(def), | ||
306 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), | ||
307 | }; | ||
308 | Some(NameRefClass::Definition(res)) | ||
309 | } | 314 | } |
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 81553150b..0b862b449 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -60,6 +60,10 @@ impl SearchScope { | |||
60 | SearchScope::new(std::iter::once((file, None)).collect()) | 60 | SearchScope::new(std::iter::once((file, None)).collect()) |
61 | } | 61 | } |
62 | 62 | ||
63 | pub fn files(files: &[FileId]) -> SearchScope { | ||
64 | SearchScope::new(files.iter().map(|f| (*f, None)).collect()) | ||
65 | } | ||
66 | |||
63 | pub fn intersection(&self, other: &SearchScope) -> SearchScope { | 67 | pub fn intersection(&self, other: &SearchScope) -> SearchScope { |
64 | let (mut small, mut large) = (&self.entries, &other.entries); | 68 | let (mut small, mut large) = (&self.entries, &other.entries); |
65 | if small.len() > large.len() { | 69 | if small.len() > large.len() { |
@@ -311,7 +315,7 @@ fn is_record_lit_name_ref(name_ref: &ast::NameRef) -> bool { | |||
311 | name_ref | 315 | name_ref |
312 | .syntax() | 316 | .syntax() |
313 | .ancestors() | 317 | .ancestors() |
314 | .find_map(ast::RecordLit::cast) | 318 | .find_map(ast::RecordExpr::cast) |
315 | .and_then(|l| l.path()) | 319 | .and_then(|l| l.path()) |
316 | .and_then(|p| p.segment()) | 320 | .and_then(|p| p.segment()) |
317 | .map(|p| p.name_ref().as_ref() == Some(name_ref)) | 321 | .map(|p| p.name_ref().as_ref() == Some(name_ref)) |
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index 131e2a128..35a2c5be3 100644 --- a/crates/ra_ide_db/src/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs | |||
@@ -344,7 +344,7 @@ impl Query { | |||
344 | } | 344 | } |
345 | 345 | ||
346 | fn is_type(kind: SyntaxKind) -> bool { | 346 | fn is_type(kind: SyntaxKind) -> bool { |
347 | matches!(kind, STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF) | 347 | matches!(kind, STRUCT | ENUM | TRAIT | TYPE_ALIAS) |
348 | } | 348 | } |
349 | 349 | ||
350 | /// The actual data that is stored in the index. It should be as compact as | 350 | /// The actual data that is stored in the index. It should be as compact as |
@@ -397,14 +397,14 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { | |||
397 | } | 397 | } |
398 | match_ast! { | 398 | match_ast! { |
399 | match node { | 399 | match node { |
400 | ast::FnDef(it) => decl(it), | 400 | ast::Fn(it) => decl(it), |
401 | ast::StructDef(it) => decl(it), | 401 | ast::Struct(it) => decl(it), |
402 | ast::EnumDef(it) => decl(it), | 402 | ast::Enum(it) => decl(it), |
403 | ast::TraitDef(it) => decl(it), | 403 | ast::Trait(it) => decl(it), |
404 | ast::Module(it) => decl(it), | 404 | ast::Module(it) => decl(it), |
405 | ast::TypeAliasDef(it) => decl(it), | 405 | ast::TypeAlias(it) => decl(it), |
406 | ast::ConstDef(it) => decl(it), | 406 | ast::Const(it) => decl(it), |
407 | ast::StaticDef(it) => decl(it), | 407 | ast::Static(it) => decl(it), |
408 | ast::MacroCall(it) => { | 408 | ast::MacroCall(it) => { |
409 | if it.is_macro_rules().is_some() { | 409 | if it.is_macro_rules().is_some() { |
410 | decl(it) | 410 | decl(it) |