token-goat 2.9.20 → 2.9.22
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/THIRD_PARTY_NOTICES.md +2 -2
- package/dist/{token-goat-chunk-GIPMOGOI.mjs → token-goat-chunk-273O227F.mjs} +5 -5
- package/dist/{token-goat-chunk-3VTJC7KU.mjs → token-goat-chunk-2GAK6LNK.mjs} +13 -12
- package/dist/{token-goat-chunk-QCQUIPIP.mjs → token-goat-chunk-3U6ZYVX5.mjs} +1582 -773
- package/dist/{token-goat-chunk-W6QYCWAT.mjs → token-goat-chunk-4642QVSQ.mjs} +6 -6
- package/dist/{token-goat-chunk-VYXGHGUY.mjs → token-goat-chunk-47MFMDCL.mjs} +3 -3
- package/dist/{token-goat-chunk-ZHFM4DHJ.mjs → token-goat-chunk-4NS4CAKI.mjs} +2 -2
- package/dist/{token-goat-chunk-ASTBLE2R.mjs → token-goat-chunk-4QGFVPFJ.mjs} +3 -3
- package/dist/{token-goat-chunk-H4VC5TR6.mjs → token-goat-chunk-4W2SZZIL.mjs} +27 -27
- package/dist/{token-goat-chunk-ERGHDBC6.mjs → token-goat-chunk-646GCK7P.mjs} +213 -208
- package/dist/{token-goat-chunk-3OGZOFLS.mjs → token-goat-chunk-6MTX77BB.mjs} +17 -17
- package/dist/{token-goat-chunk-VSJGPEBB.mjs → token-goat-chunk-75DLQORE.mjs} +4 -4
- package/dist/{token-goat-chunk-Z4ALQADF.mjs → token-goat-chunk-765U7OJS.mjs} +23 -21
- package/dist/{token-goat-chunk-DNAF26L4.mjs → token-goat-chunk-7TAFIQS4.mjs} +1 -1
- package/dist/{token-goat-chunk-T6M7DAW3.mjs → token-goat-chunk-CHLHM42P.mjs} +13 -1
- package/dist/{token-goat-chunk-T63VHOL3.mjs → token-goat-chunk-CTPTUL7L.mjs} +16 -2
- package/dist/{token-goat-chunk-SP5QR2HN.mjs → token-goat-chunk-CVPCUQON.mjs} +3 -3
- package/dist/{token-goat-chunk-2CLWWRFR.mjs → token-goat-chunk-DMCYWDMB.mjs} +10 -10
- package/dist/{token-goat-chunk-74ADIZZX.mjs → token-goat-chunk-DN4HSMH7.mjs} +1 -1
- package/dist/{token-goat-chunk-PTW22MRC.mjs → token-goat-chunk-EU5KDBII.mjs} +1 -1
- package/dist/{token-goat-chunk-2Q3N5KUQ.mjs → token-goat-chunk-FI4MIIER.mjs} +54 -38
- package/dist/{token-goat-chunk-ONMU7BON.mjs → token-goat-chunk-G7NIU2HH.mjs} +2 -2
- package/dist/{token-goat-chunk-MNJWG2ZO.mjs → token-goat-chunk-GKZLHNGN.mjs} +2 -2
- package/dist/{token-goat-chunk-BQIC3AVL.mjs → token-goat-chunk-HCEW3KTN.mjs} +2 -2
- package/dist/{token-goat-chunk-DYUBZZNP.mjs → token-goat-chunk-HGXKWLYQ.mjs} +10 -10
- package/dist/{token-goat-chunk-CBXLE54Q.mjs → token-goat-chunk-I4OCEISJ.mjs} +8 -8
- package/dist/{token-goat-chunk-KT75DZK4.mjs → token-goat-chunk-JGQ2SBAA.mjs} +4 -4
- package/dist/{token-goat-chunk-6LJNM4ZZ.mjs → token-goat-chunk-K5KG65OI.mjs} +1 -1
- package/dist/{token-goat-chunk-DW4VKU7D.mjs → token-goat-chunk-KJCMNJCG.mjs} +4 -4
- package/dist/{token-goat-chunk-K3ZNBN4U.mjs → token-goat-chunk-LPOEPINH.mjs} +2 -2
- package/dist/{token-goat-chunk-DPHJU3P7.mjs → token-goat-chunk-N3UUZAYN.mjs} +60 -27
- package/dist/{token-goat-chunk-ODF7H7WS.mjs → token-goat-chunk-N6WCYKW5.mjs} +2 -2
- package/dist/{token-goat-chunk-P4XBHZXU.mjs → token-goat-chunk-ONXXR7MS.mjs} +1 -1
- package/dist/{token-goat-chunk-ITWYDOKP.mjs → token-goat-chunk-OSLK5MBY.mjs} +4 -4
- package/dist/{token-goat-chunk-AU2K2QHR.mjs → token-goat-chunk-PQD6JTXN.mjs} +3 -3
- package/dist/{token-goat-chunk-T46UKRFM.mjs → token-goat-chunk-SLE5MVTU.mjs} +1 -1
- package/dist/{token-goat-chunk-PAVWB4L4.mjs → token-goat-chunk-TD5JS4ST.mjs} +3 -3
- package/dist/{token-goat-chunk-EUZKG7ZO.mjs → token-goat-chunk-TEK5LV6B.mjs} +3 -3
- package/dist/{token-goat-chunk-FWYZVS3E.mjs → token-goat-chunk-VRS6B7UD.mjs} +10 -14
- package/dist/{token-goat-chunk-I5PQRHFE.mjs → token-goat-chunk-VVPAGLLE.mjs} +8 -8
- package/dist/{token-goat-chunk-OMNQUUIT.mjs → token-goat-chunk-XBESNWEX.mjs} +1 -1
- package/dist/token-goat-chunk-YDPJCY62.mjs +41 -0
- package/dist/{token-goat-chunk-SL454EN5.mjs → token-goat-chunk-YHCUBOVZ.mjs} +5 -5
- package/dist/{token-goat-chunk-K5XPIUVB.mjs → token-goat-chunk-YVCGELLH.mjs} +3 -3
- package/dist/{token-goat-chunk-MUJV7BR3.mjs → token-goat-chunk-ZO6OALTM.mjs} +1 -1
- package/dist/token-goat-hook.mjs +17 -17
- package/dist/token-goat.core.mjs +27 -27
- package/package.json +1 -1
- package/dist/token-goat-chunk-G6SYQQO7.mjs +0 -41
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
pathEqClause,
|
|
5
5
|
projectScopeClause,
|
|
6
6
|
querySymbols
|
|
7
|
-
} from "./token-goat-chunk-
|
|
7
|
+
} from "./token-goat-chunk-LPOEPINH.mjs";
|
|
8
8
|
import {
|
|
9
9
|
TREE_SITTER_LANGUAGES,
|
|
10
10
|
_detectOpenQuote,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
detectLanguage,
|
|
14
14
|
findHtmlHeadingMatches,
|
|
15
15
|
getDb,
|
|
16
|
+
lineTextAt,
|
|
16
17
|
offsetToLine,
|
|
17
18
|
precedingDocComment,
|
|
18
19
|
redactIfDotenv,
|
|
@@ -21,11 +22,11 @@ import {
|
|
|
21
22
|
stripJsComments,
|
|
22
23
|
stripStringLiterals,
|
|
23
24
|
stripXmlComments
|
|
24
|
-
} from "./token-goat-chunk-
|
|
25
|
+
} from "./token-goat-chunk-CTPTUL7L.mjs";
|
|
25
26
|
import {
|
|
26
27
|
fingerprintContent,
|
|
27
28
|
loadConfig
|
|
28
|
-
} from "./token-goat-chunk-
|
|
29
|
+
} from "./token-goat-chunk-DN4HSMH7.mjs";
|
|
29
30
|
import {
|
|
30
31
|
registerReset
|
|
31
32
|
} from "./token-goat-chunk-EEIDFMEM.mjs";
|
|
@@ -39,7 +40,7 @@ import {
|
|
|
39
40
|
foldPath,
|
|
40
41
|
globalDbPath,
|
|
41
42
|
isCaseInsensitiveFs
|
|
42
|
-
} from "./token-goat-chunk-
|
|
43
|
+
} from "./token-goat-chunk-K5KG65OI.mjs";
|
|
43
44
|
import {
|
|
44
45
|
displaySafeText,
|
|
45
46
|
normalizePath
|
|
@@ -74,11 +75,11 @@ async function extractEmbeddableDocumentText(filePath) {
|
|
|
74
75
|
return text;
|
|
75
76
|
}
|
|
76
77
|
case ".docx":
|
|
77
|
-
return await (await import("./token-goat-chunk-
|
|
78
|
+
return await (await import("./token-goat-chunk-47MFMDCL.mjs")).docxText(filePath);
|
|
78
79
|
case ".pptx":
|
|
79
|
-
return await (await import("./token-goat-chunk-
|
|
80
|
+
return await (await import("./token-goat-chunk-4QGFVPFJ.mjs")).pptxAllSlidesText(filePath, true);
|
|
80
81
|
case ".xlsx":
|
|
81
|
-
return await (await import("./token-goat-chunk-
|
|
82
|
+
return await (await import("./token-goat-chunk-KJCMNJCG.mjs")).allSheetsHeadText(filePath, XLSX_SHEET_ROW_CAP);
|
|
82
83
|
default:
|
|
83
84
|
return null;
|
|
84
85
|
}
|
|
@@ -872,14 +873,14 @@ function packVec(vec) {
|
|
|
872
873
|
}
|
|
873
874
|
return Buffer.from(view.buffer);
|
|
874
875
|
}
|
|
875
|
-
function splitRangeIntoChunks(filePath,
|
|
876
|
+
function splitRangeIntoChunks(filePath, lines, rangeStart, rangeEnd, chunkSize, overlap, kind, countTokens) {
|
|
876
877
|
const chunks = [];
|
|
877
878
|
const lineTokenCache = /* @__PURE__ */ new Map();
|
|
878
879
|
const tokensOf = (lineNo) => {
|
|
879
880
|
if (countTokens === void 0) return 0;
|
|
880
881
|
let n = lineTokenCache.get(lineNo);
|
|
881
882
|
if (n === void 0) {
|
|
882
|
-
n = countTokens(
|
|
883
|
+
n = countTokens(lines[lineNo - 1] ?? "");
|
|
883
884
|
lineTokenCache.set(lineNo, n);
|
|
884
885
|
}
|
|
885
886
|
return n;
|
|
@@ -889,7 +890,7 @@ function splitRangeIntoChunks(filePath, lines2, rangeStart, rangeEnd, chunkSize,
|
|
|
889
890
|
let startLine = rangeStart;
|
|
890
891
|
let currentLine = rangeStart;
|
|
891
892
|
for (let lineNo = rangeStart; lineNo <= rangeEnd; lineNo++) {
|
|
892
|
-
const line =
|
|
893
|
+
const line = lines[lineNo - 1] ?? "";
|
|
893
894
|
const lineWithNewline = line + "\n";
|
|
894
895
|
const lineTokens = tokensOf(lineNo);
|
|
895
896
|
if ((currentChunk.length + lineWithNewline.length > chunkSize || currentTokens + lineTokens > MAX_CHUNK_TOKENS) && currentChunk.length > 0) {
|
|
@@ -908,7 +909,7 @@ function splitRangeIntoChunks(filePath, lines2, rangeStart, rangeEnd, chunkSize,
|
|
|
908
909
|
let overlapTokens = 0;
|
|
909
910
|
let computedOverlapStart = currentLine;
|
|
910
911
|
while (computedOverlapStart > rangeStart) {
|
|
911
|
-
const candidateChars = (
|
|
912
|
+
const candidateChars = (lines[computedOverlapStart - 2] ?? "").length + 1;
|
|
912
913
|
if (overlapChars + candidateChars > overlap) break;
|
|
913
914
|
const candidateTokens = tokensOf(computedOverlapStart - 1);
|
|
914
915
|
if (overlapTokens + candidateTokens + lineTokens > MAX_CHUNK_TOKENS) break;
|
|
@@ -919,7 +920,7 @@ function splitRangeIntoChunks(filePath, lines2, rangeStart, rangeEnd, chunkSize,
|
|
|
919
920
|
const droppedChunkHadContent = currentChunkTooSmall && trimmedLength > 0;
|
|
920
921
|
const overlapStart = droppedChunkHadContent ? Math.min(computedOverlapStart, startLine) : computedOverlapStart;
|
|
921
922
|
if (overlapStart !== startLine) {
|
|
922
|
-
const overlapText =
|
|
923
|
+
const overlapText = lines.slice(overlapStart - 1, currentLine - 1).join("\n");
|
|
923
924
|
currentChunk = overlapText + "\n";
|
|
924
925
|
currentTokens = overlapTokens;
|
|
925
926
|
startLine = overlapStart;
|
|
@@ -955,7 +956,7 @@ function splitRangeIntoChunks(filePath, lines2, rangeStart, rangeEnd, chunkSize,
|
|
|
955
956
|
for (let lineNo = last.startLine; lineNo <= rangeEnd; lineNo++) mergedTokens += tokensOf(lineNo);
|
|
956
957
|
if (mergedTokens <= MAX_CHUNK_TOKENS) {
|
|
957
958
|
last.endLine = rangeEnd;
|
|
958
|
-
last.text =
|
|
959
|
+
last.text = lines.slice(last.startLine - 1, rangeEnd).join("\n").trim();
|
|
959
960
|
} else if (currentChunk.trim().length > 0) {
|
|
960
961
|
chunks.push({ filePath, startLine, endLine: rangeEnd, text: currentChunk.trim(), kind });
|
|
961
962
|
}
|
|
@@ -982,11 +983,11 @@ function splitToFit(text, fits) {
|
|
|
982
983
|
return [...splitToFit(text.slice(0, cut), fits), ...splitToFit(text.slice(cut), fits)];
|
|
983
984
|
}
|
|
984
985
|
function chunkFile(filePath, content, chunkSize = MAX_CHUNK_CHARS, overlap = 200, boundaries = [], countTokens) {
|
|
985
|
-
const
|
|
986
|
-
if (
|
|
987
|
-
const totalLines =
|
|
986
|
+
const lines = content.split(/\r?\n/);
|
|
987
|
+
if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
|
|
988
|
+
const totalLines = lines.length;
|
|
988
989
|
if (boundaries.length === 0) {
|
|
989
|
-
return splitRangeIntoChunks(filePath,
|
|
990
|
+
return splitRangeIntoChunks(filePath, lines, 1, totalLines, chunkSize, overlap, "window", countTokens);
|
|
990
991
|
}
|
|
991
992
|
const clipped = boundaries.map((b) => ({
|
|
992
993
|
start: Math.max(1, Math.min(b.start, totalLines)),
|
|
@@ -994,7 +995,7 @@ function chunkFile(filePath, content, chunkSize = MAX_CHUNK_CHARS, overlap = 200
|
|
|
994
995
|
kind: b.kind
|
|
995
996
|
})).filter((b) => b.end >= b.start).sort((a, b) => a.start - b.start || b.end - a.end);
|
|
996
997
|
if (clipped.length === 0) {
|
|
997
|
-
return splitRangeIntoChunks(filePath,
|
|
998
|
+
return splitRangeIntoChunks(filePath, lines, 1, totalLines, chunkSize, overlap, "window", countTokens);
|
|
998
999
|
}
|
|
999
1000
|
const flattened = [];
|
|
1000
1001
|
let openEnd = 0;
|
|
@@ -1006,7 +1007,7 @@ function chunkFile(filePath, content, chunkSize = MAX_CHUNK_CHARS, overlap = 200
|
|
|
1006
1007
|
}
|
|
1007
1008
|
const gapLength = (start, end) => {
|
|
1008
1009
|
let text = "";
|
|
1009
|
-
for (let lineNo = start; lineNo <= end; lineNo++) text += (
|
|
1010
|
+
for (let lineNo = start; lineNo <= end; lineNo++) text += (lines[lineNo - 1] ?? "") + "\n";
|
|
1010
1011
|
return text.trim().length;
|
|
1011
1012
|
};
|
|
1012
1013
|
const ranges = [];
|
|
@@ -1061,7 +1062,7 @@ function chunkFile(filePath, content, chunkSize = MAX_CHUNK_CHARS, overlap = 200
|
|
|
1061
1062
|
}
|
|
1062
1063
|
const chunks = [];
|
|
1063
1064
|
for (const r of ranges) {
|
|
1064
|
-
chunks.push(...splitRangeIntoChunks(filePath,
|
|
1065
|
+
chunks.push(...splitRangeIntoChunks(filePath, lines, r.start, r.end, chunkSize, overlap, r.kind, countTokens));
|
|
1065
1066
|
}
|
|
1066
1067
|
return chunks;
|
|
1067
1068
|
}
|
|
@@ -1469,60 +1470,60 @@ init_define_import_meta_env();
|
|
|
1469
1470
|
|
|
1470
1471
|
// src/parser_fingerprint.ts
|
|
1471
1472
|
init_define_import_meta_env();
|
|
1472
|
-
var PARSER_FINGERPRINT = "
|
|
1473
|
+
var PARSER_FINGERPRINT = "4a3655d5cfe03a53";
|
|
1473
1474
|
var LANGUAGE_PARSER_FINGERPRINTS = /* @__PURE__ */ new Map([
|
|
1474
|
-
["abap", "
|
|
1475
|
-
["abl", "
|
|
1476
|
-
["apache", "
|
|
1477
|
-
["apex", "
|
|
1478
|
-
["asm", "
|
|
1479
|
-
["bash", "
|
|
1480
|
-
["batch", "
|
|
1481
|
-
["caddy", "
|
|
1482
|
-
["clojure", "
|
|
1483
|
-
["cmake", "
|
|
1484
|
-
["common_lisp", "
|
|
1485
|
-
["csharp", "
|
|
1486
|
-
["dart", "
|
|
1487
|
-
["elixir", "
|
|
1488
|
-
["emacs_lisp", "
|
|
1489
|
-
["erlang", "
|
|
1490
|
-
["fortran", "
|
|
1491
|
-
["fsharp", "
|
|
1492
|
-
["graphql", "
|
|
1493
|
-
["groovy", "
|
|
1494
|
-
["haskell", "
|
|
1495
|
-
["jcl", "
|
|
1496
|
-
["kotlin", "
|
|
1497
|
-
["liquid", "
|
|
1498
|
-
["lua", "
|
|
1499
|
-
["makefile", "
|
|
1500
|
-
["matlab", "
|
|
1501
|
-
["nginx", "
|
|
1502
|
-
["nix", "
|
|
1503
|
-
["objc", "
|
|
1504
|
-
["ocaml", "
|
|
1505
|
-
["pascal", "
|
|
1506
|
-
["perl", "
|
|
1507
|
-
["php", "
|
|
1508
|
-
["pli", "
|
|
1509
|
-
["powershell", "
|
|
1510
|
-
["proto", "
|
|
1511
|
-
["r", "
|
|
1512
|
-
["racket", "
|
|
1513
|
-
["rpg", "
|
|
1514
|
-
["salesforce_metadata", "
|
|
1515
|
-
["sas", "
|
|
1516
|
-
["scala", "
|
|
1517
|
-
["scheme", "
|
|
1518
|
-
["solidity", "
|
|
1519
|
-
["sql", "
|
|
1520
|
-
["swift", "
|
|
1521
|
-
["terraform", "
|
|
1522
|
-
["thrift", "
|
|
1523
|
-
["vb", "
|
|
1524
|
-
["vhdl", "
|
|
1525
|
-
["zig", "
|
|
1475
|
+
["abap", "4ef985e32a1f383b"],
|
|
1476
|
+
["abl", "bdd5e1f26e45ff2c"],
|
|
1477
|
+
["apache", "0b27b69726292efb"],
|
|
1478
|
+
["apex", "e32b7db5f4712f5b"],
|
|
1479
|
+
["asm", "39cb0f03768e600d"],
|
|
1480
|
+
["bash", "c3e48283ab19e193"],
|
|
1481
|
+
["batch", "851214ae15af3639"],
|
|
1482
|
+
["caddy", "bbeb0a2da1560633"],
|
|
1483
|
+
["clojure", "d0884e88ac85075a"],
|
|
1484
|
+
["cmake", "03340ace9b2aa883"],
|
|
1485
|
+
["common_lisp", "ae28e72ef28c9551"],
|
|
1486
|
+
["csharp", "a2c491f606bb57b9"],
|
|
1487
|
+
["dart", "a4dd5573b9546228"],
|
|
1488
|
+
["elixir", "4a81648264545c56"],
|
|
1489
|
+
["emacs_lisp", "316bfa0b437eeb85"],
|
|
1490
|
+
["erlang", "3bc366622ec4cc3b"],
|
|
1491
|
+
["fortran", "291bc41f505cdda6"],
|
|
1492
|
+
["fsharp", "10933683d81d8d1c"],
|
|
1493
|
+
["graphql", "1a20ee76f923313e"],
|
|
1494
|
+
["groovy", "9cb3181f3f4a11fe"],
|
|
1495
|
+
["haskell", "730181cb830a1030"],
|
|
1496
|
+
["jcl", "9a57499031ed347b"],
|
|
1497
|
+
["kotlin", "f3dfa562584b3c1e"],
|
|
1498
|
+
["liquid", "2c0c5e6ba3115c8a"],
|
|
1499
|
+
["lua", "6ce08b73a44c644e"],
|
|
1500
|
+
["makefile", "3ba22553e6f132b2"],
|
|
1501
|
+
["matlab", "f746df0ae9a5b830"],
|
|
1502
|
+
["nginx", "3c41efc524de3986"],
|
|
1503
|
+
["nix", "3fd1e8d077a7bf35"],
|
|
1504
|
+
["objc", "01f9ad87531b18b3"],
|
|
1505
|
+
["ocaml", "45102e7f975163f4"],
|
|
1506
|
+
["pascal", "294cd5e1691c743c"],
|
|
1507
|
+
["perl", "0e3da9140e016fcc"],
|
|
1508
|
+
["php", "3284d2b4728c415c"],
|
|
1509
|
+
["pli", "e231b4d9e03f468c"],
|
|
1510
|
+
["powershell", "a00cb003902e7925"],
|
|
1511
|
+
["proto", "295d025fcbb1530b"],
|
|
1512
|
+
["r", "a085d6e71e01a30c"],
|
|
1513
|
+
["racket", "67784484d09eb4b2"],
|
|
1514
|
+
["rpg", "c62e068dcdc9560f"],
|
|
1515
|
+
["salesforce_metadata", "355abf5e3004314b"],
|
|
1516
|
+
["sas", "3989a1cb67d116ab"],
|
|
1517
|
+
["scala", "4c26cbe2d384c6f3"],
|
|
1518
|
+
["scheme", "5002c53a7c5b2494"],
|
|
1519
|
+
["solidity", "73c98aebc6e118a3"],
|
|
1520
|
+
["sql", "2d4253d05fc034c0"],
|
|
1521
|
+
["swift", "37c62bf09376b09b"],
|
|
1522
|
+
["terraform", "eb990ef3cdcc442a"],
|
|
1523
|
+
["thrift", "5087a9dd0676c7b4"],
|
|
1524
|
+
["vb", "8f4399c3ff337841"],
|
|
1525
|
+
["vhdl", "940490b5125328d9"],
|
|
1526
|
+
["zig", "216a30e17966e444"]
|
|
1526
1527
|
]);
|
|
1527
1528
|
|
|
1528
1529
|
// src/parser_stamp.ts
|
|
@@ -1621,10 +1622,10 @@ init_define_import_meta_env();
|
|
|
1621
1622
|
|
|
1622
1623
|
// src/markdown_lines.ts
|
|
1623
1624
|
init_define_import_meta_env();
|
|
1624
|
-
function* eachUnfencedLine(
|
|
1625
|
+
function* eachUnfencedLine(lines) {
|
|
1625
1626
|
let fence = null;
|
|
1626
|
-
for (let i = 0; i <
|
|
1627
|
-
const line =
|
|
1627
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1628
|
+
const line = lines[i];
|
|
1628
1629
|
if (line === void 0) continue;
|
|
1629
1630
|
const fm = /^\s*(`{3,}|~{3,})([^\n]*)$/.exec(line);
|
|
1630
1631
|
if (fm !== null && fm[1] !== void 0) {
|
|
@@ -1649,8 +1650,8 @@ var MAX_HEADINGS = 40;
|
|
|
1649
1650
|
var MAX_OUTPUT_LINES = 60;
|
|
1650
1651
|
function extractMarkdownHeadings(content, limit = MAX_HEADINGS) {
|
|
1651
1652
|
const headings = [];
|
|
1652
|
-
const
|
|
1653
|
-
const unfenced = Array.from(eachUnfencedLine(
|
|
1653
|
+
const lines = content.split("\n");
|
|
1654
|
+
const unfenced = Array.from(eachUnfencedLine(lines));
|
|
1654
1655
|
for (let u = 0; u < unfenced.length; u++) {
|
|
1655
1656
|
const [i, line] = unfenced[u];
|
|
1656
1657
|
if (!line) continue;
|
|
@@ -1739,10 +1740,10 @@ function getWellKnownSections(basename2) {
|
|
|
1739
1740
|
return WELL_KNOWN_SECTIONS[basename2] ?? [];
|
|
1740
1741
|
}
|
|
1741
1742
|
function extractChangelogVersionHint(content, filePath) {
|
|
1742
|
-
const
|
|
1743
|
+
const lines = content.split("\n");
|
|
1743
1744
|
let foundUnreleased = false;
|
|
1744
1745
|
let firstVersion = null;
|
|
1745
|
-
for (const line of
|
|
1746
|
+
for (const line of lines) {
|
|
1746
1747
|
const m = /^##\s+(\[?[\d]+\.[\d]+\.[\d]+\]?)/.exec(line);
|
|
1747
1748
|
if (m) {
|
|
1748
1749
|
if (foundUnreleased) {
|
|
@@ -1779,9 +1780,6 @@ function buildEmbeddingBoundaries(filePath, content, dbPath) {
|
|
|
1779
1780
|
// src/languages/salesforce_frontend.ts
|
|
1780
1781
|
init_define_import_meta_env();
|
|
1781
1782
|
import * as path5 from "node:path";
|
|
1782
|
-
function lines(content) {
|
|
1783
|
-
return content.split("\n");
|
|
1784
|
-
}
|
|
1785
1783
|
function bundleName(filePath) {
|
|
1786
1784
|
const normalized = filePath.replaceAll("\\", "/");
|
|
1787
1785
|
const parent = path5.posix.basename(path5.posix.dirname(normalized));
|
|
@@ -1808,7 +1806,7 @@ function dedupe(values, key) {
|
|
|
1808
1806
|
});
|
|
1809
1807
|
}
|
|
1810
1808
|
function extractLwcJavaScript(content, filePath) {
|
|
1811
|
-
const
|
|
1809
|
+
const lineIndex = buildLineIndex(content);
|
|
1812
1810
|
const bundle = bundleName(filePath);
|
|
1813
1811
|
const symbols = [
|
|
1814
1812
|
symbol(filePath, bundle, "lwc_bundle", 1, countContentLines(content)),
|
|
@@ -1818,16 +1816,15 @@ function extractLwcJavaScript(content, filePath) {
|
|
|
1818
1816
|
const commentFree = stripJsComments(content);
|
|
1819
1817
|
const apiRe = /@api\s*(?:\r?\n\s*)?(?:(get|set)\s+)?(?:async\s+)?([A-Za-z_$][\w$]*)\s*(\()?/g;
|
|
1820
1818
|
for (const match of commentFree.matchAll(apiRe)) {
|
|
1821
|
-
const
|
|
1822
|
-
const line = before.split("\n").length;
|
|
1819
|
+
const line = offsetToLine(lineIndex, match.index ?? 0);
|
|
1823
1820
|
const kind = match[3] && !match[1] ? "lwc_api_method" : "lwc_api_property";
|
|
1824
1821
|
symbols.push(symbol(filePath, match[2] ?? "", kind, line));
|
|
1825
1822
|
}
|
|
1826
1823
|
const importRe = /from\s+['"]@salesforce\/(apex|schema|label|resourceUrl|messageChannel|customPermission|userPermission)\/([^'"]+)['"]/g;
|
|
1827
1824
|
for (const match of commentFree.matchAll(importRe)) {
|
|
1828
1825
|
const offset = match.index ?? 0;
|
|
1829
|
-
const line =
|
|
1830
|
-
const context =
|
|
1826
|
+
const line = offsetToLine(lineIndex, offset);
|
|
1827
|
+
const context = lineTextAt(content, lineIndex, line);
|
|
1831
1828
|
const target = match[2] ?? "";
|
|
1832
1829
|
const targetOffset = offset + (match[0]?.indexOf(target) ?? 0);
|
|
1833
1830
|
const col = targetOffset - (commentFree.lastIndexOf("\n", targetOffset) + 1);
|
|
@@ -1842,33 +1839,28 @@ function extractLwcJavaScript(content, filePath) {
|
|
|
1842
1839
|
refs: dedupe(refs, (entry) => `${entry.filePath}\0${entry.name}\0${entry.line}\0${entry.col}`)
|
|
1843
1840
|
};
|
|
1844
1841
|
}
|
|
1845
|
-
function matchLine(content, offset) {
|
|
1846
|
-
return content.slice(0, offset).split("\n").length;
|
|
1847
|
-
}
|
|
1848
|
-
function lineContext(content, line) {
|
|
1849
|
-
return lines(content)[line - 1]?.trim() ?? "";
|
|
1850
|
-
}
|
|
1851
1842
|
function extractLwcTemplate(content, filePath) {
|
|
1852
1843
|
const symbols = [];
|
|
1853
1844
|
const refs = [];
|
|
1854
1845
|
const markupNoComments = stripXmlComments(content);
|
|
1846
|
+
const lineIndex = buildLineIndex(content);
|
|
1855
1847
|
for (const match of markupNoComments.matchAll(/\blwc:ref\s*=\s*["']([^"']+)["']/gi)) {
|
|
1856
|
-
const line =
|
|
1848
|
+
const line = offsetToLine(lineIndex, match.index ?? 0);
|
|
1857
1849
|
symbols.push(symbol(filePath, match[1] ?? "", "lwc_ref", line));
|
|
1858
1850
|
}
|
|
1859
1851
|
for (const match of markupNoComments.matchAll(/\bid\s*=\s*["']([^"'{}:]+)["']/gi)) {
|
|
1860
|
-
const line =
|
|
1852
|
+
const line = offsetToLine(lineIndex, match.index ?? 0);
|
|
1861
1853
|
symbols.push(symbol(filePath, match[1] ?? "", "lwc_id", line));
|
|
1862
1854
|
}
|
|
1863
1855
|
for (const match of markupNoComments.matchAll(/\bon[a-z][\w-]*\s*=\s*\{\s*([A-Za-z_$][\w$]*)\s*\}/gi)) {
|
|
1864
1856
|
const offset = match.index ?? 0;
|
|
1865
|
-
const line =
|
|
1866
|
-
refs.push(ref(filePath, match[1] ?? "", line, 0,
|
|
1857
|
+
const line = offsetToLine(lineIndex, offset);
|
|
1858
|
+
refs.push(ref(filePath, match[1] ?? "", line, 0, lineTextAt(content, lineIndex, line)));
|
|
1867
1859
|
}
|
|
1868
1860
|
for (const match of markupNoComments.matchAll(/<\s*(c-[a-z][\w-]*)\b/gi)) {
|
|
1869
1861
|
const offset = match.index ?? 0;
|
|
1870
|
-
const line =
|
|
1871
|
-
refs.push(ref(filePath, (match[1] ?? "").toLowerCase(), line, 0,
|
|
1862
|
+
const line = offsetToLine(lineIndex, offset);
|
|
1863
|
+
refs.push(ref(filePath, (match[1] ?? "").toLowerCase(), line, 0, lineTextAt(content, lineIndex, line)));
|
|
1872
1864
|
}
|
|
1873
1865
|
return {
|
|
1874
1866
|
symbols: dedupe(symbols, (entry) => `${entry.name}\0${entry.kind}\0${entry.lineStart}`),
|
|
@@ -1893,18 +1885,18 @@ function markupArtifactName(filePath, extension) {
|
|
|
1893
1885
|
}
|
|
1894
1886
|
return bundleName(filePath);
|
|
1895
1887
|
}
|
|
1896
|
-
function addAttributeSymbols(symbols, content, filePath, tag, kind) {
|
|
1888
|
+
function addAttributeSymbols(symbols, content, lineIndex, filePath, tag, kind) {
|
|
1897
1889
|
const tagRe = new RegExp(`<\\s*${tag}\\b[^>]*\\bname\\s*=\\s*["']([^"']+)["'][^>]*>`, "gi");
|
|
1898
1890
|
for (const match of content.matchAll(tagRe)) {
|
|
1899
|
-
symbols.push(symbol(filePath, match[1] ?? "", kind,
|
|
1891
|
+
symbols.push(symbol(filePath, match[1] ?? "", kind, offsetToLine(lineIndex, match.index ?? 0)));
|
|
1900
1892
|
}
|
|
1901
1893
|
}
|
|
1902
|
-
function attributeRefs(refs, content, filePath, attribute, split = false) {
|
|
1894
|
+
function attributeRefs(refs, content, lineIndex, filePath, attribute, split = false) {
|
|
1903
1895
|
const attributeRe = new RegExp(`\\b${attribute}\\s*=\\s*["']([^"']+)["']`, "gi");
|
|
1904
1896
|
for (const match of content.matchAll(attributeRe)) {
|
|
1905
|
-
const line =
|
|
1897
|
+
const line = offsetToLine(lineIndex, match.index ?? 0);
|
|
1906
1898
|
const values = split ? (match[1] ?? "").split(",").map((value) => value.trim()).filter(Boolean) : [match[1] ?? ""];
|
|
1907
|
-
for (const value of values) refs.push(ref(filePath, value, line, 0,
|
|
1899
|
+
for (const value of values) refs.push(ref(filePath, value, line, 0, lineTextAt(content, lineIndex, line)));
|
|
1908
1900
|
}
|
|
1909
1901
|
}
|
|
1910
1902
|
function extractSalesforceMarkup(content, filePath) {
|
|
@@ -1917,22 +1909,23 @@ function extractSalesforceMarkup(content, filePath) {
|
|
|
1917
1909
|
const refs = [];
|
|
1918
1910
|
const isAura = [".cmp", ".app", ".evt", ".intf", ".design", ".auradoc", ".tokens"].includes(extension);
|
|
1919
1911
|
const markupNoComments = stripXmlComments(content);
|
|
1912
|
+
const lineIndex = buildLineIndex(content);
|
|
1920
1913
|
if (isAura) {
|
|
1921
|
-
addAttributeSymbols(symbols, markupNoComments, filePath, "aura:attribute", "aura_attribute");
|
|
1922
|
-
addAttributeSymbols(symbols, markupNoComments, filePath, "aura:handler", "aura_handler");
|
|
1923
|
-
addAttributeSymbols(symbols, markupNoComments, filePath, "aura:registerEvent", "aura_event");
|
|
1924
|
-
addAttributeSymbols(symbols, markupNoComments, filePath, "design:attribute", "aura_design_attribute");
|
|
1914
|
+
addAttributeSymbols(symbols, markupNoComments, lineIndex, filePath, "aura:attribute", "aura_attribute");
|
|
1915
|
+
addAttributeSymbols(symbols, markupNoComments, lineIndex, filePath, "aura:handler", "aura_handler");
|
|
1916
|
+
addAttributeSymbols(symbols, markupNoComments, lineIndex, filePath, "aura:registerEvent", "aura_event");
|
|
1917
|
+
addAttributeSymbols(symbols, markupNoComments, lineIndex, filePath, "design:attribute", "aura_design_attribute");
|
|
1925
1918
|
}
|
|
1926
|
-
attributeRefs(refs, markupNoComments, filePath, "controller");
|
|
1927
|
-
attributeRefs(refs, markupNoComments, filePath, "extensions", true);
|
|
1919
|
+
attributeRefs(refs, markupNoComments, lineIndex, filePath, "controller");
|
|
1920
|
+
attributeRefs(refs, markupNoComments, lineIndex, filePath, "extensions", true);
|
|
1928
1921
|
const actionRe = isAura ? /\{!\s*c\.([A-Za-z_$][\w$]*)(?:[^}\w$][^}]*)?\}/gi : /\baction\s*=\s*["']\{!\s*(?:c\.)?([A-Za-z_$][\w$]*)(?:[^}\w$][^}]*)?\}["']/gi;
|
|
1929
1922
|
for (const match of markupNoComments.matchAll(actionRe)) {
|
|
1930
|
-
const line =
|
|
1931
|
-
refs.push(ref(filePath, match[1] ?? "", line, 0,
|
|
1923
|
+
const line = offsetToLine(lineIndex, match.index ?? 0);
|
|
1924
|
+
refs.push(ref(filePath, match[1] ?? "", line, 0, lineTextAt(content, lineIndex, line)));
|
|
1932
1925
|
}
|
|
1933
1926
|
for (const match of markupNoComments.matchAll(/\bc:[A-Za-z_$][\w$]*/g)) {
|
|
1934
|
-
const line =
|
|
1935
|
-
refs.push(ref(filePath, match[0], line, 0,
|
|
1927
|
+
const line = offsetToLine(lineIndex, match.index ?? 0);
|
|
1928
|
+
refs.push(ref(filePath, match[0], line, 0, lineTextAt(content, lineIndex, line)));
|
|
1936
1929
|
}
|
|
1937
1930
|
return {
|
|
1938
1931
|
symbols: dedupe(symbols, (entry) => `${entry.name}\0${entry.kind}\0${entry.lineStart}`),
|
|
@@ -1945,10 +1938,10 @@ init_define_import_meta_env();
|
|
|
1945
1938
|
function normalizeSource(source) {
|
|
1946
1939
|
if (typeof source === "string") return source;
|
|
1947
1940
|
if (!Array.isArray(source)) return "";
|
|
1948
|
-
const
|
|
1949
|
-
if (
|
|
1950
|
-
const noneEndWithNewline =
|
|
1951
|
-
return noneEndWithNewline ?
|
|
1941
|
+
const lines = source.filter((s) => typeof s === "string");
|
|
1942
|
+
if (lines.length === 0) return "";
|
|
1943
|
+
const noneEndWithNewline = lines.every((l) => !l.endsWith("\n"));
|
|
1944
|
+
return noneEndWithNewline ? lines.join("\n") : lines.join("");
|
|
1952
1945
|
}
|
|
1953
1946
|
function resolveKernelLanguage(metadata) {
|
|
1954
1947
|
const kernelspecLang = metadata?.kernelspec?.language;
|
|
@@ -2078,7 +2071,7 @@ function widenToDeclaration(node) {
|
|
|
2078
2071
|
widened = parent;
|
|
2079
2072
|
}
|
|
2080
2073
|
}
|
|
2081
|
-
function makeSymbol(filePath, name, kind, node,
|
|
2074
|
+
function makeSymbol(filePath, name, kind, node, lines, style) {
|
|
2082
2075
|
const ranged = widenToDeclaration(node);
|
|
2083
2076
|
const lineStart = ranged.startPosition.row + 1;
|
|
2084
2077
|
return {
|
|
@@ -2088,7 +2081,7 @@ function makeSymbol(filePath, name, kind, node, lines2, style) {
|
|
|
2088
2081
|
lineStart,
|
|
2089
2082
|
lineEnd: ranged.endPosition.row + 1,
|
|
2090
2083
|
body: ranged.text,
|
|
2091
|
-
docstring:
|
|
2084
|
+
docstring: lines !== void 0 && style !== void 0 ? precedingDocComment(lines, lineStart, style) : "",
|
|
2092
2085
|
parent: ""
|
|
2093
2086
|
};
|
|
2094
2087
|
}
|
|
@@ -2160,7 +2153,7 @@ function isModuleWrapperCallback(node) {
|
|
|
2160
2153
|
}
|
|
2161
2154
|
return false;
|
|
2162
2155
|
}
|
|
2163
|
-
function extractTsJsSymbols(root, filePath,
|
|
2156
|
+
function extractTsJsSymbols(root, filePath, lines) {
|
|
2164
2157
|
const out = [];
|
|
2165
2158
|
const visit = (node, insideFunction) => {
|
|
2166
2159
|
const kind = TSJS_KIND_BY_TYPE.get(node.type);
|
|
@@ -2171,7 +2164,7 @@ function extractTsJsSymbols(root, filePath, lines2) {
|
|
|
2171
2164
|
if (name !== null && name !== "") {
|
|
2172
2165
|
const decorators = leadingTsDecorators(node);
|
|
2173
2166
|
if (decorators.length === 0) {
|
|
2174
|
-
out.push(makeSymbol(filePath, name, kind, node,
|
|
2167
|
+
out.push(makeSymbol(filePath, name, kind, node, lines, "c"));
|
|
2175
2168
|
} else {
|
|
2176
2169
|
const lineStart = decorators[0].startPosition.row + 1;
|
|
2177
2170
|
const decoratedEnd = widenToDeclaration(node).endPosition.row + 1;
|
|
@@ -2190,8 +2183,8 @@ function extractTsJsSymbols(root, filePath, lines2) {
|
|
|
2190
2183
|
// tree-sitter node never carries the indentation of its own first line,
|
|
2191
2184
|
// because it starts at the first real character. Reading the span off the
|
|
2192
2185
|
// file would otherwise make decorated symbols the one shape that does.
|
|
2193
|
-
body:
|
|
2194
|
-
docstring: precedingDocComment(
|
|
2186
|
+
body: lines.slice(lineStart - 1, decoratedEnd).join("\n").replace(/^[ \t]+/, ""),
|
|
2187
|
+
docstring: precedingDocComment(lines, lineStart, "c"),
|
|
2195
2188
|
parent: ""
|
|
2196
2189
|
});
|
|
2197
2190
|
}
|
|
@@ -2205,12 +2198,12 @@ function extractTsJsSymbols(root, filePath, lines2) {
|
|
|
2205
2198
|
if (name === null) continue;
|
|
2206
2199
|
if (name.type === "identifier") {
|
|
2207
2200
|
const isFn = value !== null && (value.type === "arrow_function" || value.type === "function_expression" || value.type === "function");
|
|
2208
|
-
out.push(makeSymbol(filePath, name.text, isFn ? "function" : "variable", child,
|
|
2201
|
+
out.push(makeSymbol(filePath, name.text, isFn ? "function" : "variable", child, lines, "c"));
|
|
2209
2202
|
} else {
|
|
2210
2203
|
const bindings = collectPatternBindings(name);
|
|
2211
2204
|
const elideBodies = fanOutElidesBodies(bindings.length, child.text.length);
|
|
2212
2205
|
for (const bound of bindings) {
|
|
2213
|
-
const sym = makeSymbol(filePath, bound, "variable", child,
|
|
2206
|
+
const sym = makeSymbol(filePath, bound, "variable", child, lines, "c");
|
|
2214
2207
|
out.push(elideBodies ? { ...sym, body: "" } : sym);
|
|
2215
2208
|
}
|
|
2216
2209
|
}
|
|
@@ -2220,7 +2213,7 @@ function extractTsJsSymbols(root, filePath, lines2) {
|
|
|
2220
2213
|
const fieldName = node.childForFieldName("name") ?? node.childForFieldName("property");
|
|
2221
2214
|
const value = node.childForFieldName("value");
|
|
2222
2215
|
if (fieldName !== null && value !== null && (value.type === "arrow_function" || value.type === "function_expression" || value.type === "function")) {
|
|
2223
|
-
out.push(makeSymbol(filePath, fieldName.text, "method", node,
|
|
2216
|
+
out.push(makeSymbol(filePath, fieldName.text, "method", node, lines, "c"));
|
|
2224
2217
|
}
|
|
2225
2218
|
}
|
|
2226
2219
|
if (node.type === "pair" && node.parent?.type === "object") {
|
|
@@ -2232,9 +2225,9 @@ function extractTsJsSymbols(root, filePath, lines2) {
|
|
|
2232
2225
|
const isFn = value.type === "arrow_function" || value.type === "function_expression" || value.type === "function";
|
|
2233
2226
|
const isObjectOrArray = value.type === "object" || value.type === "array";
|
|
2234
2227
|
if (isFn) {
|
|
2235
|
-
out.push(makeSymbol(filePath, keyName, "method", node,
|
|
2228
|
+
out.push(makeSymbol(filePath, keyName, "method", node, lines, "c"));
|
|
2236
2229
|
} else if (isObjectOrArray && node.endPosition.row - node.startPosition.row >= 1) {
|
|
2237
|
-
out.push(makeSymbol(filePath, keyName, "config", node,
|
|
2230
|
+
out.push(makeSymbol(filePath, keyName, "config", node, lines, "c"));
|
|
2238
2231
|
}
|
|
2239
2232
|
}
|
|
2240
2233
|
}
|
|
@@ -2345,7 +2338,7 @@ var GO_LOCAL_KINDS = /* @__PURE__ */ new Set([
|
|
|
2345
2338
|
"method_elem"
|
|
2346
2339
|
]);
|
|
2347
2340
|
var GO_MULTI_NAME_SPECS = /* @__PURE__ */ new Set(["var_spec", "const_spec"]);
|
|
2348
|
-
function extractGoSymbols(root, filePath,
|
|
2341
|
+
function extractGoSymbols(root, filePath, lines) {
|
|
2349
2342
|
const out = [];
|
|
2350
2343
|
const visit = (node, insideFunction) => {
|
|
2351
2344
|
const kind = GO_KIND_BY_TYPE.get(node.type);
|
|
@@ -2356,13 +2349,13 @@ function extractGoSymbols(root, filePath, lines2) {
|
|
|
2356
2349
|
);
|
|
2357
2350
|
const elideBodies = fanOutElidesBodies(declared.length, node.text.length);
|
|
2358
2351
|
for (const child of declared) {
|
|
2359
|
-
const sym = makeSymbol(filePath, child.text, kind, node,
|
|
2352
|
+
const sym = makeSymbol(filePath, child.text, kind, node, lines, "c");
|
|
2360
2353
|
out.push(elideBodies ? { ...sym, body: "" } : sym);
|
|
2361
2354
|
}
|
|
2362
2355
|
} else {
|
|
2363
2356
|
const name = nodeName(node);
|
|
2364
2357
|
if (name !== null && name !== "") {
|
|
2365
|
-
out.push(makeSymbol(filePath, name, kind, node,
|
|
2358
|
+
out.push(makeSymbol(filePath, name, kind, node, lines, "c"));
|
|
2366
2359
|
}
|
|
2367
2360
|
}
|
|
2368
2361
|
}
|
|
@@ -2453,7 +2446,7 @@ function leadingRustAttributes(node) {
|
|
|
2453
2446
|
}
|
|
2454
2447
|
return attrs;
|
|
2455
2448
|
}
|
|
2456
|
-
function extractRustSymbols(root, filePath,
|
|
2449
|
+
function extractRustSymbols(root, filePath, lines) {
|
|
2457
2450
|
const out = [];
|
|
2458
2451
|
const visit = (node, insideFunction) => {
|
|
2459
2452
|
const kind = RUST_KIND_BY_TYPE.get(node.type);
|
|
@@ -2462,7 +2455,7 @@ function extractRustSymbols(root, filePath, lines2) {
|
|
|
2462
2455
|
if (name !== null && name !== "") {
|
|
2463
2456
|
const attrs = leadingRustAttributes(node);
|
|
2464
2457
|
if (attrs.length === 0) {
|
|
2465
|
-
out.push(makeSymbol(filePath, name, kind, node,
|
|
2458
|
+
out.push(makeSymbol(filePath, name, kind, node, lines, "c"));
|
|
2466
2459
|
} else {
|
|
2467
2460
|
const lineStart = attrs[0].startPosition.row + 1;
|
|
2468
2461
|
out.push({
|
|
@@ -2472,7 +2465,7 @@ function extractRustSymbols(root, filePath, lines2) {
|
|
|
2472
2465
|
lineStart,
|
|
2473
2466
|
lineEnd: node.endPosition.row + 1,
|
|
2474
2467
|
body: [...attrs, node].map((n) => n.text).join("\n"),
|
|
2475
|
-
docstring: precedingDocComment(
|
|
2468
|
+
docstring: precedingDocComment(lines, lineStart, "c"),
|
|
2476
2469
|
parent: ""
|
|
2477
2470
|
});
|
|
2478
2471
|
}
|
|
@@ -2492,14 +2485,14 @@ var RUBY_KIND_BY_TYPE = /* @__PURE__ */ new Map([
|
|
|
2492
2485
|
["class", "class"],
|
|
2493
2486
|
["module", "module"]
|
|
2494
2487
|
]);
|
|
2495
|
-
function extractSimpleSymbols(root, filePath, kindByType,
|
|
2488
|
+
function extractSimpleSymbols(root, filePath, kindByType, lines, style, nameFor = nodeName) {
|
|
2496
2489
|
const out = [];
|
|
2497
2490
|
const visit = (node) => {
|
|
2498
2491
|
const kind = kindByType.get(node.type);
|
|
2499
2492
|
if (kind !== void 0) {
|
|
2500
2493
|
const name = nameFor(node);
|
|
2501
2494
|
if (name !== null && name !== "") {
|
|
2502
|
-
out.push(makeSymbol(filePath, name, kind, node,
|
|
2495
|
+
out.push(makeSymbol(filePath, name, kind, node, lines, style));
|
|
2503
2496
|
}
|
|
2504
2497
|
}
|
|
2505
2498
|
for (const child of node.namedChildren) {
|
|
@@ -2509,8 +2502,8 @@ function extractSimpleSymbols(root, filePath, kindByType, lines2, style, nameFor
|
|
|
2509
2502
|
visit(root);
|
|
2510
2503
|
return out;
|
|
2511
2504
|
}
|
|
2512
|
-
function extractRubySymbols(root, filePath,
|
|
2513
|
-
return extractSimpleSymbols(root, filePath, RUBY_KIND_BY_TYPE,
|
|
2505
|
+
function extractRubySymbols(root, filePath, lines) {
|
|
2506
|
+
return extractSimpleSymbols(root, filePath, RUBY_KIND_BY_TYPE, lines, "hash");
|
|
2514
2507
|
}
|
|
2515
2508
|
var JAVA_KIND_BY_TYPE = /* @__PURE__ */ new Map([
|
|
2516
2509
|
["method_declaration", "method"],
|
|
@@ -2531,8 +2524,8 @@ var JAVA_KIND_BY_TYPE = /* @__PURE__ */ new Map([
|
|
|
2531
2524
|
// the same kind as their bodied counterparts.
|
|
2532
2525
|
["annotation_type_element_declaration", "method"]
|
|
2533
2526
|
]);
|
|
2534
|
-
function extractJavaSymbols(root, filePath,
|
|
2535
|
-
return extractSimpleSymbols(root, filePath, JAVA_KIND_BY_TYPE,
|
|
2527
|
+
function extractJavaSymbols(root, filePath, lines) {
|
|
2528
|
+
return extractSimpleSymbols(root, filePath, JAVA_KIND_BY_TYPE, lines, "c");
|
|
2536
2529
|
}
|
|
2537
2530
|
var CPP_KIND_BY_TYPE = /* @__PURE__ */ new Map([
|
|
2538
2531
|
["function_definition", "function"],
|
|
@@ -2582,12 +2575,12 @@ var CPP_KIND_BY_TYPE = /* @__PURE__ */ new Map([
|
|
|
2582
2575
|
// tag is skipped) for anything that isn't a genuine function prototype.
|
|
2583
2576
|
["declaration", "function"]
|
|
2584
2577
|
]);
|
|
2585
|
-
function extractCppSymbols(root, filePath,
|
|
2578
|
+
function extractCppSymbols(root, filePath, lines) {
|
|
2586
2579
|
return extractSimpleSymbols(
|
|
2587
2580
|
root,
|
|
2588
2581
|
filePath,
|
|
2589
2582
|
CPP_KIND_BY_TYPE,
|
|
2590
|
-
|
|
2583
|
+
lines,
|
|
2591
2584
|
"c",
|
|
2592
2585
|
(node) => node.type === "function_definition" ? cFunctionName(node) : node.type === "type_definition" ? cTypedefAliasName(node) : node.type === "declaration" ? cFunctionPrototypeName(node) : nodeName(node)
|
|
2593
2586
|
);
|
|
@@ -3197,8 +3190,8 @@ function countNewlines(s) {
|
|
|
3197
3190
|
}
|
|
3198
3191
|
function extractMarkdownSymbols(content, filePath) {
|
|
3199
3192
|
const out = [];
|
|
3200
|
-
const
|
|
3201
|
-
const unfenced = Array.from(eachUnfencedLine(
|
|
3193
|
+
const lines = content.split(/\r?\n/);
|
|
3194
|
+
const unfenced = Array.from(eachUnfencedLine(lines));
|
|
3202
3195
|
for (let u = 0; u < unfenced.length; u++) {
|
|
3203
3196
|
const [i, line] = unfenced[u];
|
|
3204
3197
|
const atxMatch = /^(#{1,6})\s+(.+?)(?:\s+#+\s*)?$/.exec(line);
|
|
@@ -3406,10 +3399,10 @@ function yamlLineClosesQuote(line, quote) {
|
|
|
3406
3399
|
}
|
|
3407
3400
|
function extractYamlSymbols(content, filePath) {
|
|
3408
3401
|
const out = [];
|
|
3409
|
-
const
|
|
3402
|
+
const lines = content.split(/\r?\n/);
|
|
3410
3403
|
let openQuote = null;
|
|
3411
|
-
for (let i = 0; i <
|
|
3412
|
-
const line =
|
|
3404
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3405
|
+
const line = lines[i];
|
|
3413
3406
|
if (line === void 0) continue;
|
|
3414
3407
|
if (openQuote !== null) {
|
|
3415
3408
|
if (yamlLineClosesQuote(line, openQuote)) openQuote = null;
|
|
@@ -3488,8 +3481,8 @@ var TOML_SIMPLE_KEY = `(?:[A-Za-z0-9_-]+|"(?:[^"\\\\]|\\\\.)*"|'[^']*')`;
|
|
|
3488
3481
|
var TOML_KEY_RE = new RegExp(`^\\s*(${TOML_SIMPLE_KEY}(?:\\s*\\.\\s*${TOML_SIMPLE_KEY})*)\\s*=`);
|
|
3489
3482
|
function extractTomlSymbols(content, filePath) {
|
|
3490
3483
|
const out = [];
|
|
3491
|
-
const
|
|
3492
|
-
function
|
|
3484
|
+
const lines = content.split(/\r?\n/);
|
|
3485
|
+
function matchLine(line, lineNum) {
|
|
3493
3486
|
const sectionMatch = /^\s*\[\[?\s*([^\]]+)\s*\]/.exec(line);
|
|
3494
3487
|
if (sectionMatch !== null && sectionMatch[1] !== void 0) {
|
|
3495
3488
|
out.push({
|
|
@@ -3519,14 +3512,14 @@ function extractTomlSymbols(content, filePath) {
|
|
|
3519
3512
|
}
|
|
3520
3513
|
let openDelim = null;
|
|
3521
3514
|
let arrayDepth = 0;
|
|
3522
|
-
for (let i = 0; i <
|
|
3523
|
-
const line =
|
|
3515
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3516
|
+
const line = lines[i];
|
|
3524
3517
|
if (line === void 0) continue;
|
|
3525
3518
|
if (openDelim !== null) {
|
|
3526
3519
|
const closeIdx = line.indexOf(openDelim);
|
|
3527
3520
|
if (closeIdx === -1) continue;
|
|
3528
3521
|
const restStart = closeIdx + openDelim.length;
|
|
3529
|
-
|
|
3522
|
+
matchLine(line.slice(restStart), i);
|
|
3530
3523
|
openDelim = lineOpenDelimiterAfter(stripTomlComment(line.slice(restStart)), 0);
|
|
3531
3524
|
continue;
|
|
3532
3525
|
}
|
|
@@ -3534,7 +3527,7 @@ function extractTomlSymbols(content, filePath) {
|
|
|
3534
3527
|
arrayDepth = Math.max(0, arrayDepth + tomlBracketDelta(stripTomlComment(line)));
|
|
3535
3528
|
continue;
|
|
3536
3529
|
}
|
|
3537
|
-
|
|
3530
|
+
matchLine(line, i);
|
|
3538
3531
|
const code = stripTomlComment(line);
|
|
3539
3532
|
openDelim = lineOpenDelimiterAfter(code, 0);
|
|
3540
3533
|
if (openDelim === null) arrayDepth = Math.max(0, tomlBracketDelta(code));
|
|
@@ -3557,9 +3550,9 @@ function splitTopLevelSelectors(rawCapture, strippedCapture) {
|
|
|
3557
3550
|
parts.push(rawCapture.slice(start));
|
|
3558
3551
|
return parts;
|
|
3559
3552
|
}
|
|
3560
|
-
function nextContentLineOpensBrace(
|
|
3561
|
-
for (let j = i + 1; j <
|
|
3562
|
-
const next =
|
|
3553
|
+
function nextContentLineOpensBrace(lines, i) {
|
|
3554
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
3555
|
+
const next = lines[j]?.trim() ?? "";
|
|
3563
3556
|
if (next.length === 0) continue;
|
|
3564
3557
|
return next === "{";
|
|
3565
3558
|
}
|
|
@@ -3567,11 +3560,11 @@ function nextContentLineOpensBrace(lines2, i) {
|
|
|
3567
3560
|
}
|
|
3568
3561
|
function extractCssSymbols(content, filePath) {
|
|
3569
3562
|
const out = [];
|
|
3570
|
-
const
|
|
3563
|
+
const lines = stripCstyleComments(content).split(/\r?\n/);
|
|
3571
3564
|
const rawLines = content.split(/\r?\n/);
|
|
3572
3565
|
let pending = [];
|
|
3573
|
-
for (let i = 0; i <
|
|
3574
|
-
const line =
|
|
3566
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3567
|
+
const line = lines[i];
|
|
3575
3568
|
if (line === void 0) continue;
|
|
3576
3569
|
const trimmed = line.trim();
|
|
3577
3570
|
if (trimmed.length === 0 && (rawLines[i]?.trim().length ?? 0) > 0) {
|
|
@@ -3631,7 +3624,7 @@ function extractCssSymbols(content, filePath) {
|
|
|
3631
3624
|
}
|
|
3632
3625
|
if (trimmed.length > 0 && !trimmed.startsWith("@") && !trimmed.includes("{") && !trimmed.includes("}") && !trimmed.includes(";")) {
|
|
3633
3626
|
const endsWithComma = trimmed.endsWith(",");
|
|
3634
|
-
if (endsWithComma || pending.length > 0 || nextContentLineOpensBrace(
|
|
3627
|
+
if (endsWithComma || pending.length > 0 || nextContentLineOpensBrace(lines, i)) {
|
|
3635
3628
|
const name = endsWithComma ? trimmed.slice(0, -1).trim() : trimmed;
|
|
3636
3629
|
if (name) pending.push({ name, line: i + 1, body: trimmed });
|
|
3637
3630
|
continue;
|
|
@@ -3643,10 +3636,10 @@ function extractCssSymbols(content, filePath) {
|
|
|
3643
3636
|
}
|
|
3644
3637
|
function extractDockerfileSymbols(content, filePath) {
|
|
3645
3638
|
const out = [];
|
|
3646
|
-
const
|
|
3639
|
+
const lines = content.split(/\r?\n/);
|
|
3647
3640
|
let continuing = false;
|
|
3648
|
-
for (let i = 0; i <
|
|
3649
|
-
const line =
|
|
3641
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3642
|
+
const line = lines[i];
|
|
3650
3643
|
if (line === void 0) continue;
|
|
3651
3644
|
if (continuing) {
|
|
3652
3645
|
continuing = line.trimEnd().endsWith("\\");
|
|
@@ -3705,9 +3698,9 @@ var FALLBACK_PATTERNS = [
|
|
|
3705
3698
|
];
|
|
3706
3699
|
function extractWithRegex(content, filePath) {
|
|
3707
3700
|
const out = [];
|
|
3708
|
-
const
|
|
3709
|
-
for (let i = 0; i <
|
|
3710
|
-
const line =
|
|
3701
|
+
const lines = content.split(/\r?\n/);
|
|
3702
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3703
|
+
const line = lines[i];
|
|
3711
3704
|
if (line === void 0) continue;
|
|
3712
3705
|
for (const { re, kind, style } of FALLBACK_PATTERNS) {
|
|
3713
3706
|
const m = re.exec(line);
|
|
@@ -3719,7 +3712,7 @@ function extractWithRegex(content, filePath) {
|
|
|
3719
3712
|
lineStart: i + 1,
|
|
3720
3713
|
lineEnd: i + 1,
|
|
3721
3714
|
body: line.trim(),
|
|
3722
|
-
docstring: precedingDocComment(
|
|
3715
|
+
docstring: precedingDocComment(lines, i + 1, style),
|
|
3723
3716
|
parent: ""
|
|
3724
3717
|
});
|
|
3725
3718
|
break;
|
|
@@ -3779,6 +3772,18 @@ function boundSymbolDocstring(docstring) {
|
|
|
3779
3772
|
if (cutsSurrogatePair) end -= 1;
|
|
3780
3773
|
return docstring.slice(0, Math.max(0, end)) + DOCSTRING_TRUNCATION_MARKER;
|
|
3781
3774
|
}
|
|
3775
|
+
var MAX_REF_CONTEXT_CHARS = 2048;
|
|
3776
|
+
var REF_CONTEXT_ELISION = " [\u2026] ";
|
|
3777
|
+
function boundRefContext(context, col) {
|
|
3778
|
+
if (context.length <= MAX_REF_CONTEXT_CHARS) return context;
|
|
3779
|
+
const budget = MAX_REF_CONTEXT_CHARS - REF_CONTEXT_ELISION.length * 2;
|
|
3780
|
+
const centre = Math.min(Math.max(col, 0), context.length);
|
|
3781
|
+
let start = Math.max(0, Math.min(centre - Math.floor(budget / 2), context.length - budget));
|
|
3782
|
+
let end = start + budget;
|
|
3783
|
+
if (start > 0 && context.charCodeAt(start) >= 56320 && context.charCodeAt(start) <= 57343) start += 1;
|
|
3784
|
+
if (end < context.length && context.charCodeAt(end - 1) >= 55296 && context.charCodeAt(end - 1) <= 56319) end -= 1;
|
|
3785
|
+
return (start > 0 ? REF_CONTEXT_ELISION : "") + context.slice(start, end) + (end < context.length ? REF_CONTEXT_ELISION : "");
|
|
3786
|
+
}
|
|
3782
3787
|
function loadGrammar(lang, filePath, content) {
|
|
3783
3788
|
const useTsx = lang === "typescript" && filePath !== void 0 && path6.extname(filePath).toLowerCase() === ".tsx";
|
|
3784
3789
|
const useCppHeader = lang === "c" && filePath !== void 0 && path6.extname(filePath).toLowerCase() === ".h" && content !== void 0 && CPP_HEADER_SNIFF_RE.test(content);
|
|
@@ -3917,7 +3922,7 @@ function parseSourceSymbolsTreeSitterOnly(content, filePath, language) {
|
|
|
3917
3922
|
var REGEX_ADAPTERS_SLOT = /* @__PURE__ */ Symbol.for("token-goat.regex-adapters");
|
|
3918
3923
|
var adapterSlot = globalThis;
|
|
3919
3924
|
async function loadRegexExtractors() {
|
|
3920
|
-
adapterSlot[REGEX_ADAPTERS_SLOT] ??= await import("./token-goat-chunk-
|
|
3925
|
+
adapterSlot[REGEX_ADAPTERS_SLOT] ??= await import("./token-goat-chunk-VRS6B7UD.mjs");
|
|
3921
3926
|
}
|
|
3922
3927
|
function regexAdapters() {
|
|
3923
3928
|
const loaded = adapterSlot[REGEX_ADAPTERS_SLOT];
|
|
@@ -4032,7 +4037,7 @@ function writeParseResult(filePath, content, result, dbPath) {
|
|
|
4032
4037
|
);
|
|
4033
4038
|
for (const r of result.refs) {
|
|
4034
4039
|
if (r.name === "" || COMPILER_ARTIFACT_REF_NAMES.has(r.name)) continue;
|
|
4035
|
-
insRef.run(r.filePath, r.name, r.line, r.col, r.context);
|
|
4040
|
+
insRef.run(r.filePath, r.name, r.line, r.col, boundRefContext(r.context, r.col));
|
|
4036
4041
|
}
|
|
4037
4042
|
});
|
|
4038
4043
|
writeAll.immediate();
|
|
@@ -4293,9 +4298,9 @@ var TABLE_HEADER_RE = /^\s*\[+\s*([^\]]+?)\s*\]+\s*(?:[#;].*)?$/;
|
|
|
4293
4298
|
var PYTHON_HEADER_RE = /^(\s*)(?:async\s+)?(?:def|class)\s+([A-Za-z_]\w*)/;
|
|
4294
4299
|
var KEYVALUE_HEADER_RE = /^([A-Za-z_][\w.-]*)\s*(?:=|:(?!\/\/))/;
|
|
4295
4300
|
var ENV_KEYVALUE_HEADER_RE = /^(?:export\s+)?([A-Za-z_][\w.-]*)\s*(?:=|:(?!\/\/))/;
|
|
4296
|
-
function findMarkdownHeaders(
|
|
4301
|
+
function findMarkdownHeaders(lines) {
|
|
4297
4302
|
const headers = [];
|
|
4298
|
-
const unfenced = Array.from(eachUnfencedLine(
|
|
4303
|
+
const unfenced = Array.from(eachUnfencedLine(lines));
|
|
4299
4304
|
for (let u = 0; u < unfenced.length; u++) {
|
|
4300
4305
|
const [i, line] = unfenced[u];
|
|
4301
4306
|
const m = MARKDOWN_HEADER_RE.exec(line);
|
|
@@ -4323,12 +4328,12 @@ function findMarkdownHeaders(lines2) {
|
|
|
4323
4328
|
}
|
|
4324
4329
|
return headers;
|
|
4325
4330
|
}
|
|
4326
|
-
function findTableHeaders(
|
|
4331
|
+
function findTableHeaders(lines, isToml) {
|
|
4327
4332
|
const headers = [];
|
|
4328
4333
|
let openDelim = null;
|
|
4329
4334
|
let arrayDepth = 0;
|
|
4330
|
-
for (let i = 0; i <
|
|
4331
|
-
const line =
|
|
4335
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4336
|
+
const line = lines[i];
|
|
4332
4337
|
if (line === void 0) continue;
|
|
4333
4338
|
if (openDelim !== null) {
|
|
4334
4339
|
const closeIdx = line.indexOf(openDelim);
|
|
@@ -4389,10 +4394,10 @@ function extractShellBannerHeading(line) {
|
|
|
4389
4394
|
}
|
|
4390
4395
|
return null;
|
|
4391
4396
|
}
|
|
4392
|
-
function findShellBannerHeaders(
|
|
4397
|
+
function findShellBannerHeaders(lines) {
|
|
4393
4398
|
const headers = [];
|
|
4394
|
-
for (let i = 0; i <
|
|
4395
|
-
const line =
|
|
4399
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4400
|
+
const line = lines[i] ?? "";
|
|
4396
4401
|
const banner = extractShellBannerHeading(line);
|
|
4397
4402
|
if (banner !== null) {
|
|
4398
4403
|
headers.push({ heading: banner.heading, level: banner.level, index: i });
|
|
@@ -4400,11 +4405,11 @@ function findShellBannerHeaders(lines2) {
|
|
|
4400
4405
|
}
|
|
4401
4406
|
return headers;
|
|
4402
4407
|
}
|
|
4403
|
-
function findVbRegionHeaders(
|
|
4408
|
+
function findVbRegionHeaders(lines) {
|
|
4404
4409
|
const headers = [];
|
|
4405
4410
|
const open = [];
|
|
4406
|
-
for (let i = 0; i <
|
|
4407
|
-
const line =
|
|
4411
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4412
|
+
const line = lines[i] ?? "";
|
|
4408
4413
|
const m = VB_REGION_RE.exec(line);
|
|
4409
4414
|
if (m !== null) {
|
|
4410
4415
|
open.push(headers.length);
|
|
@@ -4424,12 +4429,12 @@ function headerEndIndex(headers, kind, headerPos, totalLines) {
|
|
|
4424
4429
|
if (explicit !== void 0) return explicit;
|
|
4425
4430
|
return kind === "table-toml" ? tableSectionEndIndex(headers, headerPos, totalLines) : sectionEndIndex(headers, headerPos, totalLines);
|
|
4426
4431
|
}
|
|
4427
|
-
function findPythonHeaders(
|
|
4432
|
+
function findPythonHeaders(lines) {
|
|
4428
4433
|
const headers = [];
|
|
4429
4434
|
const indentStack = [];
|
|
4430
4435
|
let openDelim = null;
|
|
4431
|
-
for (let i = 0; i <
|
|
4432
|
-
const line =
|
|
4436
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4437
|
+
const line = lines[i];
|
|
4433
4438
|
if (line === void 0) continue;
|
|
4434
4439
|
if (openDelim !== null) {
|
|
4435
4440
|
const closeIdx = line.indexOf(openDelim);
|
|
@@ -4453,12 +4458,12 @@ function findPythonHeaders(lines2) {
|
|
|
4453
4458
|
}
|
|
4454
4459
|
return headers;
|
|
4455
4460
|
}
|
|
4456
|
-
function findKeyValueHeaders(
|
|
4461
|
+
function findKeyValueHeaders(lines, language) {
|
|
4457
4462
|
const headers = [];
|
|
4458
4463
|
const isEnv = language === "env_file";
|
|
4459
4464
|
let openQuote = null;
|
|
4460
|
-
for (let i = 0; i <
|
|
4461
|
-
const line =
|
|
4465
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4466
|
+
const line = lines[i];
|
|
4462
4467
|
if (line === void 0) continue;
|
|
4463
4468
|
if (openQuote !== null) {
|
|
4464
4469
|
const closed = isEnv ? _lineClosesQuote(line, openQuote) : yamlLineClosesQuote(line, openQuote);
|
|
@@ -4484,24 +4489,24 @@ function findHtmlHeaders(text) {
|
|
|
4484
4489
|
return headers;
|
|
4485
4490
|
}
|
|
4486
4491
|
function findHeaders(text, language) {
|
|
4487
|
-
const
|
|
4488
|
-
if (language === "markdown") return { headers: findMarkdownHeaders(
|
|
4492
|
+
const lines = text.split("\n");
|
|
4493
|
+
if (language === "markdown") return { headers: findMarkdownHeaders(lines), kind: "markdown" };
|
|
4489
4494
|
if (language === "html" || language === "liquid") return { headers: findHtmlHeaders(text), kind: "markdown" };
|
|
4490
|
-
if (language === "toml") return { headers: findTableHeaders(
|
|
4491
|
-
if (language === "python") return { headers: findPythonHeaders(
|
|
4495
|
+
if (language === "toml") return { headers: findTableHeaders(lines, true), kind: "table-toml" };
|
|
4496
|
+
if (language === "python") return { headers: findPythonHeaders(lines), kind: "python" };
|
|
4492
4497
|
if (language === "bash") {
|
|
4493
|
-
const banners = findShellBannerHeaders(
|
|
4498
|
+
const banners = findShellBannerHeaders(lines);
|
|
4494
4499
|
if (banners.length > 0) return { headers: banners, kind: "banner" };
|
|
4495
4500
|
}
|
|
4496
|
-
if (language === "vb") return { headers: findVbRegionHeaders(
|
|
4497
|
-
if (language === "ini") return { headers: findTableHeaders(
|
|
4501
|
+
if (language === "vb") return { headers: findVbRegionHeaders(lines), kind: "region" };
|
|
4502
|
+
if (language === "ini") return { headers: findTableHeaders(lines, false), kind: "table-flat" };
|
|
4498
4503
|
if (language === "yaml" || language === "env_file")
|
|
4499
|
-
return { headers: findKeyValueHeaders(
|
|
4500
|
-
const md = findMarkdownHeaders(
|
|
4504
|
+
return { headers: findKeyValueHeaders(lines, language), kind: "keyvalue" };
|
|
4505
|
+
const md = findMarkdownHeaders(lines);
|
|
4501
4506
|
if (md.length > 0) return { headers: md, kind: "markdown" };
|
|
4502
|
-
const tbl = findTableHeaders(
|
|
4507
|
+
const tbl = findTableHeaders(lines, false);
|
|
4503
4508
|
if (tbl.length > 0) return { headers: tbl, kind: "table-toml" };
|
|
4504
|
-
return { headers: findKeyValueHeaders(
|
|
4509
|
+
return { headers: findKeyValueHeaders(lines, language), kind: "keyvalue" };
|
|
4505
4510
|
}
|
|
4506
4511
|
function sectionEndIndex(headers, headerPos, totalLines) {
|
|
4507
4512
|
const current = headers[headerPos];
|
|
@@ -4687,15 +4692,15 @@ function resolveHeaderPos(headers, base, ordinal, allowFuzzy = true) {
|
|
|
4687
4692
|
}
|
|
4688
4693
|
return null;
|
|
4689
4694
|
}
|
|
4690
|
-
function buildSectionResult(headers, kind,
|
|
4695
|
+
function buildSectionResult(headers, kind, lines, headerPos, redirectedFrom) {
|
|
4691
4696
|
const header = headers[headerPos];
|
|
4692
4697
|
if (header === void 0) return null;
|
|
4693
|
-
const endIndex = headerEndIndex(headers, kind, headerPos,
|
|
4698
|
+
const endIndex = headerEndIndex(headers, kind, headerPos, lines.length);
|
|
4694
4699
|
let endExclusive = endIndex;
|
|
4695
|
-
while (endExclusive > header.index + 1 && (
|
|
4700
|
+
while (endExclusive > header.index + 1 && (lines[endExclusive - 1] === "" || lines[endExclusive - 1] === "\r")) {
|
|
4696
4701
|
endExclusive--;
|
|
4697
4702
|
}
|
|
4698
|
-
const content =
|
|
4703
|
+
const content = lines.slice(header.index, endExclusive).join("\n");
|
|
4699
4704
|
const result = {
|
|
4700
4705
|
heading: header.heading,
|
|
4701
4706
|
content,
|
|
@@ -4708,10 +4713,10 @@ function resolveSectionFromText(text, headingSpec, language, allowFuzzy = true)
|
|
|
4708
4713
|
const { headers, kind } = findHeaders(text, language);
|
|
4709
4714
|
const { base, ordinal } = parseHeadingSpec(headingSpec, headers);
|
|
4710
4715
|
if (base.length === 0) return null;
|
|
4711
|
-
const
|
|
4716
|
+
const lines = text.split("\n");
|
|
4712
4717
|
const resolved = resolveHeaderPos(headers, base, ordinal, allowFuzzy);
|
|
4713
4718
|
if (resolved === null) return null;
|
|
4714
|
-
const built = buildSectionResult(headers, kind,
|
|
4719
|
+
const built = buildSectionResult(headers, kind, lines, resolved.headerPos, resolved.redirectedFrom);
|
|
4715
4720
|
if (built === null || resolved.occurrences === null) return built;
|
|
4716
4721
|
return { ...built, occurrences: resolved.occurrences };
|
|
4717
4722
|
}
|
|
@@ -4747,13 +4752,13 @@ function findContainingSection(filePath, lineStart, lineEnd, readFn) {
|
|
|
4747
4752
|
const language = refineLanguageByContent(filePath, detectLanguage(filePath), text);
|
|
4748
4753
|
const { headers, kind } = findHeaders(text, language);
|
|
4749
4754
|
if (headers.length === 0) return null;
|
|
4750
|
-
const
|
|
4755
|
+
const lines = text.split("\n");
|
|
4751
4756
|
let bestPos = -1;
|
|
4752
4757
|
let bestHeaderLine = -1;
|
|
4753
4758
|
for (let i = 0; i < headers.length; i++) {
|
|
4754
4759
|
const header = headers[i];
|
|
4755
4760
|
if (header === void 0) continue;
|
|
4756
|
-
const endIndex = headerEndIndex(headers, kind, i,
|
|
4761
|
+
const endIndex = headerEndIndex(headers, kind, i, lines.length);
|
|
4757
4762
|
const sectionLineStart = header.index + 1;
|
|
4758
4763
|
if (sectionLineStart <= lineStart && lineEnd <= endIndex) {
|
|
4759
4764
|
if (header.index > bestHeaderLine) {
|
|
@@ -4763,7 +4768,7 @@ function findContainingSection(filePath, lineStart, lineEnd, readFn) {
|
|
|
4763
4768
|
}
|
|
4764
4769
|
}
|
|
4765
4770
|
if (bestPos === -1) return null;
|
|
4766
|
-
const result = buildSectionResult(headers, kind,
|
|
4771
|
+
const result = buildSectionResult(headers, kind, lines, bestPos, null);
|
|
4767
4772
|
if (result === null) return null;
|
|
4768
4773
|
const bestHeader = headers[bestPos];
|
|
4769
4774
|
if (bestHeader === void 0) return result;
|