diff options
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r-- | crates/ide_db/src/apply_change.rs | 7 | ||||
-rw-r--r-- | crates/ide_db/src/call_info.rs | 10 | ||||
-rw-r--r-- | crates/ide_db/src/call_info/tests.rs | 27 | ||||
-rw-r--r-- | crates/ide_db/src/defs.rs | 41 | ||||
-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 | 24 |
7 files changed, 90 insertions, 29 deletions
diff --git a/crates/ide_db/src/apply_change.rs b/crates/ide_db/src/apply_change.rs index 047a9b6bc..eac5ef6b9 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 |
@@ -196,7 +201,7 @@ impl RootDatabase { | |||
196 | hir::db::InternImplTraitIdQuery | 201 | hir::db::InternImplTraitIdQuery |
197 | hir::db::InternClosureQuery | 202 | hir::db::InternClosureQuery |
198 | hir::db::AssociatedTyValueQuery | 203 | hir::db::AssociatedTyValueQuery |
199 | hir::db::TraitSolveQuery | 204 | hir::db::TraitSolveQueryQuery |
200 | 205 | ||
201 | // SymbolsDatabase | 206 | // SymbolsDatabase |
202 | crate::symbol_index::FileSymbolsQuery | 207 | crate::symbol_index::FileSymbolsQuery |
diff --git a/crates/ide_db/src/call_info.rs b/crates/ide_db/src/call_info.rs index e583a52f4..bad277a95 100644 --- a/crates/ide_db/src/call_info.rs +++ b/crates/ide_db/src/call_info.rs | |||
@@ -4,8 +4,9 @@ use either::Either; | |||
4 | use hir::{HasAttrs, HirDisplay, Semantics, Type}; | 4 | use hir::{HasAttrs, HirDisplay, Semantics, Type}; |
5 | use stdx::format_to; | 5 | use stdx::format_to; |
6 | use syntax::{ | 6 | use syntax::{ |
7 | algo, | ||
7 | ast::{self, ArgListOwner, NameOwner}, | 8 | ast::{self, ArgListOwner, NameOwner}, |
8 | match_ast, AstNode, SyntaxNode, SyntaxToken, TextRange, TextSize, | 9 | match_ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize, |
9 | }; | 10 | }; |
10 | 11 | ||
11 | use crate::RootDatabase; | 12 | use crate::RootDatabase; |
@@ -43,7 +44,12 @@ pub fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> | |||
43 | let sema = Semantics::new(db); | 44 | let sema = Semantics::new(db); |
44 | let file = sema.parse(position.file_id); | 45 | let file = sema.parse(position.file_id); |
45 | let file = file.syntax(); | 46 | let file = file.syntax(); |
46 | let token = file.token_at_offset(position.offset).next()?; | 47 | let token = file |
48 | .token_at_offset(position.offset) | ||
49 | .left_biased() | ||
50 | // if the cursor is sandwiched between two space tokens and the call is unclosed | ||
51 | // this prevents us from leaving the CallExpression | ||
52 | .and_then(|tok| algo::skip_trivia_token(tok, Direction::Prev))?; | ||
47 | let token = sema.descend_into_macros(token); | 53 | let token = sema.descend_into_macros(token); |
48 | 54 | ||
49 | let (callable, active_parameter) = call_info_impl(&sema, token)?; | 55 | let (callable, active_parameter) = call_info_impl(&sema, token)?; |
diff --git a/crates/ide_db/src/call_info/tests.rs b/crates/ide_db/src/call_info/tests.rs index 281a081a3..be1cc12de 100644 --- a/crates/ide_db/src/call_info/tests.rs +++ b/crates/ide_db/src/call_info/tests.rs | |||
@@ -522,3 +522,30 @@ fn main(f: fn(i32, f64) -> char) { | |||
522 | "#]], | 522 | "#]], |
523 | ) | 523 | ) |
524 | } | 524 | } |
525 | |||
526 | #[test] | ||
527 | fn call_info_for_unclosed_call() { | ||
528 | check( | ||
529 | r#" | ||
530 | fn foo(foo: u32, bar: u32) {} | ||
531 | fn main() { | ||
532 | foo($0 | ||
533 | }"#, | ||
534 | expect![[r#" | ||
535 | fn foo(foo: u32, bar: u32) | ||
536 | (<foo: u32>, bar: u32) | ||
537 | "#]], | ||
538 | ); | ||
539 | // check with surrounding space | ||
540 | check( | ||
541 | r#" | ||
542 | fn foo(foo: u32, bar: u32) {} | ||
543 | fn main() { | ||
544 | foo( $0 | ||
545 | }"#, | ||
546 | expect![[r#" | ||
547 | fn foo(foo: u32, bar: u32) | ||
548 | (<foo: u32>, bar: u32) | ||
549 | "#]], | ||
550 | ) | ||
551 | } | ||
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index 0d9808d24..de0dc2a40 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -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 3deb0d159..91d6a4665 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs | |||
@@ -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, |
@@ -436,6 +436,8 @@ fn trait_applicable_items( | |||
436 | }) | 436 | }) |
437 | .collect(); | 437 | .collect(); |
438 | 438 | ||
439 | let related_dyn_traits = | ||
440 | trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::<FxHashSet<_>>(); | ||
439 | let mut located_imports = FxHashSet::default(); | 441 | let mut located_imports = FxHashSet::default(); |
440 | 442 | ||
441 | if trait_assoc_item { | 443 | if trait_assoc_item { |
@@ -451,12 +453,16 @@ fn trait_applicable_items( | |||
451 | return None; | 453 | return None; |
452 | } | 454 | } |
453 | } | 455 | } |
456 | let located_trait = assoc.containing_trait(db)?; | ||
457 | if related_dyn_traits.contains(&located_trait) { | ||
458 | return None; | ||
459 | } | ||
454 | 460 | ||
455 | let item = ItemInNs::from(ModuleDef::from(assoc.containing_trait(db)?)); | 461 | let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); |
456 | let original_item = assoc_to_item(assoc); | 462 | let original_item = assoc_to_item(assoc); |
457 | located_imports.insert(LocatedImport::new( | 463 | located_imports.insert(LocatedImport::new( |
458 | mod_path(item)?, | 464 | mod_path(trait_item)?, |
459 | item, | 465 | trait_item, |
460 | original_item, | 466 | original_item, |
461 | mod_path(original_item), | 467 | mod_path(original_item), |
462 | )); | 468 | )); |
@@ -473,11 +479,15 @@ fn trait_applicable_items( | |||
473 | |_, function| { | 479 | |_, function| { |
474 | let assoc = function.as_assoc_item(db)?; | 480 | let assoc = function.as_assoc_item(db)?; |
475 | if required_assoc_items.contains(&assoc) { | 481 | if required_assoc_items.contains(&assoc) { |
476 | let item = ItemInNs::from(ModuleDef::from(assoc.containing_trait(db)?)); | 482 | let located_trait = assoc.containing_trait(db)?; |
483 | if related_dyn_traits.contains(&located_trait) { | ||
484 | return None; | ||
485 | } | ||
486 | let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); | ||
477 | let original_item = assoc_to_item(assoc); | 487 | let original_item = assoc_to_item(assoc); |
478 | located_imports.insert(LocatedImport::new( | 488 | located_imports.insert(LocatedImport::new( |
479 | mod_path(item)?, | 489 | mod_path(trait_item)?, |
480 | item, | 490 | trait_item, |
481 | original_item, | 491 | original_item, |
482 | mod_path(original_item), | 492 | mod_path(original_item), |
483 | )); | 493 | )); |