diff options
Diffstat (limited to 'crates/ide_completion/src/item.rs')
-rw-r--r-- | crates/ide_completion/src/item.rs | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 9b2435c4b..9b039e3e5 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs | |||
@@ -2,15 +2,16 @@ | |||
2 | 2 | ||
3 | use std::fmt; | 3 | use std::fmt; |
4 | 4 | ||
5 | use hir::{Documentation, ModPath, Mutability}; | 5 | use hir::{Documentation, Mutability}; |
6 | use ide_db::{ | 6 | use ide_db::{ |
7 | helpers::{ | 7 | helpers::{ |
8 | import_assets::LocatedImport, | ||
8 | insert_use::{self, ImportScope, InsertUseConfig}, | 9 | insert_use::{self, ImportScope, InsertUseConfig}, |
9 | mod_path_to_ast, SnippetCap, | 10 | mod_path_to_ast, SnippetCap, |
10 | }, | 11 | }, |
11 | SymbolKind, | 12 | SymbolKind, |
12 | }; | 13 | }; |
13 | use stdx::{impl_from, never}; | 14 | use stdx::{format_to, impl_from, never}; |
14 | use syntax::{algo, TextRange}; | 15 | use syntax::{algo, TextRange}; |
15 | use text_edit::TextEdit; | 16 | use text_edit::TextEdit; |
16 | 17 | ||
@@ -272,9 +273,8 @@ impl CompletionItem { | |||
272 | /// An extra import to add after the completion is applied. | 273 | /// An extra import to add after the completion is applied. |
273 | #[derive(Debug, Clone)] | 274 | #[derive(Debug, Clone)] |
274 | pub struct ImportEdit { | 275 | pub struct ImportEdit { |
275 | pub import_path: ModPath, | 276 | pub import: LocatedImport, |
276 | pub import_scope: ImportScope, | 277 | pub scope: ImportScope, |
277 | pub import_for_trait_assoc_item: bool, | ||
278 | } | 278 | } |
279 | 279 | ||
280 | impl ImportEdit { | 280 | impl ImportEdit { |
@@ -284,7 +284,7 @@ impl ImportEdit { | |||
284 | let _p = profile::span("ImportEdit::to_text_edit"); | 284 | let _p = profile::span("ImportEdit::to_text_edit"); |
285 | 285 | ||
286 | let rewriter = | 286 | let rewriter = |
287 | insert_use::insert_use(&self.import_scope, mod_path_to_ast(&self.import_path), cfg); | 287 | insert_use::insert_use(&self.scope, mod_path_to_ast(&self.import.import_path), cfg); |
288 | let old_ast = rewriter.rewrite_root()?; | 288 | let old_ast = rewriter.rewrite_root()?; |
289 | let mut import_insert = TextEdit::builder(); | 289 | let mut import_insert = TextEdit::builder(); |
290 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); | 290 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); |
@@ -322,20 +322,19 @@ impl Builder { | |||
322 | let mut lookup = self.lookup; | 322 | let mut lookup = self.lookup; |
323 | let mut insert_text = self.insert_text; | 323 | let mut insert_text = self.insert_text; |
324 | 324 | ||
325 | if let Some(import_to_add) = self.import_to_add.as_ref() { | 325 | if let Some(original_path) = self |
326 | if import_to_add.import_for_trait_assoc_item { | 326 | .import_to_add |
327 | lookup = lookup.or_else(|| Some(label.clone())); | 327 | .as_ref() |
328 | insert_text = insert_text.or_else(|| Some(label.clone())); | 328 | .and_then(|import_edit| import_edit.import.original_path.as_ref()) |
329 | label = format!("{} ({})", label, import_to_add.import_path); | 329 | { |
330 | lookup = lookup.or_else(|| Some(label.clone())); | ||
331 | insert_text = insert_text.or_else(|| Some(label.clone())); | ||
332 | |||
333 | let original_path_label = original_path.to_string(); | ||
334 | if original_path_label.ends_with(&label) { | ||
335 | label = original_path_label; | ||
330 | } else { | 336 | } else { |
331 | let mut import_path_without_last_segment = import_to_add.import_path.to_owned(); | 337 | format_to!(label, " ({})", original_path) |
332 | let _ = import_path_without_last_segment.pop_segment(); | ||
333 | |||
334 | if !import_path_without_last_segment.segments().is_empty() { | ||
335 | lookup = lookup.or_else(|| Some(label.clone())); | ||
336 | insert_text = insert_text.or_else(|| Some(label.clone())); | ||
337 | label = format!("{}::{}", import_path_without_last_segment, label); | ||
338 | } | ||
339 | } | 338 | } |
340 | } | 339 | } |
341 | 340 | ||
@@ -439,9 +438,3 @@ impl Builder { | |||
439 | self | 438 | self |
440 | } | 439 | } |
441 | } | 440 | } |
442 | |||
443 | impl<'a> Into<CompletionItem> for Builder { | ||
444 | fn into(self) -> CompletionItem { | ||
445 | self.build() | ||
446 | } | ||
447 | } | ||