diff options
author | Kirill Bulatov <[email protected]> | 2021-03-03 21:55:21 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-08 21:59:20 +0000 |
commit | 24a5d3b19dfa3e076df8b7413d0cc4a547aeb7d7 (patch) | |
tree | bb49da53786891e9bfd7d063f863416753265d11 /crates/ide_completion/src/item.rs | |
parent | 33c83e72b9b48177a6171fd06a26676679963a4d (diff) |
Fix the completion labels and tests
Diffstat (limited to 'crates/ide_completion/src/item.rs')
-rw-r--r-- | crates/ide_completion/src/item.rs | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index d01620500..44e4a6dfd 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs | |||
@@ -11,7 +11,7 @@ use ide_db::{ | |||
11 | }, | 11 | }, |
12 | SymbolKind, | 12 | SymbolKind, |
13 | }; | 13 | }; |
14 | use stdx::{impl_from, never}; | 14 | use stdx::{format_to, impl_from, never}; |
15 | use syntax::{algo, TextRange}; | 15 | use syntax::{algo, TextRange}; |
16 | use text_edit::TextEdit; | 16 | use text_edit::TextEdit; |
17 | 17 | ||
@@ -274,7 +274,7 @@ impl CompletionItem { | |||
274 | #[derive(Debug, Clone)] | 274 | #[derive(Debug, Clone)] |
275 | pub struct ImportEdit { | 275 | pub struct ImportEdit { |
276 | pub import: LocatedImport, | 276 | pub import: LocatedImport, |
277 | pub import_scope: ImportScope, | 277 | pub scope: ImportScope, |
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 = insert_use::insert_use( | 286 | let rewriter = insert_use::insert_use( |
287 | &self.import_scope, | 287 | &self.scope, |
288 | mod_path_to_ast(&self.import.import_path), | 288 | mod_path_to_ast(&self.import.import_path), |
289 | cfg, | 289 | cfg, |
290 | ); | 290 | ); |
@@ -302,7 +302,6 @@ impl ImportEdit { | |||
302 | pub(crate) struct Builder { | 302 | pub(crate) struct Builder { |
303 | source_range: TextRange, | 303 | source_range: TextRange, |
304 | completion_kind: CompletionKind, | 304 | completion_kind: CompletionKind, |
305 | // TODO kb also add a db here, to resolve the completion label? | ||
306 | import_to_add: Option<ImportEdit>, | 305 | import_to_add: Option<ImportEdit>, |
307 | label: String, | 306 | label: String, |
308 | insert_text: Option<String>, | 307 | insert_text: Option<String>, |
@@ -322,22 +321,24 @@ impl Builder { | |||
322 | pub(crate) fn build(self) -> CompletionItem { | 321 | pub(crate) fn build(self) -> CompletionItem { |
323 | let _p = profile::span("item::Builder::build"); | 322 | let _p = profile::span("item::Builder::build"); |
324 | 323 | ||
325 | let label = self.label; | 324 | let mut label = self.label; |
326 | let lookup = self.lookup; | 325 | let mut lookup = self.lookup; |
327 | let insert_text = self.insert_text; | 326 | let mut insert_text = self.insert_text; |
328 | 327 | ||
329 | if let Some(_import_to_add) = self.import_to_add.as_ref() { | 328 | if let Some(original_path) = self |
330 | todo!("todo kb") | 329 | .import_to_add |
331 | // let import = &import_to_add.import; | 330 | .as_ref() |
332 | // let item_to_import = import.item_to_import(); | 331 | .and_then(|import_edit| import_edit.import.original_path.as_ref()) |
333 | // lookup = lookup.or_else(|| Some(label.clone())); | 332 | { |
334 | // insert_text = insert_text.or_else(|| Some(label.clone())); | 333 | lookup = lookup.or_else(|| Some(label.clone())); |
335 | // let display_path = import_to_add.import.display_path(); | 334 | insert_text = insert_text.or_else(|| Some(label.clone())); |
336 | // if import_to_add.import { | 335 | |
337 | // label = format!("{} ({})", label, display_path); | 336 | let original_path_label = original_path.to_string(); |
338 | // } else { | 337 | if original_path_label.ends_with(&label) { |
339 | // label = display_path.to_string(); | 338 | label = original_path_label; |
340 | // } | 339 | } else { |
340 | format_to!(label, " ({})", original_path) | ||
341 | } | ||
341 | } | 342 | } |
342 | 343 | ||
343 | let text_edit = match self.text_edit { | 344 | let text_edit = match self.text_edit { |