MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / build_enum_case_body

Function build_enum_case_body

src/hover/mod.rs:1657–1683  ·  view source on GitHub ↗

Build the body lines for an enum hover showing its cases. Only enum cases are shown (not regular class constants). Each case is rendered as ` case Name = 'value';` or ` case Name;`. If there are more than [`MAX_BODY_ITEMS`] cases, the list is truncated with a `// and N more…` comment.

(cls: &ClassInfo)

Source from the content-addressed store, hash-verified

1655/// If there are more than [`MAX_BODY_ITEMS`] cases, the list is truncated
1656/// with a `// and N more…` comment.
1657fn build_enum_case_body(cls: &ClassInfo) -> String {
1658 let cases: Vec<&ConstantInfo> = cls.constants.iter().filter(|c| c.is_enum_case).collect();
1659
1660 if cases.is_empty() {
1661 return String::new();
1662 }
1663
1664 let mut body = String::new();
1665 let shown = cases.len().min(MAX_BODY_ITEMS);
1666
1667 for case in &cases[..shown] {
1668 if let Some(ref val) = case.enum_value {
1669 body.push_str(&format!(" case {} = {};\n", case.name, val));
1670 } else {
1671 body.push_str(&format!(" case {};\n", case.name));
1672 }
1673 }
1674
1675 if cases.len() > MAX_BODY_ITEMS {
1676 body.push_str(&format!(
1677 " // and {} more…\n",
1678 cases.len() - MAX_BODY_ITEMS
1679 ));
1680 }
1681
1682 body
1683}
1684
1685/// Build the body lines for a trait hover showing public member signatures.
1686///

Callers 1

hover_for_class_infoMethod · 0.85

Calls 3

filterMethod · 0.80
iterMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected