@marko/language-server 0.12.12 → 0.12.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.mjs CHANGED
@@ -571,7 +571,7 @@ function loadCompilerInfo(dir) {
571
571
  const rootDir = lassoPackageRoot.getRootDir(dir);
572
572
  const pkgPath = rootDir && resolveFrom.silent(rootDir, "@marko/compiler/package.json");
573
573
  const pkg = pkgPath && __require(pkgPath);
574
- const cache3 = /* @__PURE__ */ new Map();
574
+ const cache4 = /* @__PURE__ */ new Map();
575
575
  let translator = builtinTranslator;
576
576
  let compiler = builtinCompiler;
577
577
  if (pkg && /^5\./.test(pkg.version)) {
@@ -588,16 +588,16 @@ function loadCompilerInfo(dir) {
588
588
  }
589
589
  }
590
590
  return {
591
- cache: cache3,
591
+ cache: cache4,
592
592
  get lookup() {
593
- let lookup = cache3.get(lookupKey);
593
+ let lookup = cache4.get(lookupKey);
594
594
  if (lookup === void 0) {
595
595
  try {
596
596
  lookup = compiler.taglib.buildLookup(dir, translator);
597
597
  } catch {
598
598
  lookup = builtinInfo.lookup;
599
599
  }
600
- cache3.set(lookupKey, lookup);
600
+ cache4.set(lookupKey, lookup);
601
601
  }
602
602
  return lookup;
603
603
  },
@@ -697,10 +697,10 @@ function getTagNameCompletion({
697
697
  const fileURIForTag = URI2.file(fileForTag).toString();
698
698
  const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
699
699
  const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
700
- const isCoreTag = nodeModuleName === "marko";
700
+ const isCoreTag = /^@?marko[/-]/.test(tag.taglibId) || nodeModuleName === "marko";
701
701
  const documentation = {
702
702
  kind: MarkupKind.Markdown,
703
- value: tag.html ? `Built in [<${tag.name}>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${tag.name}) HTML tag.` : nodeModuleName ? isCoreTag ? `Core Marko [<${tag.name}>](${fileURIForTag}) tag.` : `Custom Marko tag discovered from the ["${nodeModuleName}"](${fileURIForTag}) npm package.` : `Custom Marko tag discovered from:
703
+ value: tag.html ? `Built in [&lt;${tag.name}&gt;](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${tag.name}) HTML tag.` : isCoreTag ? `Core Marko &lt;${tag.name}&gt; tag.` : nodeModuleName ? `Custom Marko tag discovered from the ["${nodeModuleName}"](${fileURIForTag}) npm package.` : `Custom Marko tag discovered from:
704
704
 
705
705
  [${importer ? path2.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
706
706
  };
@@ -1097,10 +1097,10 @@ var markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
1097
1097
  var doValidate = (doc) => {
1098
1098
  const fsPath = getDocFile(doc);
1099
1099
  const diagnostics = [];
1100
- const { compiler, translator, cache: cache3 } = getCompilerInfo(doc);
1100
+ const { compiler, translator, cache: cache4 } = getCompilerInfo(doc);
1101
1101
  try {
1102
1102
  compiler.compileSync(doc.getText(), fsPath || "untitled.marko", {
1103
- cache: cache3,
1103
+ cache: cache4,
1104
1104
  translator,
1105
1105
  code: false,
1106
1106
  output: "source",
@@ -1118,6 +1118,62 @@ var doValidate = (doc) => {
1118
1118
  return diagnostics;
1119
1119
  };
1120
1120
 
1121
+ // src/utils/utils.ts
1122
+ import fs2 from "fs";
1123
+ import { URI as URI3 } from "vscode-uri";
1124
+ import { Position, Range as Range4 } from "vscode-languageserver";
1125
+ import { TextDocument } from "vscode-languageserver-textdocument";
1126
+ var START_OF_FILE = Range4.create(Position.create(0, 0), Position.create(0, 0));
1127
+ function createTextDocument(filename) {
1128
+ const uri = URI3.file(filename).toString();
1129
+ const content = fs2.readFileSync(filename, "utf-8");
1130
+ return TextDocument.create(uri, "plaintext", 0, content);
1131
+ }
1132
+
1133
+ // src/service/marko/hover/OpenTagName.ts
1134
+ function OpenTagName2({
1135
+ document,
1136
+ lookup,
1137
+ parsed,
1138
+ node
1139
+ }) {
1140
+ const importer = getDocFile(document);
1141
+ const tag = node.parent;
1142
+ const range = parsed.locationAt(node);
1143
+ const tagDef = tag.nameText && lookup.getTag(tag.nameText);
1144
+ if (tagDef) {
1145
+ const completion = getTagNameCompletion({
1146
+ tag: tagDef,
1147
+ range: START_OF_FILE,
1148
+ importer
1149
+ });
1150
+ return {
1151
+ range,
1152
+ contents: completion.documentation
1153
+ };
1154
+ }
1155
+ }
1156
+
1157
+ // src/service/marko/hover/index.ts
1158
+ var handlers2 = {
1159
+ OpenTagName: OpenTagName2
1160
+ };
1161
+ var doHover = async (doc, params) => {
1162
+ var _a;
1163
+ const parsed = parse2(doc);
1164
+ const offset = doc.offsetAt(params.position);
1165
+ const node = parsed.nodeAt(offset);
1166
+ return await ((_a = handlers2[NodeType[node.type]]) == null ? void 0 : _a.call(handlers2, {
1167
+ document: doc,
1168
+ params,
1169
+ parsed,
1170
+ offset,
1171
+ node,
1172
+ code: doc.getText(),
1173
+ ...getCompilerInfo(doc)
1174
+ }));
1175
+ };
1176
+
1121
1177
  // src/service/marko/definition/OpenTagName.ts
1122
1178
  import path4 from "path";
1123
1179
  import { URI as URI4 } from "vscode-uri";
@@ -1147,20 +1203,8 @@ function escape(val) {
1147
1203
  return String(val).replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
1148
1204
  }
1149
1205
 
1150
- // src/utils/utils.ts
1151
- import fs2 from "fs";
1152
- import { URI as URI3 } from "vscode-uri";
1153
- import { Position, Range as Range4 } from "vscode-languageserver";
1154
- import { TextDocument } from "vscode-languageserver-textdocument";
1155
- var START_OF_FILE = Range4.create(Position.create(0, 0), Position.create(0, 0));
1156
- function createTextDocument(filename) {
1157
- const uri = URI3.file(filename).toString();
1158
- const content = fs2.readFileSync(filename, "utf-8");
1159
- return TextDocument.create(uri, "plaintext", 0, content);
1160
- }
1161
-
1162
1206
  // src/service/marko/definition/OpenTagName.ts
1163
- function OpenTagName2({
1207
+ function OpenTagName3({
1164
1208
  lookup,
1165
1209
  parsed,
1166
1210
  node
@@ -1230,8 +1274,8 @@ function AttrName2({
1230
1274
  }
1231
1275
 
1232
1276
  // src/service/marko/definition/index.ts
1233
- var handlers2 = {
1234
- OpenTagName: OpenTagName2,
1277
+ var handlers3 = {
1278
+ OpenTagName: OpenTagName3,
1235
1279
  AttrName: AttrName2
1236
1280
  };
1237
1281
  var findDefinition = async (doc, params) => {
@@ -1239,7 +1283,7 @@ var findDefinition = async (doc, params) => {
1239
1283
  const parsed = parse2(doc);
1240
1284
  const offset = doc.offsetAt(params.position);
1241
1285
  const node = parsed.nodeAt(offset);
1242
- return await ((_a = handlers2[NodeType[node.type]]) == null ? void 0 : _a.call(handlers2, {
1286
+ return await ((_a = handlers3[NodeType[node.type]]) == null ? void 0 : _a.call(handlers3, {
1243
1287
  document: doc,
1244
1288
  params,
1245
1289
  parsed,
@@ -1264,14 +1308,18 @@ function extractDocumentLinks(doc, parsed, lookup) {
1264
1308
  const read = (range) => code.slice(range.start, range.end);
1265
1309
  const visit = (node) => {
1266
1310
  switch (node.type) {
1311
+ case 14 /* AttrTag */:
1312
+ if (node.body) {
1313
+ for (const child of node.body) {
1314
+ visit(child);
1315
+ }
1316
+ }
1317
+ break;
1267
1318
  case 1 /* Tag */:
1268
1319
  if (node.attrs && node.nameText) {
1269
1320
  for (const attr of node.attrs) {
1270
1321
  if (isDocumentLinkAttr(doc, node, attr)) {
1271
- links.push(DocumentLink.create({
1272
- start: parsed.positionAt(attr.value.value.start),
1273
- end: parsed.positionAt(attr.value.value.end)
1274
- }, resolveUrl(read(attr.value.value).slice(1, -1), doc.uri)));
1322
+ links.push(DocumentLink.create(parsed.locationAt(attr.value.value), resolveUrl(read(attr.value.value).slice(1, -1), doc.uri)));
1275
1323
  }
1276
1324
  }
1277
1325
  }
@@ -1293,10 +1341,10 @@ function extractDocumentLinks(doc, parsed, lookup) {
1293
1341
  const tagDef = lookup.getTag(tagName);
1294
1342
  const fileForTag = tagDef && (tagDef.template || tagDef.renderer);
1295
1343
  if (fileForTag) {
1296
- links.push(DocumentLink.create({
1297
- start: parsed.positionAt(item.start + match.index),
1298
- end: parsed.positionAt(item.start + match.index + length)
1299
- }, fileForTag));
1344
+ links.push(DocumentLink.create(parsed.locationAt({
1345
+ start: item.start + match.index,
1346
+ end: item.start + match.index + length
1347
+ }), fileForTag));
1300
1348
  }
1301
1349
  }
1302
1350
  }
@@ -1319,14 +1367,55 @@ var findDocumentLinks = async (doc) => {
1319
1367
  return result;
1320
1368
  };
1321
1369
 
1370
+ // src/service/marko/document-symbols/extract.ts
1371
+ import { URI as URI7 } from "vscode-uri";
1372
+ import { SymbolInformation, SymbolKind } from "vscode-languageserver";
1373
+ function extractDocumentSymbols(doc, parsed, lookup) {
1374
+ if (URI7.parse(doc.uri).scheme === "untitled") {
1375
+ return [];
1376
+ }
1377
+ const symbols = [];
1378
+ const { program } = parsed;
1379
+ const visit = (node) => {
1380
+ var _a, _b;
1381
+ switch (node.type) {
1382
+ case 1 /* Tag */:
1383
+ case 14 /* AttrTag */:
1384
+ symbols.push(SymbolInformation.create((node.type === 14 /* AttrTag */ ? (_a = node.nameText) == null ? void 0 : _a.slice(node.nameText.indexOf("@")) : node.nameText) || "<${...}>", node.nameText && ((_b = lookup.getTag(node.nameText)) == null ? void 0 : _b.html) && SymbolKind.Property || SymbolKind.Class, parsed.locationAt(node), doc.uri));
1385
+ if (node.body) {
1386
+ for (const child of node.body) {
1387
+ visit(child);
1388
+ }
1389
+ }
1390
+ break;
1391
+ }
1392
+ };
1393
+ for (const item of program.body) {
1394
+ visit(item);
1395
+ }
1396
+ return symbols;
1397
+ }
1398
+
1399
+ // src/service/marko/document-symbols/index.ts
1400
+ var cache2 = /* @__PURE__ */ new WeakMap();
1401
+ var findDocumentSymbols = async (doc) => {
1402
+ const parsed = parse2(doc);
1403
+ let result = cache2.get(parsed);
1404
+ if (!result) {
1405
+ result = extractDocumentSymbols(doc, parsed, getCompilerInfo(doc).lookup);
1406
+ cache2.set(parsed, result);
1407
+ }
1408
+ return result;
1409
+ };
1410
+
1322
1411
  // src/service/marko/format.ts
1323
1412
  import { Range as Range7, TextEdit as TextEdit6 } from "vscode-languageserver";
1324
- import { URI as URI7 } from "vscode-uri";
1413
+ import { URI as URI8 } from "vscode-uri";
1325
1414
  import * as prettier from "prettier";
1326
1415
  import * as markoPrettier from "prettier-plugin-marko";
1327
1416
  var format2 = async (doc, params, cancel) => {
1328
1417
  try {
1329
- const { fsPath, scheme } = URI7.parse(doc.uri);
1418
+ const { fsPath, scheme } = URI8.parse(doc.uri);
1330
1419
  const text = doc.getText();
1331
1420
  const options = {
1332
1421
  parser: "marko",
@@ -1352,8 +1441,10 @@ var format2 = async (doc, params, cancel) => {
1352
1441
  var marko_default = {
1353
1442
  doComplete,
1354
1443
  doValidate,
1444
+ doHover,
1355
1445
  findDefinition,
1356
1446
  findDocumentLinks,
1447
+ findDocumentSymbols,
1357
1448
  format: format2
1358
1449
  };
1359
1450
 
@@ -1472,6 +1563,13 @@ function extractStyleSheets(code, program, lookup) {
1472
1563
  const visit = (node) => {
1473
1564
  var _a, _b;
1474
1565
  switch (node.type) {
1566
+ case 14 /* AttrTag */:
1567
+ if (node.body) {
1568
+ for (const child of node.body) {
1569
+ visit(child);
1570
+ }
1571
+ }
1572
+ break;
1475
1573
  case 1 /* Tag */:
1476
1574
  if (node.nameText === "style" && node.concise && node.attrs) {
1477
1575
  const block = node.attrs.at(-1);
@@ -1528,7 +1626,7 @@ function extractStyleSheets(code, program, lookup) {
1528
1626
  }
1529
1627
 
1530
1628
  // src/service/stylesheet/index.ts
1531
- var cache2 = /* @__PURE__ */ new WeakMap();
1629
+ var cache3 = /* @__PURE__ */ new WeakMap();
1532
1630
  var services = {
1533
1631
  css: getCSSLanguageService,
1534
1632
  less: getLESSLanguageService,
@@ -1616,6 +1714,32 @@ var StyleSheetService = {
1616
1714
  return result.length ? result : void 0;
1617
1715
  }
1618
1716
  },
1717
+ findDocumentSymbols(doc) {
1718
+ const infoByExt = getStyleSheetInfo(doc);
1719
+ const result = [];
1720
+ for (const ext in infoByExt) {
1721
+ const info = infoByExt[ext];
1722
+ const { service: service2, virtualDoc } = info;
1723
+ for (const symbol of service2.findDocumentSymbols(virtualDoc, info.parsed)) {
1724
+ if (symbol.location.uri === doc.uri) {
1725
+ const range = getSourceRange(doc, info, symbol.location.range);
1726
+ if (range) {
1727
+ result.push({
1728
+ kind: symbol.kind,
1729
+ name: symbol.name,
1730
+ tags: symbol.tags,
1731
+ deprecated: symbol.deprecated,
1732
+ containerName: symbol.containerName,
1733
+ location: { uri: doc.uri, range }
1734
+ });
1735
+ }
1736
+ } else {
1737
+ result.push(symbol);
1738
+ }
1739
+ }
1740
+ }
1741
+ return result.length ? result : void 0;
1742
+ },
1619
1743
  async findDocumentLinks(doc) {
1620
1744
  const infoByExt = getStyleSheetInfo(doc);
1621
1745
  const result = [];
@@ -1855,7 +1979,7 @@ function getSourceRange(doc, info, range) {
1855
1979
  function getStyleSheetInfo(doc) {
1856
1980
  var _a;
1857
1981
  const parsed = parse2(doc);
1858
- let cached = cache2.get(parsed);
1982
+ let cached = cache3.get(parsed);
1859
1983
  if (!cached) {
1860
1984
  const results = extractStyleSheets(doc.getText(), parsed.program, getCompilerInfo(doc).lookup);
1861
1985
  cached = {};
@@ -1876,7 +2000,7 @@ function getStyleSheetInfo(doc) {
1876
2000
  parsed: service2.parseStylesheet(virtualDoc)
1877
2001
  };
1878
2002
  }
1879
- cache2.set(parsed, cached);
2003
+ cache3.set(parsed, cached);
1880
2004
  }
1881
2005
  return cached;
1882
2006
  }
@@ -1959,6 +2083,24 @@ var service = {
1959
2083
  }
1960
2084
  return result;
1961
2085
  },
2086
+ async findDocumentSymbols(doc, params, cancel) {
2087
+ let result;
2088
+ try {
2089
+ for (const pending of plugins.map((plugin) => {
2090
+ var _a;
2091
+ return (_a = plugin.findDocumentSymbols) == null ? void 0 : _a.call(plugin, doc, params, cancel);
2092
+ })) {
2093
+ const cur = await pending;
2094
+ if (cancel.isCancellationRequested)
2095
+ return;
2096
+ if (cur)
2097
+ result = result ? result.concat(cur) : cur;
2098
+ }
2099
+ } catch (err) {
2100
+ displayError(err);
2101
+ }
2102
+ return result;
2103
+ },
1962
2104
  async findDocumentLinks(doc, params, cancel) {
1963
2105
  let result;
1964
2106
  try {
@@ -2159,6 +2301,7 @@ connection2.onInitialize(async (params) => {
2159
2301
  documentLinkProvider: { resolveProvider: false },
2160
2302
  colorProvider: true,
2161
2303
  documentHighlightProvider: true,
2304
+ documentSymbolProvider: true,
2162
2305
  completionProvider: {
2163
2306
  triggerCharacters: [
2164
2307
  ".",
@@ -2204,6 +2347,9 @@ connection2.onReferences(async (params, cancel) => {
2204
2347
  connection2.onDocumentLinks(async (params, cancel) => {
2205
2348
  return await service.findDocumentLinks(documents.get(params.textDocument.uri), params, cancel) || null;
2206
2349
  });
2350
+ connection2.onDocumentSymbol(async (params, cancel) => {
2351
+ return await service.findDocumentSymbols(documents.get(params.textDocument.uri), params, cancel) || null;
2352
+ });
2207
2353
  connection2.onDocumentHighlight(async (params, cancel) => {
2208
2354
  return await service.findDocumentHighlights(documents.get(params.textDocument.uri), params, cancel) || null;
2209
2355
  });