Calculates the offset at a given position in a document. Args: doc (str): The document content. position (dict): The position object containing the line and character. Returns: int: The offset at the given position.
(doc, position)
| 256 | return doc[offset_at_position(doc, range["start"]):offset_at_position(doc, range["end"])] |
| 257 | |
| 258 | def offset_at_position(doc, position): |
| 259 | """ |
| 260 | Calculates the offset at a given position in a document. |
| 261 | |
| 262 | Args: |
| 263 | doc (str): The document content. |
| 264 | position (dict): The position object containing the line and character. |
| 265 | |
| 266 | Returns: |
| 267 | int: The offset at the given position. |
| 268 | """ |
| 269 | return position["character"] + len("".join(doc.splitlines(True)[: position["line"]])) |
| 270 | |
| 271 | def save_infos_to_folder(infos_dict, name, folder): |
| 272 | if not os.path.exists(folder): |