MCPcopy Index your code
hub / github.com/bigcode-project/jupytercoder / _loop

Function _loop

src/diff.js:957–1041  ·  view source on GitHub ↗
(i)

Source from the content-addressed store, hash-verified

955 newLine = 1;
956
957 var _loop = function _loop(i) {
958 var current = diff[i],
959 lines = current.lines || current.value.replace(/\n$/, '').split('\n');
960 current.lines = lines;
961
962 if (current.added || current.removed) {
963 var _curRange;
964
965 // If we have previous context, start with that
966 if (!oldRangeStart) {
967 var prev = diff[i - 1];
968 oldRangeStart = oldLine;
969 newRangeStart = newLine;
970
971 if (prev) {
972 curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
973 oldRangeStart -= curRange.length;
974 newRangeStart -= curRange.length;
975 }
976 } // Output our changes
977
978
979 (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
980 return (current.added ? '+' : '-') + entry;
981 }))); // Track the updated file position
982
983
984 if (current.added) {
985 newLine += lines.length;
986 } else {
987 oldLine += lines.length;
988 }
989 } else {
990 // Identical context lines. Track line changes
991 if (oldRangeStart) {
992 // Close out any changes that have been output (or join overlapping)
993 if (lines.length <= options.context * 2 && i < diff.length - 2) {
994 var _curRange2;
995
996 // Overlapping
997 (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
998 } else {
999 var _curRange3;
1000
1001 // end the range and output
1002 var contextSize = Math.min(lines.length, options.context);
1003
1004 (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
1005
1006 var hunk = {
1007 oldStart: oldRangeStart,
1008 oldLines: oldLine - oldRangeStart + contextSize,
1009 newStart: newRangeStart,
1010 newLines: newLine - newRangeStart + contextSize,
1011 lines: curRange
1012 };
1013
1014 if (i >= diff.length - 2 && lines.length <= options.context) {

Callers 1

structuredPatchFunction · 0.85

Calls 2

contextLinesFunction · 0.85
_toConsumableArrayFunction · 0.85

Tested by

no test coverage detected