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

Function getFragmentAround

lib/web/CodeMirror/addon/tern/tern.js:550–575  ·  view source on GitHub ↗
(data, start, end)

Source from the content-addressed store, hash-verified

548 }
549
550 function getFragmentAround(data, start, end) {
551 var doc = data.doc;
552 var minIndent = null, minLine = null, endLine, tabSize = 4;
553 for (var p = start.line - 1, min = Math.max(0, p - 50); p >= min; --p) {
554 var line = doc.getLine(p), fn = line.search(/\bfunction\b/);
555 if (fn < 0) continue;
556 var indent = CodeMirror.countColumn(line, null, tabSize);
557 if (minIndent != null && minIndent <= indent) continue;
558 minIndent = indent;
559 minLine = p;
560 }
561 if (minLine == null) minLine = min;
562 var max = Math.min(doc.lastLine(), end.line + 20);
563 if (minIndent == null || minIndent == CodeMirror.countColumn(doc.getLine(start.line), null, tabSize))
564 endLine = max;
565 else for (endLine = end.line + 1; endLine < max; ++endLine) {
566 var indent = CodeMirror.countColumn(doc.getLine(endLine), null, tabSize);
567 if (indent <= minIndent) break;
568 }
569 var from = Pos(minLine, 0);
570
571 return {type: "part",
572 name: data.name,
573 offsetLines: from.line,
574 text: doc.getRange(from, Pos(endLine, end.line == endLine ? null : 0))};
575 }
576
577 // Generic utilities
578

Callers 1

buildRequestFunction · 0.85

Calls 6

getLineMethod · 0.65
PosFunction · 0.50
maxMethod · 0.45
searchMethod · 0.45
minMethod · 0.45
getRangeMethod · 0.45

Tested by

no test coverage detected