diff options
Diffstat (limited to 'crates/completion/src/item.rs')
-rw-r--r-- | crates/completion/src/item.rs | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 978ea76f9..bd94402d7 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs | |||
@@ -209,7 +209,6 @@ impl CompletionItem { | |||
209 | score: None, | 209 | score: None, |
210 | ref_match: None, | 210 | ref_match: None, |
211 | import_to_add: None, | 211 | import_to_add: None, |
212 | resolve_import_lazily: false, | ||
213 | } | 212 | } |
214 | } | 213 | } |
215 | 214 | ||
@@ -301,7 +300,6 @@ pub(crate) struct Builder { | |||
301 | source_range: TextRange, | 300 | source_range: TextRange, |
302 | completion_kind: CompletionKind, | 301 | completion_kind: CompletionKind, |
303 | import_to_add: Option<ImportEdit>, | 302 | import_to_add: Option<ImportEdit>, |
304 | resolve_import_lazily: bool, | ||
305 | label: String, | 303 | label: String, |
306 | insert_text: Option<String>, | 304 | insert_text: Option<String>, |
307 | insert_text_format: InsertTextFormat, | 305 | insert_text_format: InsertTextFormat, |
@@ -339,25 +337,13 @@ impl Builder { | |||
339 | } | 337 | } |
340 | } | 338 | } |
341 | 339 | ||
342 | let mut text_edit = match self.text_edit { | 340 | let text_edit = match self.text_edit { |
343 | Some(it) => it, | 341 | Some(it) => it, |
344 | None => { | 342 | None => { |
345 | TextEdit::replace(self.source_range, insert_text.unwrap_or_else(|| label.clone())) | 343 | TextEdit::replace(self.source_range, insert_text.unwrap_or_else(|| label.clone())) |
346 | } | 344 | } |
347 | }; | 345 | }; |
348 | 346 | ||
349 | let import_to_add = if self.resolve_import_lazily { | ||
350 | self.import_to_add | ||
351 | } else { | ||
352 | match apply_import_eagerly(self.import_to_add.as_ref(), &mut text_edit) { | ||
353 | Ok(()) => self.import_to_add, | ||
354 | Err(()) => { | ||
355 | log::error!("Failed to apply eager import edit: original edit and import edit intersect"); | ||
356 | None | ||
357 | } | ||
358 | } | ||
359 | }; | ||
360 | |||
361 | CompletionItem { | 347 | CompletionItem { |
362 | source_range: self.source_range, | 348 | source_range: self.source_range, |
363 | label, | 349 | label, |
@@ -372,7 +358,7 @@ impl Builder { | |||
372 | trigger_call_info: self.trigger_call_info.unwrap_or(false), | 358 | trigger_call_info: self.trigger_call_info.unwrap_or(false), |
373 | score: self.score, | 359 | score: self.score, |
374 | ref_match: self.ref_match, | 360 | ref_match: self.ref_match, |
375 | import_to_add, | 361 | import_to_add: self.import_to_add, |
376 | } | 362 | } |
377 | } | 363 | } |
378 | pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder { | 364 | pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder { |
@@ -435,13 +421,8 @@ impl Builder { | |||
435 | self.trigger_call_info = Some(true); | 421 | self.trigger_call_info = Some(true); |
436 | self | 422 | self |
437 | } | 423 | } |
438 | pub(crate) fn add_import( | 424 | pub(crate) fn add_import(mut self, import_to_add: Option<ImportEdit>) -> Builder { |
439 | mut self, | ||
440 | import_to_add: Option<ImportEdit>, | ||
441 | resolve_import_lazily: bool, | ||
442 | ) -> Builder { | ||
443 | self.import_to_add = import_to_add; | 425 | self.import_to_add = import_to_add; |
444 | self.resolve_import_lazily = resolve_import_lazily; | ||
445 | self | 426 | self |
446 | } | 427 | } |
447 | pub(crate) fn set_ref_match( | 428 | pub(crate) fn set_ref_match( |
@@ -453,16 +434,6 @@ impl Builder { | |||
453 | } | 434 | } |
454 | } | 435 | } |
455 | 436 | ||
456 | fn apply_import_eagerly( | ||
457 | import_to_add: Option<&ImportEdit>, | ||
458 | original_edit: &mut TextEdit, | ||
459 | ) -> Result<(), ()> { | ||
460 | match import_to_add.and_then(|import_edit| import_edit.to_text_edit()) { | ||
461 | Some(import_edit) => original_edit.union(import_edit).map_err(|_| ()), | ||
462 | None => Ok(()), | ||
463 | } | ||
464 | } | ||
465 | |||
466 | impl<'a> Into<CompletionItem> for Builder { | 437 | impl<'a> Into<CompletionItem> for Builder { |
467 | fn into(self) -> CompletionItem { | 438 | fn into(self) -> CompletionItem { |
468 | self.build() | 439 | self.build() |