* @internal * We assume the first line starts at position 0 and 'position' is non-negative.
(lineStarts, position, lowerBound)
| 10353 | * We assume the first line starts at position 0 and 'position' is non-negative. |
| 10354 | */ |
| 10355 | function computeLineOfPosition(lineStarts, position, lowerBound) { |
| 10356 | var lineNumber = ts.binarySearch(lineStarts, position, ts.identity, ts.compareValues, lowerBound); |
| 10357 | if (lineNumber < 0) { |
| 10358 | // If the actual position was not found, |
| 10359 | // the binary search returns the 2's-complement of the next line start |
| 10360 | // e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20 |
| 10361 | // then the search will return -2. |
| 10362 | // |
| 10363 | // We want the index of the previous line start, so we subtract 1. |
| 10364 | // Review 2's-complement if this is confusing. |
| 10365 | lineNumber = ~lineNumber - 1; |
| 10366 | ts.Debug.assert(lineNumber !== -1, "position cannot precede the beginning of the file"); |
| 10367 | } |
| 10368 | return lineNumber; |
| 10369 | } |
| 10370 | ts.computeLineOfPosition = computeLineOfPosition; |
| 10371 | /** @internal */ |
| 10372 | function getLinesBetweenPositions(sourceFile, pos1, pos2) { |
no test coverage detected