diff options
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r-- | crates/ide_db/src/call_info/tests.rs | 24 | ||||
-rw-r--r-- | crates/ide_db/src/defs.rs | 2 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/import_assets.rs | 19 | ||||
-rw-r--r-- | crates/ide_db/src/lib.rs | 20 | ||||
-rw-r--r-- | crates/ide_db/src/symbol_index.rs | 2 | ||||
-rw-r--r-- | crates/ide_db/src/traits/tests.rs | 6 | ||||
-rw-r--r-- | crates/ide_db/src/ty_filter.rs | 6 |
7 files changed, 36 insertions, 43 deletions
diff --git a/crates/ide_db/src/call_info/tests.rs b/crates/ide_db/src/call_info/tests.rs index be1cc12de..b585085f3 100644 --- a/crates/ide_db/src/call_info/tests.rs +++ b/crates/ide_db/src/call_info/tests.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | use base_db::{fixture::ChangeFixture, FilePosition}; | 1 | use base_db::{fixture::ChangeFixture, FilePosition}; |
2 | use expect_test::{expect, Expect}; | 2 | use expect_test::{expect, Expect}; |
3 | use test_utils::RangeOrOffset; | ||
4 | 3 | ||
5 | use crate::RootDatabase; | 4 | use crate::RootDatabase; |
6 | 5 | ||
@@ -10,10 +9,7 @@ pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { | |||
10 | let mut database = RootDatabase::default(); | 9 | let mut database = RootDatabase::default(); |
11 | database.apply_change(change_fixture.change); | 10 | database.apply_change(change_fixture.change); |
12 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); | 11 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); |
13 | let offset = match range_or_offset { | 12 | let offset = range_or_offset.expect_offset(); |
14 | RangeOrOffset::Range(_) => panic!(), | ||
15 | RangeOrOffset::Offset(it) => it, | ||
16 | }; | ||
17 | (database, FilePosition { file_id, offset }) | 13 | (database, FilePosition { file_id, offset }) |
18 | } | 14 | } |
19 | 15 | ||
@@ -189,6 +185,24 @@ fn main() { S.foo($0); } | |||
189 | } | 185 | } |
190 | 186 | ||
191 | #[test] | 187 | #[test] |
188 | fn test_fn_signature_for_generic_method() { | ||
189 | check( | ||
190 | r#" | ||
191 | struct S<T>(T); | ||
192 | impl<T> S<T> { | ||
193 | fn foo(&self, x: T) {} | ||
194 | } | ||
195 | |||
196 | fn main() { S(1u32).foo($0); } | ||
197 | "#, | ||
198 | expect![[r#" | ||
199 | fn foo(&self, x: u32) | ||
200 | (<x: u32>) | ||
201 | "#]], | ||
202 | ); | ||
203 | } | ||
204 | |||
205 | #[test] | ||
192 | fn test_fn_signature_for_method_with_arg_as_assoc_fn() { | 206 | fn test_fn_signature_for_method_with_arg_as_assoc_fn() { |
193 | check( | 207 | check( |
194 | r#" | 208 | r#" |
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index de0dc2a40..1dcccbb8b 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -311,7 +311,7 @@ impl NameRefClass { | |||
311 | } | 311 | } |
312 | 312 | ||
313 | if let Some(record_field) = ast::RecordExprField::for_field_name(name_ref) { | 313 | if let Some(record_field) = ast::RecordExprField::for_field_name(name_ref) { |
314 | if let Some((field, local)) = sema.resolve_record_field(&record_field) { | 314 | if let Some((field, local, _)) = sema.resolve_record_field(&record_field) { |
315 | let field = Definition::Field(field); | 315 | let field = Definition::Field(field); |
316 | let res = match local { | 316 | let res = match local { |
317 | None => NameRefClass::Definition(field), | 317 | None => NameRefClass::Definition(field), |
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 91d6a4665..ae52dd8bb 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs | |||
@@ -420,6 +420,8 @@ fn trait_applicable_items( | |||
420 | 420 | ||
421 | let db = sema.db; | 421 | let db = sema.db; |
422 | 422 | ||
423 | let related_dyn_traits = | ||
424 | trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::<FxHashSet<_>>(); | ||
423 | let mut required_assoc_items = FxHashSet::default(); | 425 | let mut required_assoc_items = FxHashSet::default(); |
424 | let trait_candidates = items_locator::items_with_name( | 426 | let trait_candidates = items_locator::items_with_name( |
425 | sema, | 427 | sema, |
@@ -431,13 +433,15 @@ fn trait_applicable_items( | |||
431 | .filter_map(|input| item_as_assoc(db, input)) | 433 | .filter_map(|input| item_as_assoc(db, input)) |
432 | .filter_map(|assoc| { | 434 | .filter_map(|assoc| { |
433 | let assoc_item_trait = assoc.containing_trait(db)?; | 435 | let assoc_item_trait = assoc.containing_trait(db)?; |
434 | required_assoc_items.insert(assoc); | 436 | if related_dyn_traits.contains(&assoc_item_trait) { |
435 | Some(assoc_item_trait.into()) | 437 | None |
438 | } else { | ||
439 | required_assoc_items.insert(assoc); | ||
440 | Some(assoc_item_trait.into()) | ||
441 | } | ||
436 | }) | 442 | }) |
437 | .collect(); | 443 | .collect(); |
438 | 444 | ||
439 | let related_dyn_traits = | ||
440 | trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::<FxHashSet<_>>(); | ||
441 | let mut located_imports = FxHashSet::default(); | 445 | let mut located_imports = FxHashSet::default(); |
442 | 446 | ||
443 | if trait_assoc_item { | 447 | if trait_assoc_item { |
@@ -454,10 +458,6 @@ fn trait_applicable_items( | |||
454 | } | 458 | } |
455 | } | 459 | } |
456 | let located_trait = assoc.containing_trait(db)?; | 460 | let located_trait = assoc.containing_trait(db)?; |
457 | if related_dyn_traits.contains(&located_trait) { | ||
458 | return None; | ||
459 | } | ||
460 | |||
461 | let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); | 461 | let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); |
462 | let original_item = assoc_to_item(assoc); | 462 | let original_item = assoc_to_item(assoc); |
463 | located_imports.insert(LocatedImport::new( | 463 | located_imports.insert(LocatedImport::new( |
@@ -480,9 +480,6 @@ fn trait_applicable_items( | |||
480 | let assoc = function.as_assoc_item(db)?; | 480 | let assoc = function.as_assoc_item(db)?; |
481 | if required_assoc_items.contains(&assoc) { | 481 | if required_assoc_items.contains(&assoc) { |
482 | let located_trait = 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)); | 483 | let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); |
487 | let original_item = assoc_to_item(assoc); | 484 | let original_item = assoc_to_item(assoc); |
488 | located_imports.insert(LocatedImport::new( | 485 | located_imports.insert(LocatedImport::new( |
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index 88ee4a87d..1f900aef4 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs | |||
@@ -19,8 +19,7 @@ use std::{fmt, sync::Arc}; | |||
19 | 19 | ||
20 | use base_db::{ | 20 | use base_db::{ |
21 | salsa::{self, Durability}, | 21 | salsa::{self, Durability}, |
22 | AnchoredPath, Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, | 22 | AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, |
23 | SourceDatabase, Upcast, | ||
24 | }; | 23 | }; |
25 | use hir::db::{AstDatabase, DefDatabase, HirDatabase}; | 24 | use hir::db::{AstDatabase, DefDatabase, HirDatabase}; |
26 | use rustc_hash::FxHashSet; | 25 | use rustc_hash::FxHashSet; |
@@ -80,20 +79,7 @@ impl FileLoader for RootDatabase { | |||
80 | } | 79 | } |
81 | } | 80 | } |
82 | 81 | ||
83 | impl salsa::Database for RootDatabase { | 82 | impl salsa::Database for RootDatabase {} |
84 | fn on_propagated_panic(&self) -> ! { | ||
85 | Canceled::throw() | ||
86 | } | ||
87 | fn salsa_event(&self, event: salsa::Event) { | ||
88 | match event.kind { | ||
89 | salsa::EventKind::DidValidateMemoizedValue { .. } | ||
90 | | salsa::EventKind::WillExecute { .. } => { | ||
91 | self.check_canceled(); | ||
92 | } | ||
93 | _ => (), | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | 83 | ||
98 | impl Default for RootDatabase { | 84 | impl Default for RootDatabase { |
99 | fn default() -> RootDatabase { | 85 | fn default() -> RootDatabase { |
@@ -126,7 +112,7 @@ impl salsa::ParallelDatabase for RootDatabase { | |||
126 | } | 112 | } |
127 | 113 | ||
128 | #[salsa::query_group(LineIndexDatabaseStorage)] | 114 | #[salsa::query_group(LineIndexDatabaseStorage)] |
129 | pub trait LineIndexDatabase: base_db::SourceDatabase + CheckCanceled { | 115 | pub trait LineIndexDatabase: base_db::SourceDatabase { |
130 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; | 116 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; |
131 | } | 117 | } |
132 | 118 | ||
diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index 0f5c4abc4..5c372a7e5 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs | |||
@@ -127,7 +127,7 @@ fn library_symbols(db: &dyn SymbolsDatabase) -> Arc<FxHashMap<SourceRootId, Symb | |||
127 | } | 127 | } |
128 | 128 | ||
129 | fn file_symbols(db: &dyn SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> { | 129 | fn file_symbols(db: &dyn SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> { |
130 | db.check_canceled(); | 130 | db.unwind_if_cancelled(); |
131 | let parse = db.parse(file_id); | 131 | let parse = db.parse(file_id); |
132 | 132 | ||
133 | let symbols = source_file_to_file_symbols(&parse.tree(), file_id); | 133 | let symbols = source_file_to_file_symbols(&parse.tree(), file_id); |
diff --git a/crates/ide_db/src/traits/tests.rs b/crates/ide_db/src/traits/tests.rs index 2a5482024..de994407c 100644 --- a/crates/ide_db/src/traits/tests.rs +++ b/crates/ide_db/src/traits/tests.rs | |||
@@ -2,7 +2,6 @@ use base_db::{fixture::ChangeFixture, FilePosition}; | |||
2 | use expect_test::{expect, Expect}; | 2 | use expect_test::{expect, Expect}; |
3 | use hir::Semantics; | 3 | use hir::Semantics; |
4 | use syntax::ast::{self, AstNode}; | 4 | use syntax::ast::{self, AstNode}; |
5 | use test_utils::RangeOrOffset; | ||
6 | 5 | ||
7 | use crate::RootDatabase; | 6 | use crate::RootDatabase; |
8 | 7 | ||
@@ -12,10 +11,7 @@ pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { | |||
12 | let mut database = RootDatabase::default(); | 11 | let mut database = RootDatabase::default(); |
13 | database.apply_change(change_fixture.change); | 12 | database.apply_change(change_fixture.change); |
14 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); | 13 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); |
15 | let offset = match range_or_offset { | 14 | let offset = range_or_offset.expect_offset(); |
16 | RangeOrOffset::Range(_) => panic!(), | ||
17 | RangeOrOffset::Offset(it) => it, | ||
18 | }; | ||
19 | (database, FilePosition { file_id, offset }) | 15 | (database, FilePosition { file_id, offset }) |
20 | } | 16 | } |
21 | 17 | ||
diff --git a/crates/ide_db/src/ty_filter.rs b/crates/ide_db/src/ty_filter.rs index 00678bf3e..766d8c628 100644 --- a/crates/ide_db/src/ty_filter.rs +++ b/crates/ide_db/src/ty_filter.rs | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | use std::iter; | 5 | use std::iter; |
6 | 6 | ||
7 | use hir::{Adt, Semantics, Type}; | 7 | use hir::Semantics; |
8 | use syntax::ast::{self, make}; | 8 | use syntax::ast::{self, make}; |
9 | 9 | ||
10 | use crate::RootDatabase; | 10 | use crate::RootDatabase; |
@@ -20,9 +20,9 @@ impl TryEnum { | |||
20 | const ALL: [TryEnum; 2] = [TryEnum::Option, TryEnum::Result]; | 20 | const ALL: [TryEnum; 2] = [TryEnum::Option, TryEnum::Result]; |
21 | 21 | ||
22 | /// Returns `Some(..)` if the provided type is an enum that implements `std::ops::Try`. | 22 | /// Returns `Some(..)` if the provided type is an enum that implements `std::ops::Try`. |
23 | pub fn from_ty(sema: &Semantics<RootDatabase>, ty: &Type) -> Option<TryEnum> { | 23 | pub fn from_ty(sema: &Semantics<RootDatabase>, ty: &hir::Type) -> Option<TryEnum> { |
24 | let enum_ = match ty.as_adt() { | 24 | let enum_ = match ty.as_adt() { |
25 | Some(Adt::Enum(it)) => it, | 25 | Some(hir::Adt::Enum(it)) => it, |
26 | _ => return None, | 26 | _ => return None, |
27 | }; | 27 | }; |
28 | TryEnum::ALL.iter().find_map(|&var| { | 28 | TryEnum::ALL.iter().find_map(|&var| { |