aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/Cargo.toml1
-rw-r--r--crates/ra_assists/src/ast_transform.rs2
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs44
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs3
4 files changed, 26 insertions, 24 deletions
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml
index 707746ad5..a87f4052a 100644
--- a/crates/ra_assists/Cargo.toml
+++ b/crates/ra_assists/Cargo.toml
@@ -12,6 +12,7 @@ format-buf = "1.0.0"
12join_to_string = "0.1.3" 12join_to_string = "0.1.3"
13rustc-hash = "1.1.0" 13rustc-hash = "1.1.0"
14itertools = "0.9.0" 14itertools = "0.9.0"
15either = "1.5.3"
15 16
16ra_syntax = { path = "../ra_syntax" } 17ra_syntax = { path = "../ra_syntax" }
17ra_text_edit = { path = "../ra_text_edit" } 18ra_text_edit = { path = "../ra_text_edit" }
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 34c816f16..45558c448 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.into())?; 132 let found_path = from.find_use_path(self.source_scope.db, def)?;
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 49d8c4c3d..443eeaaf0 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::{defs::Definition, imports_locator::ImportsLocator, RootDatabase}; 7use ra_ide_db::{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},
@@ -17,6 +17,7 @@ use crate::{
17 utils::insert_use_statement, 17 utils::insert_use_statement,
18 AssistId, 18 AssistId,
19}; 19};
20use either::Either;
20 21
21// Assist: auto_import 22// Assist: auto_import
22// 23//
@@ -127,16 +128,14 @@ impl AutoImportAssets {
127 ImportsLocator::new(db) 128 ImportsLocator::new(db)
128 .find_imports(&self.get_search_query()) 129 .find_imports(&self.get_search_query())
129 .into_iter() 130 .into_iter()
130 .filter_map(|definition| match &self.import_candidate { 131 .filter_map(|candidate| match &self.import_candidate {
131 ImportCandidate::TraitAssocItem(assoc_item_type, _) => { 132 ImportCandidate::TraitAssocItem(assoc_item_type, _) => {
132 let located_assoc_item = match definition { 133 let located_assoc_item = match candidate {
133 Definition::ModuleDef(ModuleDef::Function(located_function)) => { 134 Either::Left(ModuleDef::Function(located_function)) => located_function
134 located_function 135 .as_assoc_item(db)
135 .as_assoc_item(db) 136 .map(|assoc| assoc.container(db))
136 .map(|assoc| assoc.container(db)) 137 .and_then(Self::assoc_to_trait),
137 .and_then(Self::assoc_to_trait) 138 Either::Left(ModuleDef::Const(located_const)) => located_const
138 }
139 Definition::ModuleDef(ModuleDef::Const(located_const)) => located_const
140 .as_assoc_item(db) 139 .as_assoc_item(db)
141 .map(|assoc| assoc.container(db)) 140 .map(|assoc| assoc.container(db))
142 .and_then(Self::assoc_to_trait), 141 .and_then(Self::assoc_to_trait),
@@ -154,13 +153,12 @@ impl AutoImportAssets {
154 None, 153 None,
155 |_, assoc| Self::assoc_to_trait(assoc.container(db)), 154 |_, assoc| Self::assoc_to_trait(assoc.container(db)),
156 ) 155 )
157 .map(|located_trait| ModuleDef::from(located_trait).into()) 156 .map(ModuleDef::from)
157 .map(Either::Left)
158 } 158 }
159 ImportCandidate::TraitMethod(function_callee, _) => { 159 ImportCandidate::TraitMethod(function_callee, _) => {
160 let located_assoc_item = 160 let located_assoc_item =
161 if let Definition::ModuleDef(ModuleDef::Function(located_function)) = 161 if let Either::Left(ModuleDef::Function(located_function)) = candidate {
162 definition
163 {
164 located_function 162 located_function
165 .as_assoc_item(db) 163 .as_assoc_item(db)
166 .map(|assoc| assoc.container(db)) 164 .map(|assoc| assoc.container(db))
@@ -182,15 +180,19 @@ impl AutoImportAssets {
182 Self::assoc_to_trait(function.as_assoc_item(db)?.container(db)) 180 Self::assoc_to_trait(function.as_assoc_item(db)?.container(db))
183 }, 181 },
184 ) 182 )
185 .map(|located_trait| ModuleDef::from(located_trait).into()) 183 .map(ModuleDef::from)
184 .map(Either::Left)
185 }
186 _ => Some(candidate),
187 })
188 .filter_map(|candidate| match candidate {
189 Either::Left(module_def) => {
190 self.module_with_name_to_import.find_use_path(db, module_def)
191 }
192 Either::Right(macro_def) => {
193 self.module_with_name_to_import.find_use_path(db, macro_def)
186 } 194 }
187 _ => match definition {
188 Definition::ModuleDef(module_def) => Some(module_def.into()),
189 Definition::Macro(macro_def) => Some(macro_def.into()),
190 _ => None,
191 },
192 }) 195 })
193 .filter_map(|item| self.module_with_name_to_import.find_use_path(db, item))
194 .filter(|use_path| !use_path.segments.is_empty()) 196 .filter(|use_path| !use_path.segments.is_empty())
195 .take(20) 197 .take(20)
196 .collect::<BTreeSet<_>>() 198 .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 869942b12..88b4c8926 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -154,8 +154,7 @@ 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 = 157 let path = crate::ast_transform::path_to_ast(module.find_use_path(db, ModuleDef::from(var))?);
158 crate::ast_transform::path_to_ast(module.find_use_path(db, ModuleDef::from(var).into())?);
159 158
160 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though 159 // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
161 let pat: ast::Pat = match var.source(db).value.kind() { 160 let pat: ast::Pat = match var.source(db).value.kind() {