Function
_slice_context
(
lines: Sequence[str],
center_line: int,
span: int,
*,
before: bool,
)
Source from the content-addressed store, hash-verified
| 1079 | |
| 1080 | |
| 1081 | def _slice_context( |
| 1082 | lines: Sequence[str], |
| 1083 | center_line: int, |
| 1084 | span: int, |
| 1085 | *, |
| 1086 | before: bool, |
| 1087 | ) -> List[str]: |
| 1088 | if span <= 0: |
| 1089 | return [] |
| 1090 | if before: |
| 1091 | start_line = max(center_line - span, 1) |
| 1092 | end_line = center_line - 1 |
| 1093 | else: |
| 1094 | start_line = center_line + 1 |
| 1095 | end_line = min(center_line + span, len(lines)) |
| 1096 | if end_line < start_line: |
| 1097 | return [] |
| 1098 | start_idx = start_line - 1 |
| 1099 | end_idx = end_line |
| 1100 | return list(lines[start_idx:end_idx]) |
Tested by
no test coverage detected