* Converts from a base 0 line and column to a file offset.
(position: IPosition)
| 75 | * Converts from a base 0 line and column to a file offset. |
| 76 | */ |
| 77 | public convert(position: IPosition) { |
| 78 | const base0 = position.base0; |
| 79 | if (base0.lineNumber > this.lines.length) { |
| 80 | return this.source.length; |
| 81 | } |
| 82 | |
| 83 | const thisLine = this.lines[base0.lineNumber]; |
| 84 | const nextLine = this.lines[base0.lineNumber + 1] ?? this.source.length + 1; |
| 85 | |
| 86 | return thisLine + Math.min(nextLine - thisLine - 1, base0.columnNumber); |
| 87 | } |
| 88 | } |