@marko/language-server 1.4.25 → 1.4.26

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
@@ -21,7 +21,7 @@ Project.setDefaultCompilerMeta(defaultCompiler, {
21
21
  });
22
22
 
23
23
  // src/index.ts
24
- import { Project as Project6 } from "@marko/language-tools";
24
+ import { Project as Project7 } from "@marko/language-tools";
25
25
  import { inspect as inspect2, isDeepStrictEqual } from "util";
26
26
  import {
27
27
  createConnection,
@@ -927,7 +927,7 @@ async function acquireMutexLock() {
927
927
  var html_default = HTMLService;
928
928
 
929
929
  // src/service/marko/complete/index.ts
930
- import { NodeType as NodeType3 } from "@marko/language-tools";
930
+ import { NodeType as NodeType4 } from "@marko/language-tools";
931
931
 
932
932
  // src/service/marko/complete/AttrName.ts
933
933
  import {
@@ -1177,6 +1177,7 @@ async function AttrValue({
1177
1177
  }
1178
1178
 
1179
1179
  // src/service/marko/complete/Import.ts
1180
+ import { NodeType as NodeType2 } from "@marko/language-tools";
1180
1181
  import { TextEdit as TextEdit4 } from "vscode-languageserver";
1181
1182
 
1182
1183
  // src/service/marko/util/get-tag-name-completion.ts
@@ -1242,12 +1243,16 @@ ${autocomplete.description}`;
1242
1243
  }
1243
1244
 
1244
1245
  // src/service/marko/complete/Import.ts
1246
+ var staticImportReg = /^\s*(?:static|client|server) import\b/;
1245
1247
  var importTagReg = /(['"])<((?:[^'"\\>]|\\.)*)>?\1/;
1246
1248
  function Import({
1247
1249
  node,
1248
1250
  file: { parsed, filename, lookup }
1249
1251
  }) {
1250
1252
  const value = parsed.read(node);
1253
+ if (node.type === NodeType2.Static && !staticImportReg.test(value)) {
1254
+ return;
1255
+ }
1251
1256
  const match = importTagReg.exec(value);
1252
1257
  if (match) {
1253
1258
  const [{ length }] = match;
@@ -1273,14 +1278,14 @@ function Import({
1273
1278
  }
1274
1279
 
1275
1280
  // src/service/marko/complete/OpenTagName.ts
1276
- import { NodeType as NodeType2 } from "@marko/language-tools";
1281
+ import { NodeType as NodeType3 } from "@marko/language-tools";
1277
1282
  function OpenTagName({
1278
1283
  node,
1279
1284
  file: { parsed, filename, lookup }
1280
1285
  }) {
1281
1286
  const tag = node.parent;
1282
1287
  const range = parsed.locationAt(node);
1283
- const isAttrTag = tag.type === NodeType2.AttrTag;
1288
+ const isAttrTag = tag.type === NodeType3.AttrTag;
1284
1289
  const result = [];
1285
1290
  if (isAttrTag) {
1286
1291
  const ownerTagDef = tag.owner && tag.owner.nameText && lookup.getTag(tag.owner.nameText);
@@ -1301,7 +1306,7 @@ function OpenTagName({
1301
1306
  }
1302
1307
  }
1303
1308
  } else {
1304
- const skipStatements = !(tag.concise && tag.parent.type === NodeType2.Program);
1309
+ const skipStatements = !(tag.concise && tag.parent.type === NodeType3.Program);
1305
1310
  for (const tag2 of lookup.getTagsSorted()) {
1306
1311
  if (!(tag2.name === "*" || tag2.isNestedTag || skipStatements && tag2.parseOptions?.statement || tag2.name[0] === "_" && /^@?marko[/-]|[\\/]node_modules[\\/]/.test(tag2.filePath))) {
1307
1312
  const completion = getTagNameCompletion({
@@ -1373,14 +1378,15 @@ var handlers = {
1373
1378
  OpenTagName,
1374
1379
  AttrName,
1375
1380
  AttrValue,
1376
- Import
1381
+ Import,
1382
+ Static: Import
1377
1383
  };
1378
1384
  var doComplete = async (doc, params) => {
1379
1385
  const file = getMarkoFile(doc);
1380
1386
  const offset = doc.offsetAt(params.position);
1381
1387
  const node = file.parsed.nodeAt(offset);
1382
1388
  return {
1383
- items: await handlers[NodeType3[node.type]]?.({
1389
+ items: await handlers[NodeType4[node.type]]?.({
1384
1390
  file,
1385
1391
  params,
1386
1392
  offset,
@@ -1391,7 +1397,7 @@ var doComplete = async (doc, params) => {
1391
1397
  };
1392
1398
 
1393
1399
  // src/service/marko/definition/index.ts
1394
- import { NodeType as NodeType5 } from "@marko/language-tools";
1400
+ import { NodeType as NodeType6 } from "@marko/language-tools";
1395
1401
 
1396
1402
  // src/service/marko/definition/AttrName.ts
1397
1403
  import { getLines, getLocation } from "@marko/language-tools";
@@ -1476,7 +1482,7 @@ function AttrName2({
1476
1482
  import {
1477
1483
  getLines as getLines2,
1478
1484
  getLocation as getLocation2,
1479
- NodeType as NodeType4
1485
+ NodeType as NodeType5
1480
1486
  } from "@marko/language-tools";
1481
1487
  import fs4 from "fs";
1482
1488
  import path5 from "path";
@@ -1488,7 +1494,7 @@ function OpenTagName2({
1488
1494
  const tag = node.parent;
1489
1495
  let tagDef;
1490
1496
  let range = START_LOCATION;
1491
- if (tag.type === NodeType4.AttrTag) {
1497
+ if (tag.type === NodeType5.AttrTag) {
1492
1498
  tagDef = tag.owner && tag.owner.nameText ? lookup.getTag(tag.owner.nameText) : void 0;
1493
1499
  } else {
1494
1500
  tagDef = tag.nameText ? lookup.getTag(tag.nameText) : void 0;
@@ -1532,7 +1538,7 @@ var findDefinition = async (doc, params) => {
1532
1538
  const file = getMarkoFile(doc);
1533
1539
  const offset = doc.offsetAt(params.position);
1534
1540
  const node = file.parsed.nodeAt(offset);
1535
- return await handlers2[NodeType5[node.type]]?.({
1541
+ return await handlers2[NodeType6[node.type]]?.({
1536
1542
  file,
1537
1543
  params,
1538
1544
  offset,
@@ -1541,7 +1547,7 @@ var findDefinition = async (doc, params) => {
1541
1547
  };
1542
1548
 
1543
1549
  // src/service/marko/document-links.ts
1544
- import { NodeType as NodeType6 } from "@marko/language-tools";
1550
+ import { NodeType as NodeType7 } from "@marko/language-tools";
1545
1551
  var importTagReg2 = /(['"])<((?:[^'"\\>]|\\.)*)>?\1/g;
1546
1552
  var findDocumentLinks = async (doc) => {
1547
1553
  return processDoc(doc, extractDocumentLinks);
@@ -1560,14 +1566,14 @@ function extractDocumentLinks({
1560
1566
  const { program, read } = parsed;
1561
1567
  const visit = (node) => {
1562
1568
  switch (node.type) {
1563
- case NodeType6.AttrTag:
1569
+ case NodeType7.AttrTag:
1564
1570
  if (node.body) {
1565
1571
  for (const child of node.body) {
1566
1572
  visit(child);
1567
1573
  }
1568
1574
  }
1569
1575
  break;
1570
- case NodeType6.Tag:
1576
+ case NodeType7.Tag:
1571
1577
  if (node.attrs && node.nameText) {
1572
1578
  for (const attr of node.attrs) {
1573
1579
  if (isDocumentLinkAttr(code, node, attr)) {
@@ -1593,7 +1599,7 @@ function extractDocumentLinks({
1593
1599
  }
1594
1600
  };
1595
1601
  for (const node of program.static) {
1596
- if (node.type === NodeType6.Import) {
1602
+ if (node.type === NodeType7.Import) {
1597
1603
  importTagReg2.lastIndex = 0;
1598
1604
  const value = parsed.read(node);
1599
1605
  const match = importTagReg2.exec(value);
@@ -1620,7 +1626,7 @@ function extractDocumentLinks({
1620
1626
  }
1621
1627
 
1622
1628
  // src/service/marko/document-symbols.ts
1623
- import { NodeType as NodeType7 } from "@marko/language-tools";
1629
+ import { NodeType as NodeType8 } from "@marko/language-tools";
1624
1630
  import { SymbolKind } from "vscode-languageserver";
1625
1631
  var findDocumentSymbols = async (doc) => processDoc(doc, extractDocumentSymbols);
1626
1632
  function extractDocumentSymbols({
@@ -1636,10 +1642,10 @@ function extractDocumentSymbols({
1636
1642
  const { program } = parsed;
1637
1643
  const visit = (node) => {
1638
1644
  switch (node.type) {
1639
- case NodeType7.Tag:
1640
- case NodeType7.AttrTag:
1645
+ case NodeType8.Tag:
1646
+ case NodeType8.AttrTag:
1641
1647
  symbols.push({
1642
- name: (node.type === NodeType7.AttrTag ? node.nameText?.slice(node.nameText.indexOf("@")) : node.nameText) || "<${...}>",
1648
+ name: (node.type === NodeType8.AttrTag ? node.nameText?.slice(node.nameText.indexOf("@")) : node.nameText) || "<${...}>",
1643
1649
  kind: node.nameText && lookup.getTag(node.nameText)?.html && SymbolKind.Property || SymbolKind.Class,
1644
1650
  location: {
1645
1651
  uri,
@@ -1728,7 +1734,7 @@ var format2 = async (doc, params, cancel) => {
1728
1734
  };
1729
1735
 
1730
1736
  // src/service/marko/hover/index.ts
1731
- import { NodeType as NodeType8 } from "@marko/language-tools";
1737
+ import { NodeType as NodeType9 } from "@marko/language-tools";
1732
1738
 
1733
1739
  // src/service/marko/hover/OpenTagName.ts
1734
1740
  function OpenTagName3({
@@ -1761,7 +1767,7 @@ var doHover = async (doc, params) => {
1761
1767
  const file = getMarkoFile(doc);
1762
1768
  const offset = doc.offsetAt(params.position);
1763
1769
  const node = file.parsed.nodeAt(offset);
1764
- return await handlers3[NodeType8[node.type]]?.({
1770
+ return await handlers3[NodeType9[node.type]]?.({
1765
1771
  file,
1766
1772
  params,
1767
1773
  offset,
@@ -1936,8 +1942,8 @@ var marko_default = {
1936
1942
  // src/service/script/index.ts
1937
1943
  import {
1938
1944
  extractScript,
1939
- NodeType as NodeType9,
1940
- Project as Project5,
1945
+ NodeType as NodeType10,
1946
+ Project as Project6,
1941
1947
  ScriptLang
1942
1948
  } from "@marko/language-tools";
1943
1949
  import path8 from "path";
@@ -1957,11 +1963,13 @@ import { URI as URI6 } from "vscode-uri";
1957
1963
  import {
1958
1964
  getExt,
1959
1965
  isDefinitionFile,
1960
- Processors
1966
+ Processors,
1967
+ Project as Project5
1961
1968
  } from "@marko/language-tools";
1962
1969
  import path7 from "path";
1963
1970
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
1964
1971
  var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
1972
+ var importTagReg3 = /<([^>]+)>/;
1965
1973
  function patch(ts2, configFile, extractCache3, resolutionCache, host, ps) {
1966
1974
  const processors = Processors.create({
1967
1975
  ts: ts2,
@@ -2039,7 +2047,18 @@ function patch(ts2, configFile, extractCache3, resolutionCache, host, ps) {
2039
2047
  let resolvedModules;
2040
2048
  for (let i = 0; i < moduleLiterals.length; i++) {
2041
2049
  const moduleLiteral = moduleLiterals[i];
2042
- const moduleName = moduleLiteral.text;
2050
+ let moduleName = moduleLiteral.text;
2051
+ const tagNameMatch = importTagReg3.exec(moduleName);
2052
+ if (tagNameMatch) {
2053
+ const [, tagName] = tagNameMatch;
2054
+ const tagDef = Project5.getTagLookup(
2055
+ path7.dirname(containingFile)
2056
+ ).getTag(tagName);
2057
+ const tagFileName = tagDef && (tagDef.template || tagDef.renderer);
2058
+ if (tagFileName) {
2059
+ moduleName = tagFileName;
2060
+ }
2061
+ }
2043
2062
  const processor = moduleName[0] !== "*" ? getProcessor(moduleName) : void 0;
2044
2063
  if (processor) {
2045
2064
  let resolvedFileName;
@@ -2360,7 +2379,7 @@ var ScriptService = {
2360
2379
  if (!filename) return;
2361
2380
  const tsProject = getTSProject(filename);
2362
2381
  const extracted = processScript(doc, tsProject);
2363
- const lang = Project5.getScriptLang(
2382
+ const lang = Project6.getScriptLang(
2364
2383
  filename,
2365
2384
  tsProject.markoScriptLang,
2366
2385
  ts,
@@ -2714,9 +2733,9 @@ function processScript(doc, tsProject) {
2714
2733
  ts,
2715
2734
  parsed,
2716
2735
  lookup,
2717
- translator: Project5.getConfig(dirname).translator,
2718
- scriptLang: filename ? Project5.getScriptLang(filename, markoScriptLang, ts, host) : markoScriptLang,
2719
- runtimeTypesCode: Project5.getTypeLibs(tsProject.rootDir, ts, host)?.markoTypesCode
2736
+ translator: Project6.getConfig(dirname).translator,
2737
+ scriptLang: filename ? Project6.getScriptLang(filename, markoScriptLang, ts, host) : markoScriptLang,
2738
+ runtimeTypesCode: Project6.getTypeLibs(tsProject.rootDir, ts, host)?.markoTypesCode
2720
2739
  });
2721
2740
  });
2722
2741
  }
@@ -2727,9 +2746,9 @@ function getInsertModuleStatementOffset(parsed) {
2727
2746
  let lastImport;
2728
2747
  for (const node of program.static) {
2729
2748
  switch (node.type) {
2730
- case NodeType9.Export:
2749
+ case NodeType10.Export:
2731
2750
  return node.start;
2732
- case NodeType9.Import:
2751
+ case NodeType10.Import:
2733
2752
  lastImport = node;
2734
2753
  break;
2735
2754
  }
@@ -2769,7 +2788,7 @@ function docLocationAtTextSpan(doc, { start, length }) {
2769
2788
  function getTSConfigFile(fileName) {
2770
2789
  let configFile;
2771
2790
  const docFsDir = path8.dirname(fileName);
2772
- const cache = Project5.getCache(docFsDir);
2791
+ const cache = Project6.getCache(docFsDir);
2773
2792
  let configFileCache = cache.get(getTSConfigFile);
2774
2793
  if (configFileCache) {
2775
2794
  configFile = configFileCache.get(docFsDir);
@@ -2793,7 +2812,7 @@ function getTSProject(docFsPath) {
2793
2812
  }
2794
2813
  }
2795
2814
  const basePath = configFile && path8.dirname(configFile) || process.cwd();
2796
- const cache = Project5.getCache(configFile && basePath);
2815
+ const cache = Project6.getCache(configFile && basePath);
2797
2816
  let projectCache = cache.get(getTSProject);
2798
2817
  let cached;
2799
2818
  if (projectCache) {
@@ -3917,7 +3936,7 @@ for (const command in service.commands) {
3917
3936
  }
3918
3937
  function validateDocs() {
3919
3938
  queueDiagnostic();
3920
- Project6.clearCaches();
3939
+ Project7.clearCaches();
3921
3940
  }
3922
3941
  function queueDiagnostic() {
3923
3942
  clearTimeout(diagnosticTimeout);