@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 CHANGED
@@ -1343,6 +1343,156 @@ function patch(ts2, configFile, extractCache2, resolutionCache, host, ps) {
1343
1343
  }
1344
1344
  }
1345
1345
 
1346
+ // src/service/script/util/print-jsdoc-tag.ts
1347
+ var REG_BACK_TICK = /`/g;
1348
+ var REG_LINE = /\r\n|\n/;
1349
+ var REG_CODE_BLOCK = /^\s*[~`]{3}/m;
1350
+ var REG_CAPTION = /^<caption>(.*?)<\/caption>\s*(\r\n|\n)/;
1351
+ function printJSDocTag(tag) {
1352
+ var _a;
1353
+ switch (tag.name) {
1354
+ case "augments":
1355
+ case "extends":
1356
+ case "param":
1357
+ case "template": {
1358
+ const body = getTagBodyParts(tag);
1359
+ if ((body == null ? void 0 : body.length) === 3) {
1360
+ const [, param, text] = body;
1361
+ return `${printTagName(tag.name)} \`${param}\`${printTagBody(
1362
+ replaceLinks(text)
1363
+ )}`;
1364
+ }
1365
+ break;
1366
+ }
1367
+ case "return":
1368
+ case "returns": {
1369
+ if (!((_a = tag.text) == null ? void 0 : _a.length))
1370
+ return void 0;
1371
+ break;
1372
+ }
1373
+ }
1374
+ return printTagName(tag.name) + printTagBody(getTagBodyText(tag));
1375
+ }
1376
+ function getTagBodyParts(tag) {
1377
+ if (tag.name === "template") {
1378
+ const parts = tag.text;
1379
+ if (parts) {
1380
+ const params = parts.filter((p) => p.kind === "typeParameterName").map((p) => p.text).join(", ");
1381
+ const docs2 = parts.filter((p) => p.kind === "text").map((p) => convertLinkTags(p.text.replace(/^\s*-?\s*/, ""))).join(" ");
1382
+ return params ? ["", params, docs2] : void 0;
1383
+ }
1384
+ }
1385
+ return convertLinkTags(tag.text).split(/^(\S+)\s*-?\s*/);
1386
+ }
1387
+ function getTagBodyText(tag) {
1388
+ if (!tag.text)
1389
+ return "";
1390
+ const text = convertLinkTags(tag.text);
1391
+ switch (tag.name) {
1392
+ case "example": {
1393
+ const captionTagMatches = REG_CAPTION.exec(text);
1394
+ if (captionTagMatches) {
1395
+ const [captionMatch, captionText] = captionTagMatches;
1396
+ return `${captionText}
1397
+ ${ensureCodeblock(
1398
+ captionText.slice(captionMatch.length)
1399
+ )}`;
1400
+ } else {
1401
+ return ensureCodeblock(text);
1402
+ }
1403
+ }
1404
+ case "author": {
1405
+ const emailMatch = text.match(/(.+)\s<([-.\w]+@[-.\w]+)>/);
1406
+ if (emailMatch) {
1407
+ return `${emailMatch[1]} ${emailMatch[2]}`;
1408
+ }
1409
+ return text;
1410
+ }
1411
+ case "default":
1412
+ return ensureCodeblock(text);
1413
+ }
1414
+ return replaceLinks(text);
1415
+ }
1416
+ function convertLinkTags(parts) {
1417
+ if (!parts)
1418
+ return "";
1419
+ if (typeof parts === "string")
1420
+ return parts;
1421
+ let result = "";
1422
+ let currentLink;
1423
+ for (const part of parts) {
1424
+ switch (part.kind) {
1425
+ case "link":
1426
+ if (currentLink) {
1427
+ if (currentLink.target) {
1428
+ const linkText = currentLink.text ? currentLink.text : escapeBackTicks(currentLink.name ?? "");
1429
+ result += `[${currentLink.linkcode ? "`" + linkText + "`" : linkText}](${currentLink.target.file})`;
1430
+ } else {
1431
+ const text = currentLink.text ?? currentLink.name;
1432
+ if (text) {
1433
+ if (/^https?:/.test(text)) {
1434
+ const parts2 = text.split(" ");
1435
+ if (parts2.length === 1) {
1436
+ result += parts2[0];
1437
+ } else if (parts2.length > 1) {
1438
+ const linkText = escapeBackTicks(parts2.slice(1).join(" "));
1439
+ result += `[${currentLink.linkcode ? "`" + linkText + "`" : linkText}](${parts2[0]})`;
1440
+ }
1441
+ } else {
1442
+ result += escapeBackTicks(text);
1443
+ }
1444
+ }
1445
+ }
1446
+ currentLink = void 0;
1447
+ } else {
1448
+ currentLink = {
1449
+ linkcode: part.text === "{@linkcode "
1450
+ };
1451
+ }
1452
+ break;
1453
+ case "linkName":
1454
+ if (currentLink) {
1455
+ currentLink.name = part.text;
1456
+ currentLink.target = part.target;
1457
+ }
1458
+ break;
1459
+ case "linkText":
1460
+ if (currentLink) {
1461
+ currentLink.text = part.text;
1462
+ }
1463
+ break;
1464
+ default:
1465
+ result += part.text;
1466
+ break;
1467
+ }
1468
+ }
1469
+ return replaceLinks(result);
1470
+ }
1471
+ function replaceLinks(text) {
1472
+ return text.replace(
1473
+ /\{@(link|linkplain|linkcode) (https?:\/\/[^ |}]+?)(?:[| ]([^{}\n]+?))?\}/gi,
1474
+ (_, tag, link, text2) => {
1475
+ const alt = text2 ? text2.trim() : link;
1476
+ return `[${tag === "linkcode" ? `\`${alt}\`` : alt}](${link})`;
1477
+ }
1478
+ );
1479
+ }
1480
+ function printTagBody(text) {
1481
+ if (text) {
1482
+ return (REG_LINE.test(text) ? " \n" : " \u2014 ") + text;
1483
+ }
1484
+ return "";
1485
+ }
1486
+ function printTagName(name) {
1487
+ return `*@${name}*`;
1488
+ }
1489
+ function ensureCodeblock(text) {
1490
+ return REG_CODE_BLOCK.test(text) ? text : "```\n" + text + "\n```";
1491
+ }
1492
+ function escapeBackTicks(text) {
1493
+ return text.replace(REG_BACK_TICK, "\\$&");
1494
+ }
1495
+
1346
1496
  // src/service/script/index.ts
1347
1497
  var IGNORE_DIAG_REG = /^(?:(?:Expression|Identifier|['"][^\w]['"]) expected|Invalid character)\b/i;
1348
1498
  var extractCache = /* @__PURE__ */ new Map();
@@ -2026,14 +2176,15 @@ async function getPreferences(scriptLang) {
2026
2176
  }
2027
2177
  function printDocumentation(docs2, tags) {
2028
2178
  let result = "";
2179
+ let sep = "";
2029
2180
  if (docs2) {
2030
2181
  result += import_tsserverlibrary.default.displayPartsToString(docs2);
2182
+ sep = " \n\n";
2031
2183
  }
2032
2184
  if (tags) {
2033
2185
  for (const tag of tags) {
2034
- const text = import_tsserverlibrary.default.displayPartsToString(tag.text);
2035
- result += `*@${tag.name}*${text ? /\n/.test(text) ? `
2036
- ${text}` : `- ${text}` : ""}`;
2186
+ result += sep + printJSDocTag(tag);
2187
+ sep = " \n\n";
2037
2188
  }
2038
2189
  }
2039
2190
  return result;