bingocode 1.1.160 → 1.1.161
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -7,16 +7,16 @@ describe("findActualString", () => {
|
|
|
7
7
|
expect(findActualString(file, " bar")).toBe(" bar");
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
it("tab in file, spaces in search
|
|
10
|
+
it("tab in file, spaces in search => matches via indent normalization", () => {
|
|
11
11
|
const file = "\t\tfoo\n\t\tbar";
|
|
12
|
-
const result = findActualString(file, " bar"); //
|
|
12
|
+
const result = findActualString(file, " bar"); // model sent spaced ver
|
|
13
13
|
expect(result).toBe("\t\tbar");
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
it("spaces in file, tabs in search
|
|
17
|
-
const file = " bar"; // 4
|
|
18
|
-
const result = findActualString(file, "\tbar"); // tab
|
|
19
|
-
expect(result).toBe(" bar");
|
|
16
|
+
it("spaces in file, tabs in search => matches via indent normalization", () => {
|
|
17
|
+
const file = " bar"; // 4-space indented file
|
|
18
|
+
const result = findActualString(file, "\tbar"); // model sent tab version
|
|
19
|
+
expect(result).toBe(" bar"); // should return actual content from file
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it("normalizeIndentation trims leading whitespace", () => {
|
|
@@ -107,10 +107,25 @@ export function findActualString(
|
|
|
107
107
|
|
|
108
108
|
// Try with normalized leading whitespace (tab <-> space)
|
|
109
109
|
const indentNormalizedSearch = normalizeIndentation(searchString)
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
|
|
110
|
+
const indentTrimmedFile = normalizeIndentation(fileContent)
|
|
111
|
+
const matchPoint = indentTrimmedFile.indexOf(indentNormalizedSearch)
|
|
112
|
+
if (matchPoint !== -1) {
|
|
113
|
+
// Leading whitespace normalization is NOT length-preserving,
|
|
114
|
+
// so compute bounds by matching each trimmed line back to its original.
|
|
115
|
+
const origLines = fileContent.split('\n')
|
|
116
|
+
const trimmedLines = indentTrimmedFile.split('\n')
|
|
117
|
+
const searchLines = indentNormalizedSearch.split('\n')
|
|
118
|
+
for (let i = 0; i <= trimmedLines.length - searchLines.length; i++) {
|
|
119
|
+
let k = 0
|
|
120
|
+
while (k < searchLines.length && trimmedLines[i + k] === searchLines[k]) k++
|
|
121
|
+
if (k !== searchLines.length) continue
|
|
122
|
+
let start = 0
|
|
123
|
+
for (let j = 0; j < i; j++) start += origLines[j].length + 1
|
|
124
|
+
let end = start
|
|
125
|
+
for (let j = i; j < i + k; j++) end += origLines[j].length + 1
|
|
126
|
+
return fileContent.substring(start, Math.max(start, end - 1))
|
|
127
|
+
}
|
|
128
|
+
return null
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
return null
|