{"record":{"id":"fc98b3a5740ec03d","repo":"oraios/serena","slug":"line-col","errorCode":null,"errorMessage":"{line=}, {col=}","messagePattern":"\\{line=\\}, \\{col=\\}","errorType":"validation","errorClass":"InvalidTextLocationError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/ls_utils.py","lineNumber":235,"sourceCode":"        :param text: the text in which the index is to be located\n        :param index: the 0-based index in the text\n        :return: the 0-based line number corresponding to the index in the text\n        \"\"\"\n        return cls.get_line_col_from_index(text, index)[0]\n\n    @staticmethod\n    def get_index_from_line_col(text: str, line: int, col: int) -> int:\n        \"\"\"\n        :param text: the text in which the coordinates are to be located\n        :param line: the 0-based line number\n        :param col: the 0-based column number\n        :return: the corresponding 0-based index in the text\n        \"\"\"\n        # step over full lines until the requested line is reached\n        text_stepper = TextStepper(text)\n        while text_stepper.line < line:\n            if not text_stepper.step_line():\n                raise InvalidTextLocationError(f\"{line=}, {col=}\")\n\n        return text_stepper.line_start_idx + col\n\n    @staticmethod\n    def _get_updated_position_from_line_and_column_and_edit(l: int, c: int, text_to_be_inserted: str) -> tuple[int, int]:\n        \"\"\"\n        :param l: the 0-based line number before the edit\n        :param c: the 0-based column number before the edit\n        :param text_to_be_inserted: the text that was inserted at the given position\n        :return: the updated 0-based line and column numbers after the edit (end of insertion)\n        \"\"\"\n        text_stepper = TextStepper(text_to_be_inserted)\n        text_stepper.process_all()\n        if text_stepper.line > 0:\n            l += text_stepper.line\n            c = text_stepper.col\n        else:\n            c += text_stepper.col","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/ls_utils.py#L217-L253","documentation":"InvalidTextLocationError with the offending line/col raised by FileUtils.get_index_from_line_col (src/solidlsp/ls_utils.py:235) when the requested line number is beyond the last line of the text, so stepping to that line fails.","triggerScenarios":"Calling get_index_from_line_col(text, line, col) (directly or via insert_text_at_position, get_text_in_range, delete_text_between_positions) with a line >= number of lines in the document.","commonSituations":"LSP positions from another (longer) document version applied to the current text; appends computed with line == len(lines) instead of the last valid 0-based index; range values from external tools.","solutions":["Validate line < number of lines before conversion, clamping to the last line for appends.","Recompute positions from the current document state.","Verify 0-based line/col conventions across the integration."],"exampleFix":"// before\nidx = FileUtils.get_index_from_line_col(text, 1000, 0)\n// after\nline = min(line, len(text.splitlines()) - 1)\nidx = FileUtils.get_index_from_line_col(text, line, col)","handlingStrategy":"validation","validationCode":"def valid_line(text: str, line: int) -> bool:\n    return 0 <= line < len(text.splitlines())","typeGuard":"def clamp_line(text: str, line: int) -> int:\n    return max(0, min(line, len(text.splitlines()) - 1))","tryCatchPattern":"try:\n    idx = FileUtils.get_index_from_line_col(text, line, col)\nexcept InvalidTextLocationError:\n    idx = len(text)","preventionTips":["Clamp line numbers to the last valid line before conversion","Recompute LSP positions against the live document version","Use version numbers (e.g. LSP textDocument version) to detect stale positions"],"tags":["text-location","bounds","position"],"backgroundTag":"text-location-out-of-range","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}