(out: list[str], ast: Ast)
| 1050 | |
| 1051 | |
| 1052 | def write_node(out: list[str], ast: Ast) -> None: |
| 1053 | group_names = [group.name for group in ast.groups] |
| 1054 | for group in ast.groups: |
| 1055 | for node in group.nodes: |
| 1056 | if node.fields is None: |
| 1057 | continue |
| 1058 | if node.doc is not None: |
| 1059 | write_rustdoc(out, node.doc) |
| 1060 | out.append( |
| 1061 | "#[derive(Clone" |
| 1062 | + ("" if node.custom_debug else ", Debug") |
| 1063 | + ", PartialEq" |
| 1064 | + "".join(f", {derive}" for derive in node.derives) |
| 1065 | + ")]" |
| 1066 | ) |
| 1067 | out.append('#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]') |
| 1068 | name = node.name |
| 1069 | out.append(f"pub struct {name} {{") |
| 1070 | out.append("pub node_index: crate::AtomicNodeIndex,") |
| 1071 | if not node.custom_range: |
| 1072 | out.append("pub range: ruff_text_size::TextRange,") |
| 1073 | for field in node.fields: |
| 1074 | field_str = f"pub {field.name}: " |
| 1075 | ty = field.parsed_ty |
| 1076 | |
| 1077 | rust_ty = f"{field.parsed_ty.name}" |
| 1078 | if ty.name in types_requiring_crate_prefix: |
| 1079 | rust_ty = f"crate::{rust_ty}" |
| 1080 | |
| 1081 | if ty.sequence_kind is SequenceKind.VEC: |
| 1082 | rust_ty = f"Vec<{rust_ty}>" |
| 1083 | elif ty.sequence_kind is SequenceKind.BOXED_SLICE: |
| 1084 | rust_ty = f"Box<[{rust_ty}]>" |
| 1085 | elif ty.sequence_kind is SequenceKind.THIN_VEC: |
| 1086 | rust_ty = f"thin_vec::ThinVec<{rust_ty}>" |
| 1087 | else: |
| 1088 | if ty.name in group_names: |
| 1089 | rust_ty = f"Box<{rust_ty}>" |
| 1090 | if ty.optional: |
| 1091 | rust_ty = f"Option<{rust_ty}>" |
| 1092 | |
| 1093 | field_str += rust_ty + "," |
| 1094 | out.append(field_str) |
| 1095 | out.append("}") |
| 1096 | out.append("") |
| 1097 | |
| 1098 | |
| 1099 | # ------------------------------------------------------------------------------ |
no test coverage detected