aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r--crates/ide_db/src/call_info/tests.rs24
-rw-r--r--crates/ide_db/src/defs.rs2
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs19
-rw-r--r--crates/ide_db/src/lib.rs20
-rw-r--r--crates/ide_db/src/symbol_index.rs2
-rw-r--r--crates/ide_db/src/traits/tests.rs6
-rw-r--r--crates/ide_db/src/ty_filter.rs6
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 @@
1use base_db::{fixture::ChangeFixture, FilePosition}; 1use base_db::{fixture::ChangeFixture, FilePosition};
2use expect_test::{expect, Expect}; 2use expect_test::{expect, Expect};
3use test_utils::RangeOrOffset;
4 3
5use crate::RootDatabase; 4use 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]
188fn test_fn_signature_for_generic_method() {
189 check(
190 r#"
191struct S<T>(T);
192impl<T> S<T> {
193 fn foo(&self, x: T) {}
194}
195
196fn main() { S(1u32).foo($0); }
197"#,
198 expect![[r#"
199 fn foo(&self, x: u32)
200 (<x: u32>)
201 "#]],
202 );
203}
204
205#[test]
192fn test_fn_signature_for_method_with_arg_as_assoc_fn() { 206fn 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
20use base_db::{ 20use 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};
25use hir::db::{AstDatabase, DefDatabase, HirDatabase}; 24use hir::db::{AstDatabase, DefDatabase, HirDatabase};
26use rustc_hash::FxHashSet; 25use rustc_hash::FxHashSet;
@@ -80,20 +79,7 @@ impl FileLoader for RootDatabase {
80 } 79 }
81} 80}
82 81
83impl salsa::Database for RootDatabase { 82impl 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
98impl Default for RootDatabase { 84impl 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)]
129pub trait LineIndexDatabase: base_db::SourceDatabase + CheckCanceled { 115pub 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
129fn file_symbols(db: &dyn SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> { 129fn 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};
2use expect_test::{expect, Expect}; 2use expect_test::{expect, Expect};
3use hir::Semantics; 3use hir::Semantics;
4use syntax::ast::{self, AstNode}; 4use syntax::ast::{self, AstNode};
5use test_utils::RangeOrOffset;
6 5
7use crate::RootDatabase; 6use 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
5use std::iter; 5use std::iter;
6 6
7use hir::{Adt, Semantics, Type}; 7use hir::Semantics;
8use syntax::ast::{self, make}; 8use syntax::ast::{self, make};
9 9
10use crate::RootDatabase; 10use 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| {