MCPcopy
hub / github.com/ternjs/tern / findLineStart

Function findLineStart

lib/tern.js:579–592  ·  view source on GitHub ↗
(file, line)

Source from the content-addressed store, hash-verified

577 }
578
579 function findLineStart(file, line) {
580 var text = file.text, offsets = file.lineOffsets || (file.lineOffsets = [0]);
581 var pos = 0, curLine = 0;
582 var storePos = Math.min(Math.floor(line / offsetSkipLines), offsets.length - 1);
583 var pos = offsets[storePos], curLine = storePos * offsetSkipLines;
584
585 while (curLine < line) {
586 ++curLine;
587 pos = text.indexOf("\n", pos) + 1;
588 if (pos === 0) return null;
589 if (curLine % offsetSkipLines === 0) offsets.push(pos);
590 }
591 return pos;
592 }
593
594 var resolvePos = exports.resolvePos = function(file, pos, tolerant) {
595 if (typeof pos != "number") {

Callers 1

tern.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…