diff options
author | Kirill Bulatov <[email protected]> | 2021-02-24 23:06:31 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-08 21:59:18 +0000 |
commit | 582cee2cdf5355b681f14bbb33bd5c431c284d87 (patch) | |
tree | 47d25e9c057759b1aa334abf3f584f1d0317d941 /crates/ide_completion/src/item.rs | |
parent | 309421c117fc20e58b9f30fb28a01a89f50b0086 (diff) |
Return more data about located imports
Diffstat (limited to 'crates/ide_completion/src/item.rs')
-rw-r--r-- | crates/ide_completion/src/item.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 9b2435c4b..0390fe226 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs | |||
@@ -2,9 +2,10 @@ | |||
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 | }, |
@@ -272,7 +273,7 @@ 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 import_scope: ImportScope, |
277 | pub import_for_trait_assoc_item: bool, | 278 | pub import_for_trait_assoc_item: bool, |
278 | } | 279 | } |
@@ -283,8 +284,11 @@ impl ImportEdit { | |||
283 | pub fn to_text_edit(&self, cfg: InsertUseConfig) -> Option<TextEdit> { | 284 | pub fn to_text_edit(&self, cfg: InsertUseConfig) -> Option<TextEdit> { |
284 | let _p = profile::span("ImportEdit::to_text_edit"); | 285 | let _p = profile::span("ImportEdit::to_text_edit"); |
285 | 286 | ||
286 | let rewriter = | 287 | let rewriter = insert_use::insert_use( |
287 | insert_use::insert_use(&self.import_scope, mod_path_to_ast(&self.import_path), cfg); | 288 | &self.import_scope, |
289 | mod_path_to_ast(self.import.import_path()), | ||
290 | cfg, | ||
291 | ); | ||
288 | let old_ast = rewriter.rewrite_root()?; | 292 | let old_ast = rewriter.rewrite_root()?; |
289 | let mut import_insert = TextEdit::builder(); | 293 | let mut import_insert = TextEdit::builder(); |
290 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); | 294 | algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); |
@@ -323,19 +327,13 @@ impl Builder { | |||
323 | let mut insert_text = self.insert_text; | 327 | let mut insert_text = self.insert_text; |
324 | 328 | ||
325 | if let Some(import_to_add) = self.import_to_add.as_ref() { | 329 | if let Some(import_to_add) = self.import_to_add.as_ref() { |
330 | lookup = lookup.or_else(|| Some(label.clone())); | ||
331 | insert_text = insert_text.or_else(|| Some(label.clone())); | ||
332 | let display_path = import_to_add.import.display_path(); | ||
326 | if import_to_add.import_for_trait_assoc_item { | 333 | if import_to_add.import_for_trait_assoc_item { |
327 | lookup = lookup.or_else(|| Some(label.clone())); | 334 | label = format!("{} ({})", label, display_path); |
328 | insert_text = insert_text.or_else(|| Some(label.clone())); | ||
329 | label = format!("{} ({})", label, import_to_add.import_path); | ||
330 | } else { | 335 | } else { |
331 | let mut import_path_without_last_segment = import_to_add.import_path.to_owned(); | 336 | label = display_path.to_string(); |
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 | } | 337 | } |
340 | } | 338 | } |
341 | 339 | ||