diff options
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r-- | crates/ide_db/src/apply_change.rs | 5 | ||||
-rw-r--r-- | crates/ide_db/src/call_info/tests.rs | 3 | ||||
-rw-r--r-- | crates/ide_db/src/defs.rs | 43 | ||||
-rw-r--r-- | crates/ide_db/src/helpers.rs | 4 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/famous_defs_fixture.rs | 6 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/import_assets.rs | 4 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/insert_use.rs | 5 | ||||
-rw-r--r-- | crates/ide_db/src/label.rs | 2 | ||||
-rw-r--r-- | crates/ide_db/src/search.rs | 3 | ||||
-rw-r--r-- | crates/ide_db/src/source_change.rs | 2 | ||||
-rw-r--r-- | crates/ide_db/src/symbol_index.rs | 3 | ||||
-rw-r--r-- | crates/ide_db/src/traits.rs | 3 | ||||
-rw-r--r-- | crates/ide_db/src/traits/tests.rs | 3 | ||||
-rw-r--r-- | crates/ide_db/src/ty_filter.rs | 6 |
14 files changed, 58 insertions, 34 deletions
diff --git a/crates/ide_db/src/apply_change.rs b/crates/ide_db/src/apply_change.rs index 047a9b6bc..6c67425d7 100644 --- a/crates/ide_db/src/apply_change.rs +++ b/crates/ide_db/src/apply_change.rs | |||
@@ -101,6 +101,7 @@ impl RootDatabase { | |||
101 | // | 101 | // |
102 | // | VS Code | **Rust Analyzer: Memory Usage (Clears Database)** | 102 | // | VS Code | **Rust Analyzer: Memory Usage (Clears Database)** |
103 | // |=== | 103 | // |=== |
104 | // image::https://user-images.githubusercontent.com/48062697/113065592-08559f00-91b1-11eb-8c96-64b88068ec02.gif[] | ||
104 | pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { | 105 | pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { |
105 | let mut acc: Vec<(String, Bytes)> = vec![]; | 106 | let mut acc: Vec<(String, Bytes)> = vec![]; |
106 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); | 107 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); |
@@ -151,6 +152,10 @@ impl RootDatabase { | |||
151 | hir::db::FileItemTreeQuery | 152 | hir::db::FileItemTreeQuery |
152 | hir::db::BlockDefMapQuery | 153 | hir::db::BlockDefMapQuery |
153 | hir::db::CrateDefMapQueryQuery | 154 | hir::db::CrateDefMapQueryQuery |
155 | hir::db::FieldsAttrsQuery | ||
156 | hir::db::VariantsAttrsQuery | ||
157 | hir::db::FieldsAttrsSourceMapQuery | ||
158 | hir::db::VariantsAttrsSourceMapQuery | ||
154 | hir::db::StructDataQuery | 159 | hir::db::StructDataQuery |
155 | hir::db::UnionDataQuery | 160 | hir::db::UnionDataQuery |
156 | hir::db::EnumDataQuery | 161 | hir::db::EnumDataQuery |
diff --git a/crates/ide_db/src/call_info/tests.rs b/crates/ide_db/src/call_info/tests.rs index 75ab3eb6e..281a081a3 100644 --- a/crates/ide_db/src/call_info/tests.rs +++ b/crates/ide_db/src/call_info/tests.rs | |||
@@ -1,8 +1,9 @@ | |||
1 | use crate::RootDatabase; | ||
2 | use base_db::{fixture::ChangeFixture, FilePosition}; | 1 | use base_db::{fixture::ChangeFixture, FilePosition}; |
3 | use expect_test::{expect, Expect}; | 2 | use expect_test::{expect, Expect}; |
4 | use test_utils::RangeOrOffset; | 3 | use test_utils::RangeOrOffset; |
5 | 4 | ||
5 | use crate::RootDatabase; | ||
6 | |||
6 | /// Creates analysis from a multi-file fixture, returns positions marked with $0. | 7 | /// Creates analysis from a multi-file fixture, returns positions marked with $0. |
7 | pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { | 8 | pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { |
8 | let change_fixture = ChangeFixture::parse(ra_fixture); | 9 | let change_fixture = ChangeFixture::parse(ra_fixture); |
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index 75167ff39..de0dc2a40 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -227,7 +227,7 @@ impl NameClass { | |||
227 | let def: hir::TypeAlias = sema.to_def(&it)?; | 227 | let def: hir::TypeAlias = sema.to_def(&it)?; |
228 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) | 228 | Some(NameClass::Definition(Definition::ModuleDef(def.into()))) |
229 | }, | 229 | }, |
230 | ast::MacroRules(it) => { | 230 | ast::Macro(it) => { |
231 | let def = sema.to_def(&it)?; | 231 | let def = sema.to_def(&it)?; |
232 | Some(NameClass::Definition(Definition::Macro(def))) | 232 | Some(NameClass::Definition(Definition::Macro(def))) |
233 | }, | 233 | }, |
@@ -330,25 +330,30 @@ impl NameRefClass { | |||
330 | } | 330 | } |
331 | } | 331 | } |
332 | 332 | ||
333 | if ast::AssocTypeArg::cast(parent.clone()).is_some() { | 333 | if let Some(assoc_type_arg) = ast::AssocTypeArg::cast(parent.clone()) { |
334 | // `Trait<Assoc = Ty>` | 334 | if assoc_type_arg.name_ref().as_ref() == Some(name_ref) { |
335 | // ^^^^^ | 335 | // `Trait<Assoc = Ty>` |
336 | let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; | 336 | // ^^^^^ |
337 | let resolved = sema.resolve_path(&path)?; | 337 | let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; |
338 | if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved { | 338 | let resolved = sema.resolve_path(&path)?; |
339 | if let Some(ty) = tr | 339 | if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved { |
340 | .items(sema.db) | 340 | // FIXME: resolve in supertraits |
341 | .iter() | 341 | if let Some(ty) = tr |
342 | .filter_map(|assoc| match assoc { | 342 | .items(sema.db) |
343 | hir::AssocItem::TypeAlias(it) => Some(*it), | 343 | .iter() |
344 | _ => None, | 344 | .filter_map(|assoc| match assoc { |
345 | }) | 345 | hir::AssocItem::TypeAlias(it) => Some(*it), |
346 | .find(|alias| &alias.name(sema.db).to_string() == name_ref.text()) | 346 | _ => None, |
347 | { | 347 | }) |
348 | return Some(NameRefClass::Definition(Definition::ModuleDef( | 348 | .find(|alias| &alias.name(sema.db).to_string() == &name_ref.text()) |
349 | ModuleDef::TypeAlias(ty), | 349 | { |
350 | ))); | 350 | return Some(NameRefClass::Definition(Definition::ModuleDef( |
351 | ModuleDef::TypeAlias(ty), | ||
352 | ))); | ||
353 | } | ||
351 | } | 354 | } |
355 | |||
356 | return None; | ||
352 | } | 357 | } |
353 | } | 358 | } |
354 | 359 | ||
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index 9992a92bd..66798ea3a 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs | |||
@@ -93,6 +93,10 @@ impl FamousDefs<'_, '_> { | |||
93 | self.find_trait("core:convert:From") | 93 | self.find_trait("core:convert:From") |
94 | } | 94 | } |
95 | 95 | ||
96 | pub fn core_convert_Into(&self) -> Option<Trait> { | ||
97 | self.find_trait("core:convert:Into") | ||
98 | } | ||
99 | |||
96 | pub fn core_option_Option(&self) -> Option<Enum> { | 100 | pub fn core_option_Option(&self) -> Option<Enum> { |
97 | self.find_enum("core:option:Option") | 101 | self.find_enum("core:option:Option") |
98 | } | 102 | } |
diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs index d3464ae17..4d79e064e 100644 --- a/crates/ide_db/src/helpers/famous_defs_fixture.rs +++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs | |||
@@ -14,6 +14,10 @@ pub mod convert { | |||
14 | pub trait From<T> { | 14 | pub trait From<T> { |
15 | fn from(t: T) -> Self; | 15 | fn from(t: T) -> Self; |
16 | } | 16 | } |
17 | |||
18 | pub trait Into<T> { | ||
19 | pub fn into(self) -> T; | ||
20 | } | ||
17 | } | 21 | } |
18 | 22 | ||
19 | pub mod default { | 23 | pub mod default { |
@@ -120,7 +124,7 @@ pub mod option { | |||
120 | pub mod prelude { | 124 | pub mod prelude { |
121 | pub use crate::{ | 125 | pub use crate::{ |
122 | cmp::Ord, | 126 | cmp::Ord, |
123 | convert::From, | 127 | convert::{From, Into}, |
124 | default::Default, | 128 | default::Default, |
125 | iter::{IntoIterator, Iterator}, | 129 | iter::{IntoIterator, Iterator}, |
126 | ops::{Fn, FnMut, FnOnce}, | 130 | ops::{Fn, FnMut, FnOnce}, |
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 1881c746f..8ce648367 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs | |||
@@ -288,7 +288,7 @@ fn path_applicable_imports( | |||
288 | import_for_item( | 288 | import_for_item( |
289 | sema.db, | 289 | sema.db, |
290 | mod_path, | 290 | mod_path, |
291 | unresolved_first_segment, | 291 | &unresolved_first_segment, |
292 | &unresolved_qualifier, | 292 | &unresolved_qualifier, |
293 | item, | 293 | item, |
294 | ) | 294 | ) |
@@ -361,7 +361,7 @@ fn item_for_path_search(db: &RootDatabase, item: ItemInNs) -> Option<ItemInNs> { | |||
361 | Some(assoc_item) => match assoc_item.container(db) { | 361 | Some(assoc_item) => match assoc_item.container(db) { |
362 | AssocItemContainer::Trait(trait_) => ItemInNs::from(ModuleDef::from(trait_)), | 362 | AssocItemContainer::Trait(trait_) => ItemInNs::from(ModuleDef::from(trait_)), |
363 | AssocItemContainer::Impl(impl_) => { | 363 | AssocItemContainer::Impl(impl_) => { |
364 | ItemInNs::from(ModuleDef::from(impl_.target_ty(db).as_adt()?)) | 364 | ItemInNs::from(ModuleDef::from(impl_.self_ty(db).as_adt()?)) |
365 | } | 365 | } |
366 | }, | 366 | }, |
367 | None => item, | 367 | None => item, |
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index 20c195f82..be3a22725 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! Handle syntactic aspects of inserting a new `use`. | 1 | //! Handle syntactic aspects of inserting a new `use`. |
2 | use std::{cmp::Ordering, iter::successors}; | 2 | use std::{cmp::Ordering, iter::successors}; |
3 | 3 | ||
4 | use crate::RootDatabase; | ||
5 | use hir::Semantics; | 4 | use hir::Semantics; |
6 | use itertools::{EitherOrBoth, Itertools}; | 5 | use itertools::{EitherOrBoth, Itertools}; |
7 | use syntax::{ | 6 | use syntax::{ |
@@ -14,6 +13,8 @@ use syntax::{ | |||
14 | AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken, | 13 | AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken, |
15 | }; | 14 | }; |
16 | 15 | ||
16 | use crate::RootDatabase; | ||
17 | |||
17 | pub use hir::PrefixKind; | 18 | pub use hir::PrefixKind; |
18 | 19 | ||
19 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 20 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
@@ -509,7 +510,7 @@ impl ImportGroup { | |||
509 | PathSegmentKind::SelfKw => ImportGroup::ThisModule, | 510 | PathSegmentKind::SelfKw => ImportGroup::ThisModule, |
510 | PathSegmentKind::SuperKw => ImportGroup::SuperModule, | 511 | PathSegmentKind::SuperKw => ImportGroup::SuperModule, |
511 | PathSegmentKind::CrateKw => ImportGroup::ThisCrate, | 512 | PathSegmentKind::CrateKw => ImportGroup::ThisCrate, |
512 | PathSegmentKind::Name(name) => match name.text() { | 513 | PathSegmentKind::Name(name) => match name.text().as_str() { |
513 | "std" => ImportGroup::Std, | 514 | "std" => ImportGroup::Std, |
514 | "core" => ImportGroup::Std, | 515 | "core" => ImportGroup::Std, |
515 | _ => ImportGroup::ExternCrate, | 516 | _ => ImportGroup::ExternCrate, |
diff --git a/crates/ide_db/src/label.rs b/crates/ide_db/src/label.rs index c0e89e72f..1f1e715c9 100644 --- a/crates/ide_db/src/label.rs +++ b/crates/ide_db/src/label.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! See `Label` | 1 | //! See [`Label`] |
2 | use std::fmt; | 2 | use std::fmt; |
3 | 3 | ||
4 | /// A type to specify UI label, like an entry in the list of assists. Enforces | 4 | /// A type to specify UI label, like an entry in the list of assists. Enforces |
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 3634b2b26..b55e3851e 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -12,9 +12,8 @@ use once_cell::unsync::Lazy; | |||
12 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
13 | use syntax::{ast, match_ast, AstNode, TextRange, TextSize}; | 13 | use syntax::{ast, match_ast, AstNode, TextRange, TextSize}; |
14 | 14 | ||
15 | use crate::defs::NameClass; | ||
16 | use crate::{ | 15 | use crate::{ |
17 | defs::{Definition, NameRefClass}, | 16 | defs::{Definition, NameClass, NameRefClass}, |
18 | RootDatabase, | 17 | RootDatabase, |
19 | }; | 18 | }; |
20 | 19 | ||
diff --git a/crates/ide_db/src/source_change.rs b/crates/ide_db/src/source_change.rs index b36455d49..846530f78 100644 --- a/crates/ide_db/src/source_change.rs +++ b/crates/ide_db/src/source_change.rs | |||
@@ -37,6 +37,8 @@ impl SourceChange { | |||
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | /// Inserts a [`TextEdit`] for the given [`FileId`]. This properly handles merging existing | ||
41 | /// edits for a file if some already exist. | ||
40 | pub fn insert_source_edit(&mut self, file_id: FileId, edit: TextEdit) { | 42 | pub fn insert_source_edit(&mut self, file_id: FileId, edit: TextEdit) { |
41 | match self.source_file_edits.entry(file_id) { | 43 | match self.source_file_edits.entry(file_id) { |
42 | Entry::Occupied(mut entry) => { | 44 | Entry::Occupied(mut entry) => { |
diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index 35e382b5c..da427d686 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs | |||
@@ -438,7 +438,7 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { | |||
438 | ast::TypeAlias(it) => decl(it), | 438 | ast::TypeAlias(it) => decl(it), |
439 | ast::Const(it) => decl(it), | 439 | ast::Const(it) => decl(it), |
440 | ast::Static(it) => decl(it), | 440 | ast::Static(it) => decl(it), |
441 | ast::MacroRules(it) => decl(it), | 441 | ast::Macro(it) => decl(it), |
442 | ast::Union(it) => decl(it), | 442 | ast::Union(it) => decl(it), |
443 | _ => None, | 443 | _ => None, |
444 | } | 444 | } |
@@ -458,6 +458,7 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> { | |||
458 | CONST => FileSymbolKind::Const, | 458 | CONST => FileSymbolKind::Const, |
459 | STATIC => FileSymbolKind::Static, | 459 | STATIC => FileSymbolKind::Static, |
460 | MACRO_RULES => FileSymbolKind::Macro, | 460 | MACRO_RULES => FileSymbolKind::Macro, |
461 | MACRO_DEF => FileSymbolKind::Macro, | ||
461 | UNION => FileSymbolKind::Union, | 462 | UNION => FileSymbolKind::Union, |
462 | kind => unreachable!("{:?}", kind), | 463 | kind => unreachable!("{:?}", kind), |
463 | }, | 464 | }, |
diff --git a/crates/ide_db/src/traits.rs b/crates/ide_db/src/traits.rs index 78a43f587..66ae81c73 100644 --- a/crates/ide_db/src/traits.rs +++ b/crates/ide_db/src/traits.rs | |||
@@ -61,7 +61,7 @@ pub fn get_missing_assoc_items( | |||
61 | resolve_target_trait(sema, impl_def).map_or(vec![], |target_trait| { | 61 | resolve_target_trait(sema, impl_def).map_or(vec![], |target_trait| { |
62 | target_trait | 62 | target_trait |
63 | .items(sema.db) | 63 | .items(sema.db) |
64 | .iter() | 64 | .into_iter() |
65 | .filter(|i| match i { | 65 | .filter(|i| match i { |
66 | hir::AssocItem::Function(f) => { | 66 | hir::AssocItem::Function(f) => { |
67 | !impl_fns_consts.contains(&f.name(sema.db).to_string()) | 67 | !impl_fns_consts.contains(&f.name(sema.db).to_string()) |
@@ -72,7 +72,6 @@ pub fn get_missing_assoc_items( | |||
72 | .map(|n| !impl_fns_consts.contains(&n.to_string())) | 72 | .map(|n| !impl_fns_consts.contains(&n.to_string())) |
73 | .unwrap_or_default(), | 73 | .unwrap_or_default(), |
74 | }) | 74 | }) |
75 | .cloned() | ||
76 | .collect() | 75 | .collect() |
77 | }) | 76 | }) |
78 | } | 77 | } |
diff --git a/crates/ide_db/src/traits/tests.rs b/crates/ide_db/src/traits/tests.rs index 84bb25505..2a5482024 100644 --- a/crates/ide_db/src/traits/tests.rs +++ b/crates/ide_db/src/traits/tests.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use crate::RootDatabase; | ||
2 | use base_db::{fixture::ChangeFixture, FilePosition}; | 1 | use base_db::{fixture::ChangeFixture, FilePosition}; |
3 | use expect_test::{expect, Expect}; | 2 | use expect_test::{expect, Expect}; |
4 | use hir::Semantics; | 3 | use hir::Semantics; |
5 | use syntax::ast::{self, AstNode}; | 4 | use syntax::ast::{self, AstNode}; |
6 | use test_utils::RangeOrOffset; | 5 | use test_utils::RangeOrOffset; |
7 | 6 | ||
7 | use crate::RootDatabase; | ||
8 | |||
8 | /// Creates analysis from a multi-file fixture, returns positions marked with $0. | 9 | /// Creates analysis from a multi-file fixture, returns positions marked with $0. |
9 | pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { | 10 | pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { |
10 | let change_fixture = ChangeFixture::parse(ra_fixture); | 11 | let change_fixture = ChangeFixture::parse(ra_fixture); |
diff --git a/crates/ide_db/src/ty_filter.rs b/crates/ide_db/src/ty_filter.rs index f8406851b..988ecd060 100644 --- a/crates/ide_db/src/ty_filter.rs +++ b/crates/ide_db/src/ty_filter.rs | |||
@@ -2,11 +2,13 @@ | |||
2 | //! Use case for structures in this module is, for example, situation when you need to process | 2 | //! Use case for structures in this module is, for example, situation when you need to process |
3 | //! only certain `Enum`s. | 3 | //! only certain `Enum`s. |
4 | 4 | ||
5 | use crate::RootDatabase; | ||
6 | use hir::{Adt, Semantics, Type}; | ||
7 | use std::iter; | 5 | use std::iter; |
6 | |||
7 | use hir::{Adt, Semantics, Type}; | ||
8 | use syntax::ast::{self, make}; | 8 | use syntax::ast::{self, make}; |
9 | 9 | ||
10 | use crate::RootDatabase; | ||
11 | |||
10 | /// Enum types that implement `std::ops::Try` trait. | 12 | /// Enum types that implement `std::ops::Try` trait. |
11 | #[derive(Clone, Copy)] | 13 | #[derive(Clone, Copy)] |
12 | pub enum TryEnum { | 14 | pub enum TryEnum { |