aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/apply_change.rs1
-rw-r--r--crates/ide_db/src/call_info/tests.rs3
-rw-r--r--crates/ide_db/src/defs.rs43
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs4
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs5
-rw-r--r--crates/ide_db/src/label.rs2
-rw-r--r--crates/ide_db/src/search.rs3
-rw-r--r--crates/ide_db/src/source_change.rs2
-rw-r--r--crates/ide_db/src/symbol_index.rs3
-rw-r--r--crates/ide_db/src/traits.rs3
-rw-r--r--crates/ide_db/src/traits/tests.rs3
-rw-r--r--crates/ide_db/src/ty_filter.rs6
12 files changed, 45 insertions, 33 deletions
diff --git a/crates/ide_db/src/apply_change.rs b/crates/ide_db/src/apply_change.rs
index 047a9b6bc..111e9325a 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();
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 @@
1use crate::RootDatabase;
2use base_db::{fixture::ChangeFixture, FilePosition}; 1use base_db::{fixture::ChangeFixture, FilePosition};
3use expect_test::{expect, Expect}; 2use expect_test::{expect, Expect};
4use test_utils::RangeOrOffset; 3use test_utils::RangeOrOffset;
5 4
5use 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.
7pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { 8pub(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/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`.
2use std::{cmp::Ordering, iter::successors}; 2use std::{cmp::Ordering, iter::successors};
3 3
4use crate::RootDatabase;
5use hir::Semantics; 4use hir::Semantics;
6use itertools::{EitherOrBoth, Itertools}; 5use itertools::{EitherOrBoth, Itertools};
7use syntax::{ 6use 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
16use crate::RootDatabase;
17
17pub use hir::PrefixKind; 18pub 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`]
2use std::fmt; 2use 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;
12use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
13use syntax::{ast, match_ast, AstNode, TextRange, TextSize}; 13use syntax::{ast, match_ast, AstNode, TextRange, TextSize};
14 14
15use crate::defs::NameClass;
16use crate::{ 15use 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 @@
1use crate::RootDatabase;
2use base_db::{fixture::ChangeFixture, FilePosition}; 1use base_db::{fixture::ChangeFixture, FilePosition};
3use expect_test::{expect, Expect}; 2use expect_test::{expect, Expect};
4use hir::Semantics; 3use hir::Semantics;
5use syntax::ast::{self, AstNode}; 4use syntax::ast::{self, AstNode};
6use test_utils::RangeOrOffset; 5use test_utils::RangeOrOffset;
7 6
7use 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.
9pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { 10pub(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
5use crate::RootDatabase;
6use hir::{Adt, Semantics, Type};
7use std::iter; 5use std::iter;
6
7use hir::{Adt, Semantics, Type};
8use syntax::ast::{self, make}; 8use syntax::ast::{self, make};
9 9
10use 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)]
12pub enum TryEnum { 14pub enum TryEnum {