@marko/language-server 1.0.12 → 1.0.13
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/dist/index.js +154 -3
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +154 -3
- package/dist/index.mjs.map +4 -4
- package/dist/service/script/util/print-jsdoc-tag.d.ts +5 -0
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1369,6 +1369,156 @@ function patch(ts2, configFile, extractCache2, resolutionCache, host, ps) {
|
|
|
1369
1369
|
}
|
|
1370
1370
|
}
|
|
1371
1371
|
|
|
1372
|
+
// src/service/script/util/print-jsdoc-tag.ts
|
|
1373
|
+
var REG_BACK_TICK = /`/g;
|
|
1374
|
+
var REG_LINE = /\r\n|\n/;
|
|
1375
|
+
var REG_CODE_BLOCK = /^\s*[~`]{3}/m;
|
|
1376
|
+
var REG_CAPTION = /^<caption>(.*?)<\/caption>\s*(\r\n|\n)/;
|
|
1377
|
+
function printJSDocTag(tag) {
|
|
1378
|
+
var _a;
|
|
1379
|
+
switch (tag.name) {
|
|
1380
|
+
case "augments":
|
|
1381
|
+
case "extends":
|
|
1382
|
+
case "param":
|
|
1383
|
+
case "template": {
|
|
1384
|
+
const body = getTagBodyParts(tag);
|
|
1385
|
+
if ((body == null ? void 0 : body.length) === 3) {
|
|
1386
|
+
const [, param, text] = body;
|
|
1387
|
+
return `${printTagName(tag.name)} \`${param}\`${printTagBody(
|
|
1388
|
+
replaceLinks(text)
|
|
1389
|
+
)}`;
|
|
1390
|
+
}
|
|
1391
|
+
break;
|
|
1392
|
+
}
|
|
1393
|
+
case "return":
|
|
1394
|
+
case "returns": {
|
|
1395
|
+
if (!((_a = tag.text) == null ? void 0 : _a.length))
|
|
1396
|
+
return void 0;
|
|
1397
|
+
break;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
return printTagName(tag.name) + printTagBody(getTagBodyText(tag));
|
|
1401
|
+
}
|
|
1402
|
+
function getTagBodyParts(tag) {
|
|
1403
|
+
if (tag.name === "template") {
|
|
1404
|
+
const parts = tag.text;
|
|
1405
|
+
if (parts) {
|
|
1406
|
+
const params = parts.filter((p) => p.kind === "typeParameterName").map((p) => p.text).join(", ");
|
|
1407
|
+
const docs2 = parts.filter((p) => p.kind === "text").map((p) => convertLinkTags(p.text.replace(/^\s*-?\s*/, ""))).join(" ");
|
|
1408
|
+
return params ? ["", params, docs2] : void 0;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return convertLinkTags(tag.text).split(/^(\S+)\s*-?\s*/);
|
|
1412
|
+
}
|
|
1413
|
+
function getTagBodyText(tag) {
|
|
1414
|
+
if (!tag.text)
|
|
1415
|
+
return "";
|
|
1416
|
+
const text = convertLinkTags(tag.text);
|
|
1417
|
+
switch (tag.name) {
|
|
1418
|
+
case "example": {
|
|
1419
|
+
const captionTagMatches = REG_CAPTION.exec(text);
|
|
1420
|
+
if (captionTagMatches) {
|
|
1421
|
+
const [captionMatch, captionText] = captionTagMatches;
|
|
1422
|
+
return `${captionText}
|
|
1423
|
+
${ensureCodeblock(
|
|
1424
|
+
captionText.slice(captionMatch.length)
|
|
1425
|
+
)}`;
|
|
1426
|
+
} else {
|
|
1427
|
+
return ensureCodeblock(text);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
case "author": {
|
|
1431
|
+
const emailMatch = text.match(/(.+)\s<([-.\w]+@[-.\w]+)>/);
|
|
1432
|
+
if (emailMatch) {
|
|
1433
|
+
return `${emailMatch[1]} ${emailMatch[2]}`;
|
|
1434
|
+
}
|
|
1435
|
+
return text;
|
|
1436
|
+
}
|
|
1437
|
+
case "default":
|
|
1438
|
+
return ensureCodeblock(text);
|
|
1439
|
+
}
|
|
1440
|
+
return replaceLinks(text);
|
|
1441
|
+
}
|
|
1442
|
+
function convertLinkTags(parts) {
|
|
1443
|
+
if (!parts)
|
|
1444
|
+
return "";
|
|
1445
|
+
if (typeof parts === "string")
|
|
1446
|
+
return parts;
|
|
1447
|
+
let result = "";
|
|
1448
|
+
let currentLink;
|
|
1449
|
+
for (const part of parts) {
|
|
1450
|
+
switch (part.kind) {
|
|
1451
|
+
case "link":
|
|
1452
|
+
if (currentLink) {
|
|
1453
|
+
if (currentLink.target) {
|
|
1454
|
+
const linkText = currentLink.text ? currentLink.text : escapeBackTicks(currentLink.name ?? "");
|
|
1455
|
+
result += `[${currentLink.linkcode ? "`" + linkText + "`" : linkText}](${currentLink.target.file})`;
|
|
1456
|
+
} else {
|
|
1457
|
+
const text = currentLink.text ?? currentLink.name;
|
|
1458
|
+
if (text) {
|
|
1459
|
+
if (/^https?:/.test(text)) {
|
|
1460
|
+
const parts2 = text.split(" ");
|
|
1461
|
+
if (parts2.length === 1) {
|
|
1462
|
+
result += parts2[0];
|
|
1463
|
+
} else if (parts2.length > 1) {
|
|
1464
|
+
const linkText = escapeBackTicks(parts2.slice(1).join(" "));
|
|
1465
|
+
result += `[${currentLink.linkcode ? "`" + linkText + "`" : linkText}](${parts2[0]})`;
|
|
1466
|
+
}
|
|
1467
|
+
} else {
|
|
1468
|
+
result += escapeBackTicks(text);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
currentLink = void 0;
|
|
1473
|
+
} else {
|
|
1474
|
+
currentLink = {
|
|
1475
|
+
linkcode: part.text === "{@linkcode "
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
break;
|
|
1479
|
+
case "linkName":
|
|
1480
|
+
if (currentLink) {
|
|
1481
|
+
currentLink.name = part.text;
|
|
1482
|
+
currentLink.target = part.target;
|
|
1483
|
+
}
|
|
1484
|
+
break;
|
|
1485
|
+
case "linkText":
|
|
1486
|
+
if (currentLink) {
|
|
1487
|
+
currentLink.text = part.text;
|
|
1488
|
+
}
|
|
1489
|
+
break;
|
|
1490
|
+
default:
|
|
1491
|
+
result += part.text;
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
return replaceLinks(result);
|
|
1496
|
+
}
|
|
1497
|
+
function replaceLinks(text) {
|
|
1498
|
+
return text.replace(
|
|
1499
|
+
/\{@(link|linkplain|linkcode) (https?:\/\/[^ |}]+?)(?:[| ]([^{}\n]+?))?\}/gi,
|
|
1500
|
+
(_, tag, link, text2) => {
|
|
1501
|
+
const alt = text2 ? text2.trim() : link;
|
|
1502
|
+
return `[${tag === "linkcode" ? `\`${alt}\`` : alt}](${link})`;
|
|
1503
|
+
}
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
function printTagBody(text) {
|
|
1507
|
+
if (text) {
|
|
1508
|
+
return (REG_LINE.test(text) ? " \n" : " \u2014 ") + text;
|
|
1509
|
+
}
|
|
1510
|
+
return "";
|
|
1511
|
+
}
|
|
1512
|
+
function printTagName(name) {
|
|
1513
|
+
return `*@${name}*`;
|
|
1514
|
+
}
|
|
1515
|
+
function ensureCodeblock(text) {
|
|
1516
|
+
return REG_CODE_BLOCK.test(text) ? text : "```\n" + text + "\n```";
|
|
1517
|
+
}
|
|
1518
|
+
function escapeBackTicks(text) {
|
|
1519
|
+
return text.replace(REG_BACK_TICK, "\\$&");
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1372
1522
|
// src/service/script/index.ts
|
|
1373
1523
|
var IGNORE_DIAG_REG = /^(?:(?:Expression|Identifier|['"][^\w]['"]) expected|Invalid character)\b/i;
|
|
1374
1524
|
var extractCache = /* @__PURE__ */ new Map();
|
|
@@ -2052,14 +2202,15 @@ async function getPreferences(scriptLang) {
|
|
|
2052
2202
|
}
|
|
2053
2203
|
function printDocumentation(docs2, tags) {
|
|
2054
2204
|
let result = "";
|
|
2205
|
+
let sep = "";
|
|
2055
2206
|
if (docs2) {
|
|
2056
2207
|
result += ts.displayPartsToString(docs2);
|
|
2208
|
+
sep = " \n\n";
|
|
2057
2209
|
}
|
|
2058
2210
|
if (tags) {
|
|
2059
2211
|
for (const tag of tags) {
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
${text}` : `- ${text}` : ""}`;
|
|
2212
|
+
result += sep + printJSDocTag(tag);
|
|
2213
|
+
sep = " \n\n";
|
|
2063
2214
|
}
|
|
2064
2215
|
}
|
|
2065
2216
|
return result;
|