diff options
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/import_map.rs | 66 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 10 | ||||
-rw-r--r-- | crates/hir_def/src/path.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/type_ref.rs | 2 |
4 files changed, 70 insertions, 10 deletions
diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs index e5368b293..fac0de90c 100644 --- a/crates/hir_def/src/import_map.rs +++ b/crates/hir_def/src/import_map.rs | |||
@@ -263,6 +263,7 @@ pub enum ImportKind { | |||
263 | Trait, | 263 | Trait, |
264 | TypeAlias, | 264 | TypeAlias, |
265 | BuiltinType, | 265 | BuiltinType, |
266 | AssociatedItem, | ||
266 | } | 267 | } |
267 | 268 | ||
268 | /// A way to match import map contents against the search query. | 269 | /// A way to match import map contents against the search query. |
@@ -282,6 +283,7 @@ pub struct Query { | |||
282 | query: String, | 283 | query: String, |
283 | lowercased: String, | 284 | lowercased: String, |
284 | name_only: bool, | 285 | name_only: bool, |
286 | assoc_items_only: bool, | ||
285 | search_mode: SearchMode, | 287 | search_mode: SearchMode, |
286 | case_sensitive: bool, | 288 | case_sensitive: bool, |
287 | limit: usize, | 289 | limit: usize, |
@@ -295,6 +297,7 @@ impl Query { | |||
295 | query, | 297 | query, |
296 | lowercased, | 298 | lowercased, |
297 | name_only: false, | 299 | name_only: false, |
300 | assoc_items_only: false, | ||
298 | search_mode: SearchMode::Contains, | 301 | search_mode: SearchMode::Contains, |
299 | case_sensitive: false, | 302 | case_sensitive: false, |
300 | limit: usize::max_value(), | 303 | limit: usize::max_value(), |
@@ -309,6 +312,11 @@ impl Query { | |||
309 | Self { name_only: true, ..self } | 312 | Self { name_only: true, ..self } |
310 | } | 313 | } |
311 | 314 | ||
315 | /// Matches only the entries that are associated items, ignoring the rest. | ||
316 | pub fn assoc_items_only(self) -> Self { | ||
317 | Self { assoc_items_only: true, ..self } | ||
318 | } | ||
319 | |||
312 | /// Specifies the way to search for the entries using the query. | 320 | /// Specifies the way to search for the entries using the query. |
313 | pub fn search_mode(self, search_mode: SearchMode) -> Self { | 321 | pub fn search_mode(self, search_mode: SearchMode) -> Self { |
314 | Self { search_mode, ..self } | 322 | Self { search_mode, ..self } |
@@ -331,6 +339,14 @@ impl Query { | |||
331 | } | 339 | } |
332 | 340 | ||
333 | fn import_matches(&self, import: &ImportInfo, enforce_lowercase: bool) -> bool { | 341 | fn import_matches(&self, import: &ImportInfo, enforce_lowercase: bool) -> bool { |
342 | if import.is_trait_assoc_item { | ||
343 | if self.exclude_import_kinds.contains(&ImportKind::AssociatedItem) { | ||
344 | return false; | ||
345 | } | ||
346 | } else if self.assoc_items_only { | ||
347 | return false; | ||
348 | } | ||
349 | |||
334 | let mut input = if import.is_trait_assoc_item || self.name_only { | 350 | let mut input = if import.is_trait_assoc_item || self.name_only { |
335 | import.path.segments.last().unwrap().to_string() | 351 | import.path.segments.last().unwrap().to_string() |
336 | } else { | 352 | } else { |
@@ -814,6 +830,56 @@ mod tests { | |||
814 | } | 830 | } |
815 | 831 | ||
816 | #[test] | 832 | #[test] |
833 | fn assoc_items_filtering() { | ||
834 | let ra_fixture = r#" | ||
835 | //- /main.rs crate:main deps:dep | ||
836 | //- /dep.rs crate:dep | ||
837 | pub mod fmt { | ||
838 | pub trait Display { | ||
839 | type FmtTypeAlias; | ||
840 | const FMT_CONST: bool; | ||
841 | |||
842 | fn format_function(); | ||
843 | fn format_method(&self); | ||
844 | } | ||
845 | } | ||
846 | "#; | ||
847 | |||
848 | check_search( | ||
849 | ra_fixture, | ||
850 | "main", | ||
851 | Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy).assoc_items_only(), | ||
852 | expect![[r#" | ||
853 | dep::fmt::Display::FMT_CONST (a) | ||
854 | dep::fmt::Display::format_function (a) | ||
855 | dep::fmt::Display::format_method (a) | ||
856 | "#]], | ||
857 | ); | ||
858 | |||
859 | check_search( | ||
860 | ra_fixture, | ||
861 | "main", | ||
862 | Query::new("fmt".to_string()) | ||
863 | .search_mode(SearchMode::Fuzzy) | ||
864 | .exclude_import_kind(ImportKind::AssociatedItem), | ||
865 | expect![[r#" | ||
866 | dep::fmt (t) | ||
867 | dep::fmt::Display (t) | ||
868 | "#]], | ||
869 | ); | ||
870 | |||
871 | check_search( | ||
872 | ra_fixture, | ||
873 | "main", | ||
874 | Query::new("fmt".to_string()) | ||
875 | .search_mode(SearchMode::Fuzzy) | ||
876 | .assoc_items_only() | ||
877 | .exclude_import_kind(ImportKind::AssociatedItem), | ||
878 | expect![[r#""#]], | ||
879 | ); | ||
880 | } | ||
881 | |||
882 | #[test] | ||
817 | fn search_mode() { | 883 | fn search_mode() { |
818 | let ra_fixture = r#" | 884 | let ra_fixture = r#" |
819 | //- /main.rs crate:main deps:dep | 885 | //- /main.rs crate:main deps:dep |
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 9a433b61c..ff62928df 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -145,7 +145,6 @@ impl ItemTree { | |||
145 | macro_calls, | 145 | macro_calls, |
146 | macro_rules, | 146 | macro_rules, |
147 | macro_defs, | 147 | macro_defs, |
148 | exprs, | ||
149 | vis, | 148 | vis, |
150 | generics, | 149 | generics, |
151 | } = &mut **data; | 150 | } = &mut **data; |
@@ -167,7 +166,6 @@ impl ItemTree { | |||
167 | macro_calls.shrink_to_fit(); | 166 | macro_calls.shrink_to_fit(); |
168 | macro_rules.shrink_to_fit(); | 167 | macro_rules.shrink_to_fit(); |
169 | macro_defs.shrink_to_fit(); | 168 | macro_defs.shrink_to_fit(); |
170 | exprs.shrink_to_fit(); | ||
171 | 169 | ||
172 | vis.arena.shrink_to_fit(); | 170 | vis.arena.shrink_to_fit(); |
173 | generics.arena.shrink_to_fit(); | 171 | generics.arena.shrink_to_fit(); |
@@ -296,7 +294,6 @@ struct ItemTreeData { | |||
296 | macro_calls: Arena<MacroCall>, | 294 | macro_calls: Arena<MacroCall>, |
297 | macro_rules: Arena<MacroRules>, | 295 | macro_rules: Arena<MacroRules>, |
298 | macro_defs: Arena<MacroDef>, | 296 | macro_defs: Arena<MacroDef>, |
299 | exprs: Arena<Expr>, | ||
300 | 297 | ||
301 | vis: ItemVisibilities, | 298 | vis: ItemVisibilities, |
302 | generics: GenericParamsStorage, | 299 | generics: GenericParamsStorage, |
@@ -461,7 +458,7 @@ macro_rules! impl_index { | |||
461 | }; | 458 | }; |
462 | } | 459 | } |
463 | 460 | ||
464 | impl_index!(fields: Field, variants: Variant, exprs: Expr); | 461 | impl_index!(fields: Field, variants: Variant); |
465 | 462 | ||
466 | impl Index<RawVisibilityId> for ItemTree { | 463 | impl Index<RawVisibilityId> for ItemTree { |
467 | type Output = RawVisibility; | 464 | type Output = RawVisibility; |
@@ -664,11 +661,6 @@ pub struct MacroDef { | |||
664 | pub ast_id: FileAstId<ast::MacroDef>, | 661 | pub ast_id: FileAstId<ast::MacroDef>, |
665 | } | 662 | } |
666 | 663 | ||
667 | // NB: There's no `FileAstId` for `Expr`. The only case where this would be useful is for array | ||
668 | // lengths, but we don't do much with them yet. | ||
669 | #[derive(Debug, Clone, Eq, PartialEq)] | ||
670 | pub struct Expr; | ||
671 | |||
672 | macro_rules! impl_froms { | 664 | macro_rules! impl_froms { |
673 | ($e:ident { $($v:ident ($t:ty)),* $(,)? }) => { | 665 | ($e:ident { $($v:ident ($t:ty)),* $(,)? }) => { |
674 | $( | 666 | $( |
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 3dd7c3cbb..e34cd7f2f 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs | |||
@@ -87,7 +87,7 @@ impl ModPath { | |||
87 | 87 | ||
88 | /// If this path is a single identifier, like `foo`, return its name. | 88 | /// If this path is a single identifier, like `foo`, return its name. |
89 | pub fn as_ident(&self) -> Option<&Name> { | 89 | pub fn as_ident(&self) -> Option<&Name> { |
90 | if self.kind != PathKind::Plain || self.segments.len() > 1 { | 90 | if !self.is_ident() { |
91 | return None; | 91 | return None; |
92 | } | 92 | } |
93 | self.segments.first() | 93 | self.segments.first() |
diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs index ae93d0d10..049b2e462 100644 --- a/crates/hir_def/src/type_ref.rs +++ b/crates/hir_def/src/type_ref.rs | |||
@@ -159,6 +159,8 @@ impl TypeRef { | |||
159 | ast::Type::DynTraitType(inner) => { | 159 | ast::Type::DynTraitType(inner) => { |
160 | TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) | 160 | TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) |
161 | } | 161 | } |
162 | // FIXME: Macros in type position are not yet supported. | ||
163 | ast::Type::MacroType(_) => TypeRef::Error, | ||
162 | } | 164 | } |
163 | } | 165 | } |
164 | 166 | ||