@marko/language-server 0.12.11 → 0.12.12

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
@@ -674,76 +674,113 @@ ${closingTagStr}`
674
674
  }
675
675
  }
676
676
 
677
- // src/service/marko/complete/OpenTagName.ts
677
+ // src/service/marko/util/get-tag-name-completion.ts
678
678
  import path2 from "path";
679
- import { URI as URI2 } from "vscode-uri";
680
679
  import {
681
680
  CompletionItemKind as CompletionItemKind2,
681
+ CompletionItemTag,
682
682
  InsertTextFormat as InsertTextFormat2,
683
683
  MarkupKind,
684
684
  TextEdit as TextEdit2
685
685
  } from "vscode-languageserver";
686
+ import { URI as URI2 } from "vscode-uri";
687
+ var deprecated = [CompletionItemTag.Deprecated];
688
+ function getTagNameCompletion({
689
+ tag,
690
+ range,
691
+ showAutoComplete,
692
+ importer
693
+ }) {
694
+ var _a;
695
+ let label = tag.isNestedTag ? `@${tag.name}` : tag.name;
696
+ const fileForTag = tag.template || tag.renderer || tag.filePath;
697
+ const fileURIForTag = URI2.file(fileForTag).toString();
698
+ const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
699
+ const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
700
+ const isCoreTag = nodeModuleName === "marko";
701
+ const documentation = {
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:
704
+
705
+ [${importer ? path2.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
706
+ };
707
+ if (tag.description) {
708
+ documentation.value += `
709
+
710
+ ${tag.description}`;
711
+ }
712
+ const autocomplete = showAutoComplete ? (_a = tag.autocomplete) == null ? void 0 : _a[0] : void 0;
713
+ if (autocomplete) {
714
+ if (autocomplete.displayText) {
715
+ label = autocomplete.displayText;
716
+ }
717
+ if (autocomplete.description) {
718
+ documentation.value += `
719
+
720
+ ${autocomplete.description}`;
721
+ }
722
+ if (autocomplete.descriptionMoreURL) {
723
+ documentation.value += `
724
+
725
+ [More Info](${autocomplete.descriptionMoreURL})`;
726
+ }
727
+ }
728
+ return {
729
+ label,
730
+ documentation,
731
+ tags: tag.deprecated ? deprecated : void 0,
732
+ insertTextFormat: autocomplete ? InsertTextFormat2.Snippet : void 0,
733
+ kind: tag.html ? CompletionItemKind2.Property : CompletionItemKind2.Class,
734
+ textEdit: range && TextEdit2.replace(range, (autocomplete == null ? void 0 : autocomplete.snippet) || label)
735
+ };
736
+ }
737
+
738
+ // src/service/marko/complete/OpenTagName.ts
686
739
  function OpenTagName({
687
740
  document,
688
741
  lookup,
689
742
  parsed,
690
743
  node
691
744
  }) {
692
- const currentTemplateFilePath = getDocFile(document);
745
+ var _a;
746
+ const importer = getDocFile(document);
693
747
  const tag = node.parent;
694
- const tagNameLocation = parsed.locationAt(node);
695
- let tags;
696
- if (tag.type === 14 /* AttrTag */) {
748
+ const range = parsed.locationAt(node);
749
+ const isAttrTag = tag.type === 14 /* AttrTag */;
750
+ const result = [];
751
+ if (isAttrTag) {
697
752
  let parentTag = tag.owner;
698
753
  while ((parentTag == null ? void 0 : parentTag.type) === 14 /* AttrTag */)
699
754
  parentTag = parentTag.owner;
700
755
  const parentTagDef = parentTag && parentTag.nameText && lookup.getTag(parentTag.nameText);
701
- tags = parentTagDef && parentTagDef.nestedTags && Object.values(parentTagDef.nestedTags) || [];
702
- } else {
703
- tags = lookup.getTagsSorted().filter((it) => !it.isNestedTag);
704
- }
705
- return tags.filter((it) => !it.deprecated).filter((it) => it.name !== "*").filter((it) => /^[^_]/.test(it.name) || !/\/node_modules\//.test(it.filePath)).map((it) => {
706
- let label = it.isNestedTag ? `@${it.name}` : it.name;
707
- const fileForTag = it.template || it.renderer || it.filePath;
708
- const fileURIForTag = URI2.file(fileForTag).toString();
709
- const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
710
- const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
711
- const isCoreTag = nodeModuleName === "marko";
712
- const documentation = {
713
- kind: MarkupKind.Markdown,
714
- value: it.html ? `Built in [<${it.name}>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${it.name}) HTML tag.` : nodeModuleName ? isCoreTag ? `Core Marko [<${it.name}>](${fileURIForTag}) tag.` : `Custom Marko tag discovered from the ["${nodeModuleName}"](${fileURIForTag}) npm package.` : `Custom Marko tag discovered from:
715
-
716
- [${currentTemplateFilePath ? path2.relative(currentTemplateFilePath, fileForTag) : currentTemplateFilePath}](${fileURIForTag})`
717
- };
718
- if (it.description) {
719
- documentation.value += `
720
-
721
- ${it.description}`;
722
- }
723
- const autocomplete = it.autocomplete && it.autocomplete[0];
724
- if (autocomplete) {
725
- if (autocomplete.displayText) {
726
- label = autocomplete.displayText;
727
- }
728
- if (autocomplete.description) {
729
- documentation.value += `
730
-
731
- ${autocomplete.description}`;
756
+ if (parentTagDef) {
757
+ const { nestedTags } = parentTagDef;
758
+ for (const key in nestedTags) {
759
+ if (key !== "*") {
760
+ const tag2 = nestedTags[key];
761
+ result.push(getTagNameCompletion({
762
+ tag: tag2,
763
+ range,
764
+ importer,
765
+ showAutoComplete: true
766
+ }));
767
+ }
732
768
  }
733
- if (autocomplete.descriptionMoreURL) {
734
- documentation.value += `
735
-
736
- [More Info](${autocomplete.descriptionMoreURL})`;
769
+ }
770
+ } else {
771
+ const skipStatements = !(tag.concise && tag.parent.type === 0 /* Program */);
772
+ for (const tag2 of lookup.getTagsSorted()) {
773
+ if (!(tag2.name === "*" || tag2.isNestedTag || skipStatements && ((_a = tag2.parseOptions) == null ? void 0 : _a.statement) || tag2.name[0] === "_" && /^@?marko[/-]|[\\/]node_modules[\\/]/.test(tag2.filePath))) {
774
+ result.push(getTagNameCompletion({
775
+ tag: tag2,
776
+ range,
777
+ importer,
778
+ showAutoComplete: true
779
+ }));
737
780
  }
738
781
  }
739
- return {
740
- label,
741
- documentation,
742
- kind: CompletionItemKind2.Class,
743
- insertTextFormat: InsertTextFormat2.Snippet,
744
- textEdit: TextEdit2.replace(tagNameLocation, autocomplete && autocomplete.snippet || label)
745
- };
746
- });
782
+ }
783
+ return result;
747
784
  }
748
785
 
749
786
  // src/service/marko/complete/AttrName.ts
@@ -991,12 +1028,52 @@ async function AttrValue({
991
1028
  }
992
1029
  }
993
1030
 
1031
+ // src/service/marko/complete/Statement.ts
1032
+ import { TextEdit as TextEdit5 } from "vscode-languageserver";
1033
+ var importTagReg = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1034
+ function Statement({
1035
+ code,
1036
+ node,
1037
+ parsed,
1038
+ lookup,
1039
+ document
1040
+ }) {
1041
+ var _a;
1042
+ if (code[node.start] === "i") {
1043
+ importTagReg.lastIndex = 0;
1044
+ const value = parsed.read(node);
1045
+ const match = importTagReg.exec(value);
1046
+ if (match) {
1047
+ const importer = getDocFile(document);
1048
+ const [{ length }] = match;
1049
+ const range = parsed.locationAt({
1050
+ start: node.start + match.index + 1,
1051
+ end: node.start + match.index + length - 1
1052
+ });
1053
+ const result = [];
1054
+ for (const tag of lookup.getTagsSorted()) {
1055
+ if ((tag.template || tag.renderer) && !(tag.html || tag.parser || tag.translator || tag.isNestedTag || tag.name === "*" || ((_a = tag.parseOptions) == null ? void 0 : _a.statement) || /^@?marko[/-]/.test(tag.taglibId) || tag.name[0] === "_" && /[\\/]node_modules[\\/]/.test(tag.filePath))) {
1056
+ const completion = getTagNameCompletion({
1057
+ tag,
1058
+ importer
1059
+ });
1060
+ completion.label = `<${completion.label}>`;
1061
+ completion.textEdit = TextEdit5.replace(range, completion.label);
1062
+ result.push(completion);
1063
+ }
1064
+ }
1065
+ return result;
1066
+ }
1067
+ }
1068
+ }
1069
+
994
1070
  // src/service/marko/complete/index.ts
995
1071
  var handlers = {
996
1072
  Tag,
997
1073
  OpenTagName,
998
1074
  AttrName,
999
- AttrValue
1075
+ AttrValue,
1076
+ Statement
1000
1077
  };
1001
1078
  var doComplete = async (doc, params) => {
1002
1079
  var _a;
@@ -1176,7 +1253,7 @@ var findDefinition = async (doc, params) => {
1176
1253
  // src/service/marko/document-links/extract.ts
1177
1254
  import { DocumentLink } from "vscode-languageserver";
1178
1255
  import { URI as URI6 } from "vscode-uri";
1179
- var importTagReg = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1256
+ var importTagReg2 = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1180
1257
  function extractDocumentLinks(doc, parsed, lookup) {
1181
1258
  if (URI6.parse(doc.uri).scheme === "untitled") {
1182
1259
  return [];
@@ -1208,9 +1285,9 @@ function extractDocumentLinks(doc, parsed, lookup) {
1208
1285
  };
1209
1286
  for (const item of program.static) {
1210
1287
  if (item.type === 20 /* Statement */ && code[item.start] === "i") {
1211
- importTagReg.lastIndex = 0;
1288
+ importTagReg2.lastIndex = 0;
1212
1289
  const value = parsed.read(item);
1213
- const match = importTagReg.exec(value);
1290
+ const match = importTagReg2.exec(value);
1214
1291
  if (match) {
1215
1292
  const [{ length }, , tagName] = match;
1216
1293
  const tagDef = lookup.getTag(tagName);
@@ -1243,7 +1320,7 @@ var findDocumentLinks = async (doc) => {
1243
1320
  };
1244
1321
 
1245
1322
  // src/service/marko/format.ts
1246
- import { Range as Range7, TextEdit as TextEdit5 } from "vscode-languageserver";
1323
+ import { Range as Range7, TextEdit as TextEdit6 } from "vscode-languageserver";
1247
1324
  import { URI as URI7 } from "vscode-uri";
1248
1325
  import * as prettier from "prettier";
1249
1326
  import * as markoPrettier from "prettier-plugin-marko";
@@ -1264,7 +1341,7 @@ var format2 = async (doc, params, cancel) => {
1264
1341
  if (cancel.isCancellationRequested)
1265
1342
  return;
1266
1343
  return [
1267
- TextEdit5.replace(Range7.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1344
+ TextEdit6.replace(Range7.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1268
1345
  ];
1269
1346
  } catch (e) {
1270
1347
  displayError(e);
@@ -1817,51 +1894,47 @@ var service = {
1817
1894
  }));
1818
1895
  },
1819
1896
  async doComplete(doc, params, cancel) {
1820
- const result = CompletionList3.create([], false);
1897
+ let items;
1898
+ let isIncomplete = false;
1821
1899
  try {
1822
- const requests = plugins.map((plugin) => {
1900
+ for (const pending of plugins.map((plugin) => {
1823
1901
  var _a;
1824
1902
  return (_a = plugin.doComplete) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1825
- });
1826
- for (const pending of requests) {
1903
+ })) {
1827
1904
  const cur = await pending;
1828
1905
  if (cancel.isCancellationRequested)
1829
1906
  return;
1830
1907
  if (cur) {
1831
- let items;
1908
+ let curItems;
1832
1909
  if (Array.isArray(cur)) {
1833
- items = cur;
1910
+ curItems = cur;
1834
1911
  } else {
1835
- items = cur.items;
1836
- result.isIncomplete || (result.isIncomplete = cur.isIncomplete);
1912
+ curItems = cur.items;
1913
+ isIncomplete || (isIncomplete = cur.isIncomplete);
1837
1914
  }
1838
- result.items.push(...items);
1915
+ items = items ? items.concat(curItems) : curItems;
1839
1916
  }
1840
1917
  }
1841
1918
  } catch (err) {
1842
- result.isIncomplete = true;
1919
+ isIncomplete = true;
1843
1920
  displayError(err);
1844
1921
  }
1845
- return result;
1922
+ if (items) {
1923
+ return CompletionList3.create(items, isIncomplete);
1924
+ }
1846
1925
  },
1847
1926
  async findDefinition(doc, params, cancel) {
1848
- const result = [];
1927
+ let result;
1849
1928
  try {
1850
- const requests = plugins.map((plugin) => {
1929
+ for (const pending of plugins.map((plugin) => {
1851
1930
  var _a;
1852
1931
  return (_a = plugin.findDefinition) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1853
- });
1854
- for (const pending of requests) {
1932
+ })) {
1855
1933
  const cur = await pending;
1856
1934
  if (cancel.isCancellationRequested)
1857
1935
  return;
1858
- if (cur) {
1859
- if (Array.isArray(cur)) {
1860
- result.push(...cur);
1861
- } else {
1862
- result.push(cur);
1863
- }
1864
- }
1936
+ if (cur)
1937
+ result = (result || []).concat(cur);
1865
1938
  }
1866
1939
  } catch (err) {
1867
1940
  displayError(err);
@@ -1871,21 +1944,15 @@ var service = {
1871
1944
  async findReferences(doc, params, cancel) {
1872
1945
  let result;
1873
1946
  try {
1874
- const requests = plugins.map((plugin) => {
1947
+ for (const pending of plugins.map((plugin) => {
1875
1948
  var _a;
1876
1949
  return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1877
- });
1878
- for (const pending of requests) {
1950
+ })) {
1879
1951
  const cur = await pending;
1880
1952
  if (cancel.isCancellationRequested)
1881
1953
  return;
1882
- if (cur) {
1883
- if (result) {
1884
- result.push(...cur);
1885
- } else {
1886
- result = cur;
1887
- }
1888
- }
1954
+ if (cur)
1955
+ result = result ? result.concat(cur) : cur;
1889
1956
  }
1890
1957
  } catch (err) {
1891
1958
  displayError(err);
@@ -1895,21 +1962,15 @@ var service = {
1895
1962
  async findDocumentLinks(doc, params, cancel) {
1896
1963
  let result;
1897
1964
  try {
1898
- const requests = plugins.map((plugin) => {
1965
+ for (const pending of plugins.map((plugin) => {
1899
1966
  var _a;
1900
1967
  return (_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1901
- });
1902
- for (const pending of requests) {
1968
+ })) {
1903
1969
  const cur = await pending;
1904
1970
  if (cancel.isCancellationRequested)
1905
1971
  return;
1906
- if (cur) {
1907
- if (result) {
1908
- result.push(...cur);
1909
- } else {
1910
- result = cur;
1911
- }
1912
- }
1972
+ if (cur)
1973
+ result = result ? result.concat(cur) : cur;
1913
1974
  }
1914
1975
  } catch (err) {
1915
1976
  displayError(err);
@@ -1919,21 +1980,15 @@ var service = {
1919
1980
  async findDocumentHighlights(doc, params, cancel) {
1920
1981
  let result;
1921
1982
  try {
1922
- const requests = plugins.map((plugin) => {
1983
+ for (const pending of plugins.map((plugin) => {
1923
1984
  var _a;
1924
1985
  return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1925
- });
1926
- for (const pending of requests) {
1986
+ })) {
1927
1987
  const cur = await pending;
1928
1988
  if (cancel.isCancellationRequested)
1929
1989
  return;
1930
- if (cur) {
1931
- if (result) {
1932
- result.push(...cur);
1933
- } else {
1934
- result = cur;
1935
- }
1936
- }
1990
+ if (cur)
1991
+ result = result ? result.concat(cur) : cur;
1937
1992
  }
1938
1993
  } catch (err) {
1939
1994
  displayError(err);
@@ -1943,21 +1998,15 @@ var service = {
1943
1998
  async findDocumentColors(doc, params, cancel) {
1944
1999
  let result;
1945
2000
  try {
1946
- const requests = plugins.map((plugin) => {
2001
+ for (const pending of plugins.map((plugin) => {
1947
2002
  var _a;
1948
2003
  return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1949
- });
1950
- for (const pending of requests) {
2004
+ })) {
1951
2005
  const cur = await pending;
1952
2006
  if (cancel.isCancellationRequested)
1953
2007
  return;
1954
- if (cur) {
1955
- if (result) {
1956
- result.push(...cur);
1957
- } else {
1958
- result = cur;
1959
- }
1960
- }
2008
+ if (cur)
2009
+ result = result ? result.concat(cur) : cur;
1961
2010
  }
1962
2011
  } catch (err) {
1963
2012
  displayError(err);
@@ -1967,21 +2016,15 @@ var service = {
1967
2016
  async getColorPresentations(doc, params, cancel) {
1968
2017
  let result;
1969
2018
  try {
1970
- const requests = plugins.map((plugin) => {
2019
+ for (const pending of plugins.map((plugin) => {
1971
2020
  var _a;
1972
2021
  return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1973
- });
1974
- for (const pending of requests) {
2022
+ })) {
1975
2023
  const cur = await pending;
1976
2024
  if (cancel.isCancellationRequested)
1977
2025
  return;
1978
- if (cur) {
1979
- if (result) {
1980
- result.push(...cur);
1981
- } else {
1982
- result = cur;
1983
- }
1984
- }
2026
+ if (cur)
2027
+ result = result ? result.concat(cur) : cur;
1985
2028
  }
1986
2029
  } catch (err) {
1987
2030
  displayError(err);
@@ -2007,41 +2050,32 @@ var service = {
2007
2050
  let changeAnnotations;
2008
2051
  let documentChanges;
2009
2052
  try {
2010
- const requests = plugins.map((plugin) => {
2053
+ for (const pending of plugins.map((plugin) => {
2011
2054
  var _a;
2012
2055
  return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
2013
- });
2014
- for (const pending of requests) {
2056
+ })) {
2015
2057
  const cur = await pending;
2016
2058
  if (cancel.isCancellationRequested)
2017
2059
  return;
2018
2060
  if (cur) {
2019
2061
  if (cur.changes) {
2020
2062
  if (changes) {
2063
+ changes = { ...changes };
2021
2064
  for (const uri in cur.changes) {
2022
- if (changes[uri]) {
2023
- changes[uri].push(...cur.changes[uri]);
2024
- } else {
2025
- changes[uri] = cur.changes[uri];
2026
- }
2065
+ changes[uri] = changes[uri] ? changes[uri].concat(cur.changes[uri]) : cur.changes[uri];
2027
2066
  }
2028
2067
  } else {
2029
2068
  changes = cur.changes;
2030
2069
  }
2031
2070
  }
2032
2071
  if (cur.changeAnnotations) {
2033
- if (changeAnnotations) {
2034
- Object.assign(changeAnnotations, cur.changeAnnotations);
2035
- } else {
2036
- changeAnnotations = cur.changeAnnotations;
2037
- }
2072
+ changeAnnotations = changeAnnotations ? {
2073
+ ...changeAnnotations,
2074
+ ...cur.changeAnnotations
2075
+ } : cur.changeAnnotations;
2038
2076
  }
2039
2077
  if (cur.documentChanges) {
2040
- if (documentChanges) {
2041
- documentChanges.push(...cur.documentChanges);
2042
- } else {
2043
- documentChanges = cur.documentChanges;
2044
- }
2078
+ documentChanges = documentChanges ? documentChanges.concat(cur.documentChanges) : cur.documentChanges;
2045
2079
  }
2046
2080
  }
2047
2081
  }
@@ -2057,19 +2091,17 @@ var service = {
2057
2091
  }
2058
2092
  },
2059
2093
  async doCodeActions(doc, params, cancel) {
2060
- const result = [];
2094
+ let result;
2061
2095
  try {
2062
- const requests = plugins.map((plugin) => {
2096
+ for (const pending of plugins.map((plugin) => {
2063
2097
  var _a;
2064
2098
  return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
2065
- });
2066
- for (const pending of requests) {
2099
+ })) {
2067
2100
  const cur = await pending;
2068
2101
  if (cancel.isCancellationRequested)
2069
2102
  return;
2070
- if (cur) {
2071
- result.push(...cur);
2072
- }
2103
+ if (cur)
2104
+ result = result ? result.concat(cur) : cur;
2073
2105
  }
2074
2106
  } catch (err) {
2075
2107
  displayError(err);
@@ -2077,16 +2109,15 @@ var service = {
2077
2109
  return result;
2078
2110
  },
2079
2111
  async doValidate(doc) {
2080
- const result = [];
2112
+ let result;
2081
2113
  try {
2082
- const requests = plugins.map((plugin) => {
2114
+ for (const pending of plugins.map((plugin) => {
2083
2115
  var _a;
2084
2116
  return (_a = plugin.doValidate) == null ? void 0 : _a.call(plugin, doc);
2085
- });
2086
- for (const pending of requests) {
2117
+ })) {
2087
2118
  const cur = await pending;
2088
2119
  if (cur)
2089
- result.push(...cur);
2120
+ result = result ? result.concat(cur) : cur;
2090
2121
  }
2091
2122
  } catch (err) {
2092
2123
  displayError(err);