diff options
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ide_db/src/defs.rs | 13 | ||||
-rw-r--r-- | crates/ide_db/src/imports_locator.rs | 23 | ||||
-rw-r--r-- | crates/ide_db/src/search.rs | 53 |
4 files changed, 65 insertions, 26 deletions
diff --git a/crates/ide_db/Cargo.toml b/crates/ide_db/Cargo.toml index 0ad6e1000..ebe53c8ee 100644 --- a/crates/ide_db/Cargo.toml +++ b/crates/ide_db/Cargo.toml | |||
@@ -19,7 +19,7 @@ fst = { version = "0.4", default-features = false } | |||
19 | rustc-hash = "1.1.0" | 19 | rustc-hash = "1.1.0" |
20 | once_cell = "1.3.1" | 20 | once_cell = "1.3.1" |
21 | either = "1.6.1" | 21 | either = "1.6.1" |
22 | itertools = "0.9.0" | 22 | itertools = "0.10.0" |
23 | 23 | ||
24 | stdx = { path = "../stdx", version = "0.0.0" } | 24 | stdx = { path = "../stdx", version = "0.0.0" } |
25 | syntax = { path = "../syntax", version = "0.0.0" } | 25 | syntax = { path = "../syntax", version = "0.0.0" } |
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index d33a6cb86..cc5078bf0 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs | |||
@@ -6,8 +6,8 @@ | |||
6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). | 6 | // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). |
7 | 7 | ||
8 | use hir::{ | 8 | use hir::{ |
9 | db::HirDatabase, Crate, Field, HasVisibility, Impl, Label, LifetimeParam, Local, MacroDef, | 9 | db::HirDatabase, ConstParam, Crate, Field, HasVisibility, Impl, Label, LifetimeParam, Local, |
10 | Module, ModuleDef, Name, PathResolution, Semantics, TypeParam, Visibility, | 10 | MacroDef, Module, ModuleDef, Name, PathResolution, Semantics, TypeParam, Visibility, |
11 | }; | 11 | }; |
12 | use syntax::{ | 12 | use syntax::{ |
13 | ast::{self, AstNode}, | 13 | ast::{self, AstNode}, |
@@ -26,6 +26,7 @@ pub enum Definition { | |||
26 | Local(Local), | 26 | Local(Local), |
27 | TypeParam(TypeParam), | 27 | TypeParam(TypeParam), |
28 | LifetimeParam(LifetimeParam), | 28 | LifetimeParam(LifetimeParam), |
29 | ConstParam(ConstParam), | ||
29 | Label(Label), | 30 | Label(Label), |
30 | } | 31 | } |
31 | 32 | ||
@@ -39,6 +40,7 @@ impl Definition { | |||
39 | Definition::Local(it) => Some(it.module(db)), | 40 | Definition::Local(it) => Some(it.module(db)), |
40 | Definition::TypeParam(it) => Some(it.module(db)), | 41 | Definition::TypeParam(it) => Some(it.module(db)), |
41 | Definition::LifetimeParam(it) => Some(it.module(db)), | 42 | Definition::LifetimeParam(it) => Some(it.module(db)), |
43 | Definition::ConstParam(it) => Some(it.module(db)), | ||
42 | Definition::Label(it) => Some(it.module(db)), | 44 | Definition::Label(it) => Some(it.module(db)), |
43 | } | 45 | } |
44 | } | 46 | } |
@@ -52,6 +54,7 @@ impl Definition { | |||
52 | Definition::Local(_) => None, | 54 | Definition::Local(_) => None, |
53 | Definition::TypeParam(_) => None, | 55 | Definition::TypeParam(_) => None, |
54 | Definition::LifetimeParam(_) => None, | 56 | Definition::LifetimeParam(_) => None, |
57 | Definition::ConstParam(_) => None, | ||
55 | Definition::Label(_) => None, | 58 | Definition::Label(_) => None, |
56 | } | 59 | } |
57 | } | 60 | } |
@@ -79,6 +82,7 @@ impl Definition { | |||
79 | Definition::Local(it) => it.name(db)?, | 82 | Definition::Local(it) => it.name(db)?, |
80 | Definition::TypeParam(it) => it.name(db), | 83 | Definition::TypeParam(it) => it.name(db), |
81 | Definition::LifetimeParam(it) => it.name(db), | 84 | Definition::LifetimeParam(it) => it.name(db), |
85 | Definition::ConstParam(it) => it.name(db), | ||
82 | Definition::Label(it) => it.name(db), | 86 | Definition::Label(it) => it.name(db), |
83 | }; | 87 | }; |
84 | Some(name) | 88 | Some(name) |
@@ -233,6 +237,10 @@ impl NameClass { | |||
233 | let def = sema.to_def(&it)?; | 237 | let def = sema.to_def(&it)?; |
234 | Some(NameClass::Definition(Definition::TypeParam(def))) | 238 | Some(NameClass::Definition(Definition::TypeParam(def))) |
235 | }, | 239 | }, |
240 | ast::ConstParam(it) => { | ||
241 | let def = sema.to_def(&it)?; | ||
242 | Some(NameClass::Definition(Definition::ConstParam(def))) | ||
243 | }, | ||
236 | _ => None, | 244 | _ => None, |
237 | } | 245 | } |
238 | } | 246 | } |
@@ -417,6 +425,7 @@ impl From<PathResolution> for Definition { | |||
417 | PathResolution::TypeParam(par) => Definition::TypeParam(par), | 425 | PathResolution::TypeParam(par) => Definition::TypeParam(par), |
418 | PathResolution::Macro(def) => Definition::Macro(def), | 426 | PathResolution::Macro(def) => Definition::Macro(def), |
419 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), | 427 | PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def), |
428 | PathResolution::ConstParam(par) => Definition::ConstParam(par), | ||
420 | } | 429 | } |
421 | } | 430 | } |
422 | } | 431 | } |
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index b2980a5d6..0f4c2ca47 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs | |||
@@ -15,19 +15,23 @@ use rustc_hash::FxHashSet; | |||
15 | pub fn find_exact_imports<'a>( | 15 | pub fn find_exact_imports<'a>( |
16 | sema: &Semantics<'a, RootDatabase>, | 16 | sema: &Semantics<'a, RootDatabase>, |
17 | krate: Crate, | 17 | krate: Crate, |
18 | name_to_import: &str, | 18 | name_to_import: String, |
19 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { | 19 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { |
20 | let _p = profile::span("find_exact_imports"); | 20 | let _p = profile::span("find_exact_imports"); |
21 | find_imports( | 21 | find_imports( |
22 | sema, | 22 | sema, |
23 | krate, | 23 | krate, |
24 | { | 24 | { |
25 | let mut local_query = symbol_index::Query::new(name_to_import.to_string()); | 25 | let mut local_query = symbol_index::Query::new(name_to_import.clone()); |
26 | local_query.exact(); | 26 | local_query.exact(); |
27 | local_query.limit(40); | 27 | local_query.limit(40); |
28 | local_query | 28 | local_query |
29 | }, | 29 | }, |
30 | import_map::Query::new(name_to_import).anchor_end().case_sensitive().limit(40), | 30 | import_map::Query::new(name_to_import) |
31 | .limit(40) | ||
32 | .name_only() | ||
33 | .search_mode(import_map::SearchMode::Equals) | ||
34 | .case_sensitive(), | ||
31 | ) | 35 | ) |
32 | } | 36 | } |
33 | 37 | ||
@@ -35,17 +39,18 @@ pub fn find_similar_imports<'a>( | |||
35 | sema: &Semantics<'a, RootDatabase>, | 39 | sema: &Semantics<'a, RootDatabase>, |
36 | krate: Crate, | 40 | krate: Crate, |
37 | limit: Option<usize>, | 41 | limit: Option<usize>, |
38 | name_to_import: &str, | 42 | fuzzy_search_string: String, |
39 | ignore_modules: bool, | 43 | name_only: bool, |
40 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { | 44 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { |
41 | let _p = profile::span("find_similar_imports"); | 45 | let _p = profile::span("find_similar_imports"); |
42 | 46 | ||
43 | let mut external_query = import_map::Query::new(name_to_import); | 47 | let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) |
44 | if ignore_modules { | 48 | .search_mode(import_map::SearchMode::Fuzzy); |
45 | external_query = external_query.exclude_import_kind(import_map::ImportKind::Module); | 49 | if name_only { |
50 | external_query = external_query.name_only(); | ||
46 | } | 51 | } |
47 | 52 | ||
48 | let mut local_query = symbol_index::Query::new(name_to_import.to_string()); | 53 | let mut local_query = symbol_index::Query::new(fuzzy_search_string); |
49 | 54 | ||
50 | if let Some(limit) = limit { | 55 | if let Some(limit) = limit { |
51 | local_query.limit(limit); | 56 | local_query.limit(limit); |
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index ff10f71c3..436c59d2c 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -121,31 +121,56 @@ impl Definition { | |||
121 | 121 | ||
122 | if let Definition::Local(var) = self { | 122 | if let Definition::Local(var) = self { |
123 | let range = match var.parent(db) { | 123 | let range = match var.parent(db) { |
124 | DefWithBody::Function(f) => f.source(db).value.syntax().text_range(), | 124 | DefWithBody::Function(f) => { |
125 | DefWithBody::Const(c) => c.source(db).value.syntax().text_range(), | 125 | f.source(db).and_then(|src| Some(src.value.syntax().text_range())) |
126 | DefWithBody::Static(s) => s.source(db).value.syntax().text_range(), | 126 | } |
127 | DefWithBody::Const(c) => { | ||
128 | c.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
129 | } | ||
130 | DefWithBody::Static(s) => { | ||
131 | s.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
132 | } | ||
127 | }; | 133 | }; |
128 | let mut res = FxHashMap::default(); | 134 | let mut res = FxHashMap::default(); |
129 | res.insert(file_id, Some(range)); | 135 | res.insert(file_id, range); |
130 | return SearchScope::new(res); | 136 | return SearchScope::new(res); |
131 | } | 137 | } |
132 | 138 | ||
133 | if let Definition::LifetimeParam(param) = self { | 139 | if let Definition::LifetimeParam(param) = self { |
140 | #[allow(deprecated)] | ||
134 | let range = match param.parent(db) { | 141 | let range = match param.parent(db) { |
135 | hir::GenericDef::Function(it) => it.source(db).value.syntax().text_range(), | 142 | hir::GenericDef::Function(it) => { |
143 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
144 | } | ||
136 | hir::GenericDef::Adt(it) => match it { | 145 | hir::GenericDef::Adt(it) => match it { |
137 | hir::Adt::Struct(it) => it.source(db).value.syntax().text_range(), | 146 | hir::Adt::Struct(it) => { |
138 | hir::Adt::Union(it) => it.source(db).value.syntax().text_range(), | 147 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) |
139 | hir::Adt::Enum(it) => it.source(db).value.syntax().text_range(), | 148 | } |
149 | hir::Adt::Union(it) => { | ||
150 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
151 | } | ||
152 | hir::Adt::Enum(it) => { | ||
153 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
154 | } | ||
140 | }, | 155 | }, |
141 | hir::GenericDef::Trait(it) => it.source(db).value.syntax().text_range(), | 156 | hir::GenericDef::Trait(it) => { |
142 | hir::GenericDef::TypeAlias(it) => it.source(db).value.syntax().text_range(), | 157 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) |
143 | hir::GenericDef::Impl(it) => it.source(db).value.syntax().text_range(), | 158 | } |
144 | hir::GenericDef::Variant(it) => it.source(db).value.syntax().text_range(), | 159 | hir::GenericDef::TypeAlias(it) => { |
145 | hir::GenericDef::Const(it) => it.source(db).value.syntax().text_range(), | 160 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) |
161 | } | ||
162 | hir::GenericDef::Impl(it) => { | ||
163 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
164 | } | ||
165 | hir::GenericDef::Variant(it) => { | ||
166 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
167 | } | ||
168 | hir::GenericDef::Const(it) => { | ||
169 | it.source(db).and_then(|src| Some(src.value.syntax().text_range())) | ||
170 | } | ||
146 | }; | 171 | }; |
147 | let mut res = FxHashMap::default(); | 172 | let mut res = FxHashMap::default(); |
148 | res.insert(file_id, Some(range)); | 173 | res.insert(file_id, range); |
149 | return SearchScope::new(res); | 174 | return SearchScope::new(res); |
150 | } | 175 | } |
151 | 176 | ||