MCPcopy Index your code
hub / github.com/nodejs/node / computeLineOfPosition

Function computeLineOfPosition

test/fixtures/snapshot/typescript.js:10355–10369  ·  view source on GitHub ↗

* @internal * We assume the first line starts at position 0 and 'position' is non-negative.

(lineStarts, position, lowerBound)

Source from the content-addressed store, hash-verified

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) {

Callers 2

getLinesBetweenPositionsFunction · 0.85

Calls 1

assertMethod · 0.80

Tested by

no test coverage detected