Applies various processing to a raw code string (normalises it so it always ends with a line return, dedents it if necessary, etc.) Args: code (str): The raw code string to process Returns: Tuple[bool, str]: the boolean indicates whether the
(self, code: str)
| 821 | text.stylize(stylized_range.style, start, end) |
| 822 | |
| 823 | def _process_code(self, code: str) -> Tuple[bool, str]: |
| 824 | """ |
| 825 | Applies various processing to a raw code string |
| 826 | (normalises it so it always ends with a line return, dedents it if necessary, etc.) |
| 827 | |
| 828 | Args: |
| 829 | code (str): The raw code string to process |
| 830 | |
| 831 | Returns: |
| 832 | Tuple[bool, str]: the boolean indicates whether the raw code ends with a line return, |
| 833 | while the string is the processed code. |
| 834 | """ |
| 835 | ends_on_nl = code.endswith("\n") |
| 836 | processed_code = code if ends_on_nl else code + "\n" |
| 837 | processed_code = ( |
| 838 | textwrap.dedent(processed_code) if self.dedent else processed_code |
| 839 | ) |
| 840 | processed_code = processed_code.expandtabs(self.tab_size) |
| 841 | return ends_on_nl, processed_code |
| 842 | |
| 843 | |
| 844 | def _get_code_index_for_syntax_position( |