|
1 | 1 | import unicodedata |
2 | 2 | from collections import OrderedDict |
3 | | -from typing import Any, Dict, Iterator, OrderedDict as OrderedDictType |
| 3 | +from typing import Any, Dict, Tuple, Iterator, OrderedDict as OrderedDictType |
4 | 4 | from functools import total_ordering |
5 | 5 |
|
6 | 6 | def get_match_ordered_dict() -> OrderedDictType[str, type]: |
@@ -185,6 +185,23 @@ def matchedText(self) -> str: |
185 | 185 | :rtype: str |
186 | 186 | """ |
187 | 187 | return self.context[self.offsetInContext:self.offsetInContext+self.errorLength] |
| 188 | + |
| 189 | + def get_line_and_column(self, original_text: str) -> Tuple[int, int]: |
| 190 | + """ |
| 191 | + Returns the line and column number of the error in the context. |
| 192 | +
|
| 193 | + :param original_text: The original text in which the error occurred. We need this to calculate the line and column number, because the context has no more newline characters. |
| 194 | + :type original_text: str |
| 195 | + :return: A tuple containing the line and column number of the error. |
| 196 | + :rtype: Tuple[int, int] |
| 197 | + """ |
| 198 | + |
| 199 | + context_without_additions = self.context[3:-3] if len(self.context) > 6 else self.context |
| 200 | + if context_without_additions not in original_text.replace('\n', ' '): |
| 201 | + raise ValueError('The original text does not match the context of the error') |
| 202 | + line = original_text.count('\n', 0, self.offset) |
| 203 | + column = self.offset - original_text.rfind('\n', 0, self.offset) |
| 204 | + return line + 1, column |
188 | 205 |
|
189 | 206 | def select_replacement(self, index: int) -> None: |
190 | 207 | """ |
|
0 commit comments