(traceback: string[], cell: NotebookCell)
| 862 | } |
| 863 | |
| 864 | export function findErrorLocation(traceback: string[], cell: NotebookCell) { |
| 865 | const cellRegex = /Cell\s+In\s*\[(?<executionCount>\d+)\],\s*line (?<lineNumber>\d+).*/; |
| 866 | // older versions of IPython ~8.3.0 |
| 867 | const inputRegex = /Input\s+?In\s*\[(?<executionCount>\d+)\][^<]*<cell line:\s?(?<lineNumber>\d+)>.*/; |
| 868 | let lineNumber: number | undefined = undefined; |
| 869 | for (const line of traceback) { |
| 870 | const cleanLine = removeAnsiEscapeCodes(line); |
| 871 | const lineMatch = cellRegex.exec(cleanLine) ?? inputRegex.exec(cleanLine); |
| 872 | if (lineMatch && lineMatch.groups) { |
| 873 | lineNumber = parseInt(lineMatch.groups['lineNumber']); |
| 874 | break; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | let range: Range | undefined = undefined; |
| 879 | if (lineNumber && lineNumber > 0 && lineNumber <= cell.document.lineCount) { |
| 880 | const line = cell.document.lineAt(lineNumber - 1); |
| 881 | const end = line.text.split('#')[0].trimEnd().length; |
| 882 | |
| 883 | range = new Range( |
| 884 | new Position(line.lineNumber, line.firstNonWhitespaceCharacterIndex), |
| 885 | new Position(line.lineNumber, end) |
| 886 | ); |
| 887 | } |
| 888 | |
| 889 | return range; |
| 890 | } |
no test coverage detected