aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/ast_transform.rs2
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs34
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs5
3 files changed, 25 insertions, 16 deletions
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 45558c448..34c816f16 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -129,7 +129,7 @@ impl<'a> QualifyPaths<'a> {
129 let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; 129 let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
130 match resolution { 130 match resolution {
131 PathResolution::Def(def) => { 131 PathResolution::Def(def) => {
132 let found_path = from.find_use_path(self.source_scope.db, def)?; 132 let found_path = from.find_use_path(self.source_scope.db, def.into())?;
133 let mut path = path_to_ast(found_path); 133 let mut path = path_to_ast(found_path);
134 134
135 let type_args = p 135 let type_args = p
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs
index bb280f633..49d8c4c3d 100644
--- a/crates/ra_assists/src/handlers/auto_import.rs
+++ b/crates/ra_assists/src/handlers/auto_import.rs
@@ -4,7 +4,7 @@ use hir::{
4 AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait, 4 AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait,
5 Type, 5 Type,
6}; 6};
7use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase}; 7use ra_ide_db::{defs::Definition, imports_locator::ImportsLocator, RootDatabase};
8use ra_prof::profile; 8use ra_prof::profile;
9use ra_syntax::{ 9use ra_syntax::{
10 ast::{self, AstNode}, 10 ast::{self, AstNode},
@@ -127,14 +127,16 @@ impl AutoImportAssets {
127 ImportsLocator::new(db) 127 ImportsLocator::new(db)
128 .find_imports(&self.get_search_query()) 128 .find_imports(&self.get_search_query())
129 .into_iter() 129 .into_iter()
130 .filter_map(|module_def| match &self.import_candidate { 130 .filter_map(|definition| match &self.import_candidate {
131 ImportCandidate::TraitAssocItem(assoc_item_type, _) => { 131 ImportCandidate::TraitAssocItem(assoc_item_type, _) => {
132 let located_assoc_item = match module_def { 132 let located_assoc_item = match definition {
133 ModuleDef::Function(located_function) => located_function 133 Definition::ModuleDef(ModuleDef::Function(located_function)) => {
134 .as_assoc_item(db) 134 located_function
135 .map(|assoc| assoc.container(db)) 135 .as_assoc_item(db)
136 .and_then(Self::assoc_to_trait), 136 .map(|assoc| assoc.container(db))
137 ModuleDef::Const(located_const) => located_const 137 .and_then(Self::assoc_to_trait)
138 }
139 Definition::ModuleDef(ModuleDef::Const(located_const)) => located_const
138 .as_assoc_item(db) 140 .as_assoc_item(db)
139 .map(|assoc| assoc.container(db)) 141 .map(|assoc| assoc.container(db))
140 .and_then(Self::assoc_to_trait), 142 .and_then(Self::assoc_to_trait),
@@ -152,11 +154,13 @@ impl AutoImportAssets {
152 None, 154 None,
153 |_, assoc| Self::assoc_to_trait(assoc.container(db)), 155 |_, assoc| Self::assoc_to_trait(assoc.container(db)),
154 ) 156 )
155 .map(ModuleDef::from) 157 .map(|located_trait| ModuleDef::from(located_trait).into())
156 } 158 }
157 ImportCandidate::TraitMethod(function_callee, _) => { 159 ImportCandidate::TraitMethod(function_callee, _) => {
158 let located_assoc_item = 160 let located_assoc_item =
159 if let ModuleDef::Function(located_function) = module_def { 161 if let Definition::ModuleDef(ModuleDef::Function(located_function)) =
162 definition
163 {
160 located_function 164 located_function
161 .as_assoc_item(db) 165 .as_assoc_item(db)
162 .map(|assoc| assoc.container(db)) 166 .map(|assoc| assoc.container(db))
@@ -178,11 +182,15 @@ impl AutoImportAssets {
178 Self::assoc_to_trait(function.as_assoc_item(db)?.container(db)) 182 Self::assoc_to_trait(function.as_assoc_item(db)?.container(db))
179 }, 183 },
180 ) 184 )
181 .map(ModuleDef::from) 185 .map(|located_trait| ModuleDef::from(located_trait).into())
182 } 186 }
183 _ => Some(module_def), 187 _ => match definition {
188 Definition::ModuleDef(module_def) => Some(module_def.into()),
189 Definition::Macro(macro_def) => Some(macro_def.into()),
190 _ => None,
191 },
184 }) 192 })
185 .filter_map(|module_def| self.module_with_name_to_import.find_use_path(db, module_def)) 193 .filter_map(|item| self.module_with_name_to_import.find_use_path(db, item))
186 .filter(|use_path| !use_path.segments.is_empty()) 194 .filter(|use_path| !use_path.segments.is_empty())
187 .take(20) 195 .take(20)
188 .collect::<BTreeSet<_>>() 196 .collect::<BTreeSet<_>>()
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index 7463b2af7..869942b12 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -2,7 +2,7 @@
2 2
3use std::iter; 3use std::iter;
4 4
5use hir::{Adt, HasSource, Semantics}; 5use hir::{Adt, HasSource, ModuleDef, Semantics};
6use itertools::Itertools; 6use itertools::Itertools;
7use ra_ide_db::RootDatabase; 7use ra_ide_db::RootDatabase;
8 8
@@ -154,7 +154,8 @@ fn resolve_tuple_of_enum_def(
154} 154}
155 155
156fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option<ast::Pat> { 156fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option<ast::Pat> {
157 let path = crate::ast_transform::path_to_ast(module.find_use_path(db, var.into())?); 157 let path =
158 crate::ast_transform::path_to_ast(module.find_use_path(db, ModuleDef::from(var).into())?);
158 159
159 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though 160 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
160 let pat: ast::Pat = match var.source(db).value.kind() { 161 let pat: ast::Pat = match var.source(db).value.kind() {