MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / findLineStart

Function findLineStart

lib/web/tern/tern.js:563–576  ·  view source on GitHub ↗
(file, line)

Source from the content-addressed store, hash-verified

561 var offsetSkipLines = 25;
562
563 function findLineStart(file, line) {
564 var text = file.text, offsets = file.lineOffsets || (file.lineOffsets = [0]);
565 var pos = 0, curLine = 0;
566 var storePos = Math.min(Math.floor(line / offsetSkipLines), offsets.length - 1);
567 var pos = offsets[storePos], curLine = storePos * offsetSkipLines;
568
569 while (curLine < line) {
570 ++curLine;
571 pos = text.indexOf("\n", pos) + 1;
572 if (pos === 0) return null;
573 if (curLine % offsetSkipLines === 0) offsets.push(pos);
574 }
575 return pos;
576 }
577
578 var resolvePos = exports.resolvePos = function(file, pos, tolerant) {
579 if (typeof pos != "number") {

Callers 1

tern.jsFile · 0.85

Calls 3

indexOfMethod · 0.80
minMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected