Merge the class name from a new item's `data` into the existing item's `data.extra_class_names` so that `completionItem/resolve` can iterate all union branches when building hover documentation.
(existing: &mut CompletionItem, new_item: &CompletionItem)
| 683 | /// `data.extra_class_names` so that `completionItem/resolve` can iterate |
| 684 | /// all union branches when building hover documentation. |
| 685 | fn merge_data_class_names(existing: &mut CompletionItem, new_item: &CompletionItem) { |
| 686 | let (Some(existing_data), Some(new_data)) = (&existing.data, &new_item.data) else { |
| 687 | return; |
| 688 | }; |
| 689 | let (Ok(mut ed), Ok(nd)) = ( |
| 690 | serde_json::from_value::<CompletionItemData>(existing_data.clone()), |
| 691 | serde_json::from_value::<CompletionItemData>(new_data.clone()), |
| 692 | ) else { |
| 693 | return; |
| 694 | }; |
| 695 | // Skip if the class name is already recorded. |
| 696 | if ed.class_name == nd.class_name || ed.extra_class_names.contains(&nd.class_name) { |
| 697 | return; |
| 698 | } |
| 699 | ed.extra_class_names.push(nd.class_name.clone()); |
| 700 | if let Ok(v) = serde_json::to_value(&ed) { |
| 701 | existing.data = Some(v); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | /// Extract the class name(s) from a `CompletionItem`'s `data` field. |
| 706 | /// |
no test coverage detected