@marko/language-server 0.12.10 → 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.js CHANGED
@@ -575,7 +575,7 @@ function loadCompilerInfo(dir) {
575
575
  const rootDir = import_lasso_package_root.default.getRootDir(dir);
576
576
  const pkgPath = rootDir && import_resolve_from.default.silent(rootDir, "@marko/compiler/package.json");
577
577
  const pkg = pkgPath && require(pkgPath);
578
- const cache3 = /* @__PURE__ */ new Map();
578
+ const cache4 = /* @__PURE__ */ new Map();
579
579
  let translator = builtinTranslator;
580
580
  let compiler = builtinCompiler;
581
581
  if (pkg && /^5\./.test(pkg.version)) {
@@ -592,16 +592,16 @@ function loadCompilerInfo(dir) {
592
592
  }
593
593
  }
594
594
  return {
595
- cache: cache3,
595
+ cache: cache4,
596
596
  get lookup() {
597
- let lookup = cache3.get(lookupKey);
597
+ let lookup = cache4.get(lookupKey);
598
598
  if (lookup === void 0) {
599
599
  try {
600
600
  lookup = compiler.taglib.buildLookup(dir, translator);
601
601
  } catch {
602
602
  lookup = builtinInfo.lookup;
603
603
  }
604
- cache3.set(lookupKey, lookup);
604
+ cache4.set(lookupKey, lookup);
605
605
  }
606
606
  return lookup;
607
607
  },
@@ -625,10 +625,10 @@ function display(type, data) {
625
625
  }
626
626
 
627
627
  // src/service/index.ts
628
- var import_vscode_languageserver13 = require("vscode-languageserver");
628
+ var import_vscode_languageserver15 = require("vscode-languageserver");
629
629
 
630
630
  // src/service/marko/complete/index.ts
631
- var import_vscode_languageserver5 = require("vscode-languageserver");
631
+ var import_vscode_languageserver6 = require("vscode-languageserver");
632
632
 
633
633
  // src/service/marko/complete/Tag.ts
634
634
  var import_vscode_languageserver = require("vscode-languageserver");
@@ -670,71 +670,107 @@ ${closingTagStr}`
670
670
  }
671
671
  }
672
672
 
673
- // src/service/marko/complete/OpenTagName.ts
673
+ // src/service/marko/util/get-tag-name-completion.ts
674
674
  var import_path2 = __toESM(require("path"));
675
- var import_vscode_uri2 = require("vscode-uri");
676
675
  var import_vscode_languageserver2 = require("vscode-languageserver");
676
+ var import_vscode_uri2 = require("vscode-uri");
677
+ var deprecated = [import_vscode_languageserver2.CompletionItemTag.Deprecated];
678
+ function getTagNameCompletion({
679
+ tag,
680
+ range,
681
+ showAutoComplete,
682
+ importer
683
+ }) {
684
+ var _a;
685
+ let label = tag.isNestedTag ? `@${tag.name}` : tag.name;
686
+ const fileForTag = tag.template || tag.renderer || tag.filePath;
687
+ const fileURIForTag = import_vscode_uri2.URI.file(fileForTag).toString();
688
+ const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
689
+ const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
690
+ const isCoreTag = /^@?marko[/-]/.test(tag.taglibId) || nodeModuleName === "marko";
691
+ const documentation = {
692
+ kind: import_vscode_languageserver2.MarkupKind.Markdown,
693
+ value: tag.html ? `Built in [<${tag.name}>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${tag.name}) HTML tag.` : isCoreTag ? `Core Marko <${tag.name}> tag.` : nodeModuleName ? `Custom Marko tag discovered from the ["${nodeModuleName}"](${fileURIForTag}) npm package.` : `Custom Marko tag discovered from:
694
+
695
+ [${importer ? import_path2.default.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
696
+ };
697
+ if (tag.description) {
698
+ documentation.value += `
699
+
700
+ ${tag.description}`;
701
+ }
702
+ const autocomplete = showAutoComplete ? (_a = tag.autocomplete) == null ? void 0 : _a[0] : void 0;
703
+ if (autocomplete) {
704
+ if (autocomplete.displayText) {
705
+ label = autocomplete.displayText;
706
+ }
707
+ if (autocomplete.description) {
708
+ documentation.value += `
709
+
710
+ ${autocomplete.description}`;
711
+ }
712
+ if (autocomplete.descriptionMoreURL) {
713
+ documentation.value += `
714
+
715
+ [More Info](${autocomplete.descriptionMoreURL})`;
716
+ }
717
+ }
718
+ return {
719
+ label,
720
+ documentation,
721
+ tags: tag.deprecated ? deprecated : void 0,
722
+ insertTextFormat: autocomplete ? import_vscode_languageserver2.InsertTextFormat.Snippet : void 0,
723
+ kind: tag.html ? import_vscode_languageserver2.CompletionItemKind.Property : import_vscode_languageserver2.CompletionItemKind.Class,
724
+ textEdit: range && import_vscode_languageserver2.TextEdit.replace(range, (autocomplete == null ? void 0 : autocomplete.snippet) || label)
725
+ };
726
+ }
727
+
728
+ // src/service/marko/complete/OpenTagName.ts
677
729
  function OpenTagName({
678
730
  document,
679
731
  lookup,
680
732
  parsed,
681
733
  node
682
734
  }) {
683
- const currentTemplateFilePath = getDocFile(document);
735
+ var _a;
736
+ const importer = getDocFile(document);
684
737
  const tag = node.parent;
685
- const tagNameLocation = parsed.locationAt(node);
686
- let tags;
687
- if (tag.type === 14 /* AttrTag */) {
738
+ const range = parsed.locationAt(node);
739
+ const isAttrTag = tag.type === 14 /* AttrTag */;
740
+ const result = [];
741
+ if (isAttrTag) {
688
742
  let parentTag = tag.owner;
689
743
  while ((parentTag == null ? void 0 : parentTag.type) === 14 /* AttrTag */)
690
744
  parentTag = parentTag.owner;
691
745
  const parentTagDef = parentTag && parentTag.nameText && lookup.getTag(parentTag.nameText);
692
- tags = parentTagDef && parentTagDef.nestedTags && Object.values(parentTagDef.nestedTags) || [];
693
- } else {
694
- tags = lookup.getTagsSorted().filter((it) => !it.isNestedTag);
695
- }
696
- return tags.filter((it) => !it.deprecated).filter((it) => it.name !== "*").filter((it) => /^[^_]/.test(it.name) || !/\/node_modules\//.test(it.filePath)).map((it) => {
697
- let label = it.isNestedTag ? `@${it.name}` : it.name;
698
- const fileForTag = it.template || it.renderer || it.filePath;
699
- const fileURIForTag = import_vscode_uri2.URI.file(fileForTag).toString();
700
- const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
701
- const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
702
- const isCoreTag = nodeModuleName === "marko";
703
- const documentation = {
704
- kind: import_vscode_languageserver2.MarkupKind.Markdown,
705
- 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:
706
-
707
- [${currentTemplateFilePath ? import_path2.default.relative(currentTemplateFilePath, fileForTag) : currentTemplateFilePath}](${fileURIForTag})`
708
- };
709
- if (it.description) {
710
- documentation.value += `
711
-
712
- ${it.description}`;
713
- }
714
- const autocomplete = it.autocomplete && it.autocomplete[0];
715
- if (autocomplete) {
716
- if (autocomplete.displayText) {
717
- label = autocomplete.displayText;
718
- }
719
- if (autocomplete.description) {
720
- documentation.value += `
721
-
722
- ${autocomplete.description}`;
746
+ if (parentTagDef) {
747
+ const { nestedTags } = parentTagDef;
748
+ for (const key in nestedTags) {
749
+ if (key !== "*") {
750
+ const tag2 = nestedTags[key];
751
+ result.push(getTagNameCompletion({
752
+ tag: tag2,
753
+ range,
754
+ importer,
755
+ showAutoComplete: true
756
+ }));
757
+ }
723
758
  }
724
- if (autocomplete.descriptionMoreURL) {
725
- documentation.value += `
726
-
727
- [More Info](${autocomplete.descriptionMoreURL})`;
759
+ }
760
+ } else {
761
+ const skipStatements = !(tag.concise && tag.parent.type === 0 /* Program */);
762
+ for (const tag2 of lookup.getTagsSorted()) {
763
+ if (!(tag2.name === "*" || tag2.isNestedTag || skipStatements && ((_a = tag2.parseOptions) == null ? void 0 : _a.statement) || tag2.name[0] === "_" && /^@?marko[/-]|[\\/]node_modules[\\/]/.test(tag2.filePath))) {
764
+ result.push(getTagNameCompletion({
765
+ tag: tag2,
766
+ range,
767
+ importer,
768
+ showAutoComplete: true
769
+ }));
728
770
  }
729
771
  }
730
- return {
731
- label,
732
- documentation,
733
- kind: import_vscode_languageserver2.CompletionItemKind.Class,
734
- insertTextFormat: import_vscode_languageserver2.InsertTextFormat.Snippet,
735
- textEdit: import_vscode_languageserver2.TextEdit.replace(tagNameLocation, autocomplete && autocomplete.snippet || label)
736
- };
737
- });
772
+ }
773
+ return result;
738
774
  }
739
775
 
740
776
  // src/service/marko/complete/AttrName.ts
@@ -843,7 +879,7 @@ function AttrName({
843
879
  }
844
880
 
845
881
  // src/service/marko/complete/AttrValue.ts
846
- var import_path4 = __toESM(require("path"));
882
+ var import_path3 = __toESM(require("path"));
847
883
  var import_vscode_languageserver4 = require("vscode-languageserver");
848
884
 
849
885
  // src/service/marko/util/is-document-link-attr.ts
@@ -872,20 +908,20 @@ function isDocumentLinkAttr(doc, tag, attr) {
872
908
  }
873
909
 
874
910
  // src/utils/file-system.ts
875
- var import_path3 = __toESM(require("path"));
876
911
  var import_promises = __toESM(require("fs/promises"));
877
912
  var import_vscode_css_languageservice = require("vscode-css-languageservice");
913
+ var import_url = require("url");
878
914
  var file_system_default = {
879
915
  stat,
880
916
  readDirectory
881
917
  };
882
- async function stat(fileName) {
883
- const stat2 = await import_promises.default.stat(fileName).catch(() => null);
918
+ async function stat(uri) {
884
919
  let type = import_vscode_css_languageservice.FileType.Unknown;
885
- let ctime = 0;
886
- let mtime = 0;
887
- let size = 0;
888
- if (stat2) {
920
+ let ctime = -1;
921
+ let mtime = -1;
922
+ let size = -1;
923
+ try {
924
+ const stat2 = await import_promises.default.stat((0, import_url.fileURLToPath)(uri));
889
925
  if (stat2.isDirectory())
890
926
  type = import_vscode_css_languageservice.FileType.Directory;
891
927
  else if (stat2.isFile())
@@ -893,6 +929,7 @@ async function stat(fileName) {
893
929
  ctime = stat2.ctimeMs;
894
930
  mtime = stat2.mtimeMs;
895
931
  size = stat2.size;
932
+ } catch {
896
933
  }
897
934
  return {
898
935
  type,
@@ -901,20 +938,22 @@ async function stat(fileName) {
901
938
  size
902
939
  };
903
940
  }
904
- async function readDirectory(dir) {
905
- return (await Promise.all((await import_promises.default.readdir(dir).catch(() => [])).map(async (entry) => [entry, (await stat(import_path3.default.join(dir, entry))).type]))).filter(([, type]) => type !== import_vscode_css_languageservice.FileType.Unknown);
941
+ async function readDirectory(uri) {
942
+ try {
943
+ const entries = await import_promises.default.readdir((0, import_url.fileURLToPath)(uri));
944
+ const base = uri.at(-1) === "/" ? uri : `${uri}/`;
945
+ return (await Promise.all(entries.map(async (entry) => [entry, (await stat(new URL(entry, base).toString())).type]))).filter(([, type]) => type !== import_vscode_css_languageservice.FileType.Unknown);
946
+ } catch {
947
+ return [];
948
+ }
906
949
  }
907
950
 
908
951
  // src/utils/resolve-url.ts
909
952
  function resolveUrl(to, base) {
910
953
  try {
911
- const baseUrl = new URL(base, "file://");
912
- const resolved = new URL(to, baseUrl);
913
- const { origin, protocol } = baseUrl;
914
- if (resolved.origin === origin && resolved.protocol === protocol) {
915
- return resolved.pathname + resolved.search + resolved.hash;
916
- }
917
- return resolved.toString();
954
+ const url = new URL(to, base);
955
+ if (url.protocol === "file:")
956
+ return url.toString();
918
957
  } catch {
919
958
  return void 0;
920
959
  }
@@ -939,28 +978,29 @@ async function AttrValue({
939
978
  start,
940
979
  end
941
980
  });
942
- let segmentStart = rawValue.lastIndexOf("/", relativeOffset);
981
+ const segmentStart = rawValue.lastIndexOf("/", relativeOffset);
943
982
  if (segmentStart === -1)
944
- segmentStart = relativeOffset;
945
- const resolveRequest = rawValue.slice(0, segmentStart) || ".";
946
- const dir = resolveUrl(resolveRequest, document.uri);
947
- if ((dir == null ? void 0 : dir[0]) === "/") {
983
+ return;
984
+ const req = rawValue.slice(0, segmentStart);
985
+ const uri = resolveUrl(req, document.uri);
986
+ if (uri) {
948
987
  const result = [];
949
- const curDir = resolveRequest === "." ? dir : resolveUrl(".", document.uri);
950
- const curFile = curDir === dir ? import_path4.default.basename(document.uri) : void 0;
988
+ const curFile = req === "." ? import_path3.default.basename(document.uri) : void 0;
951
989
  const replaceRange = import_vscode_languageserver4.Range.create(document.positionAt(start + segmentStart + 1), document.positionAt(start + rawValue.length));
952
- for (const [entry, type] of await file_system_default.readDirectory(dir)) {
990
+ for (const [entry, type] of await file_system_default.readDirectory(uri)) {
953
991
  if (entry[0] !== "." && entry !== curFile) {
954
- const isDir = type === import_vscode_css_languageservice.FileType.Directory;
955
- const label = isDir ? `${entry}/` : entry;
956
- result.push({
957
- label,
958
- kind: isDir ? import_vscode_languageserver4.CompletionItemKind.Folder : import_vscode_languageserver4.CompletionItemKind.File,
959
- textEdit: import_vscode_languageserver4.TextEdit.replace(replaceRange, label),
960
- command: isDir ? {
992
+ result.push(type === import_vscode_css_languageservice.FileType.Directory ? {
993
+ label: `${entry}/`,
994
+ kind: import_vscode_languageserver4.CompletionItemKind.Folder,
995
+ textEdit: import_vscode_languageserver4.TextEdit.replace(replaceRange, `${entry}/`),
996
+ command: {
961
997
  title: "Suggest",
962
998
  command: "editor.action.triggerSuggest"
963
- } : void 0
999
+ }
1000
+ } : {
1001
+ label: entry,
1002
+ kind: import_vscode_languageserver4.CompletionItemKind.File,
1003
+ textEdit: import_vscode_languageserver4.TextEdit.replace(replaceRange, entry)
964
1004
  });
965
1005
  }
966
1006
  }
@@ -969,19 +1009,59 @@ async function AttrValue({
969
1009
  }
970
1010
  }
971
1011
 
1012
+ // src/service/marko/complete/Statement.ts
1013
+ var import_vscode_languageserver5 = require("vscode-languageserver");
1014
+ var importTagReg = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1015
+ function Statement({
1016
+ code,
1017
+ node,
1018
+ parsed,
1019
+ lookup,
1020
+ document
1021
+ }) {
1022
+ var _a;
1023
+ if (code[node.start] === "i") {
1024
+ importTagReg.lastIndex = 0;
1025
+ const value = parsed.read(node);
1026
+ const match = importTagReg.exec(value);
1027
+ if (match) {
1028
+ const importer = getDocFile(document);
1029
+ const [{ length }] = match;
1030
+ const range = parsed.locationAt({
1031
+ start: node.start + match.index + 1,
1032
+ end: node.start + match.index + length - 1
1033
+ });
1034
+ const result = [];
1035
+ for (const tag of lookup.getTagsSorted()) {
1036
+ 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))) {
1037
+ const completion = getTagNameCompletion({
1038
+ tag,
1039
+ importer
1040
+ });
1041
+ completion.label = `<${completion.label}>`;
1042
+ completion.textEdit = import_vscode_languageserver5.TextEdit.replace(range, completion.label);
1043
+ result.push(completion);
1044
+ }
1045
+ }
1046
+ return result;
1047
+ }
1048
+ }
1049
+ }
1050
+
972
1051
  // src/service/marko/complete/index.ts
973
1052
  var handlers = {
974
1053
  Tag,
975
1054
  OpenTagName,
976
1055
  AttrName,
977
- AttrValue
1056
+ AttrValue,
1057
+ Statement
978
1058
  };
979
1059
  var doComplete = async (doc, params) => {
980
1060
  var _a;
981
1061
  const parsed = parse2(doc);
982
1062
  const offset = doc.offsetAt(params.position);
983
1063
  const node = parsed.nodeAt(offset);
984
- return import_vscode_languageserver5.CompletionList.create(await ((_a = handlers[NodeType[node.type]]) == null ? void 0 : _a.call(handlers, {
1064
+ return import_vscode_languageserver6.CompletionList.create(await ((_a = handlers[NodeType[node.type]]) == null ? void 0 : _a.call(handlers, {
985
1065
  document: doc,
986
1066
  params,
987
1067
  parsed,
@@ -993,15 +1073,15 @@ var doComplete = async (doc, params) => {
993
1073
  };
994
1074
 
995
1075
  // src/service/marko/validate.ts
996
- var import_vscode_languageserver6 = require("vscode-languageserver");
1076
+ var import_vscode_languageserver7 = require("vscode-languageserver");
997
1077
  var markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
998
1078
  var doValidate = (doc) => {
999
1079
  const fsPath = getDocFile(doc);
1000
1080
  const diagnostics = [];
1001
- const { compiler, translator, cache: cache3 } = getCompilerInfo(doc);
1081
+ const { compiler, translator, cache: cache4 } = getCompilerInfo(doc);
1002
1082
  try {
1003
1083
  compiler.compileSync(doc.getText(), fsPath || "untitled.marko", {
1004
- cache: cache3,
1084
+ cache: cache4,
1005
1085
  translator,
1006
1086
  code: false,
1007
1087
  output: "source",
@@ -1013,16 +1093,72 @@ var doValidate = (doc) => {
1013
1093
  const [, fileName, rawLine, rawCol, msg] = match;
1014
1094
  const line = (parseInt(rawLine, 10) || 1) - 1;
1015
1095
  const col = (parseInt(rawCol, 10) || 1) - 1;
1016
- diagnostics.push(import_vscode_languageserver6.Diagnostic.create(import_vscode_languageserver6.Range.create(line, col, line, col), msg, import_vscode_languageserver6.DiagnosticSeverity.Error, void 0, fileName));
1096
+ diagnostics.push(import_vscode_languageserver7.Diagnostic.create(import_vscode_languageserver7.Range.create(line, col, line, col), msg, import_vscode_languageserver7.DiagnosticSeverity.Error, void 0, fileName));
1017
1097
  }
1018
1098
  }
1019
1099
  return diagnostics;
1020
1100
  };
1021
1101
 
1102
+ // src/utils/utils.ts
1103
+ var import_fs = __toESM(require("fs"));
1104
+ var import_vscode_uri3 = require("vscode-uri");
1105
+ var import_vscode_languageserver8 = require("vscode-languageserver");
1106
+ var import_vscode_languageserver_textdocument = require("vscode-languageserver-textdocument");
1107
+ var START_OF_FILE = import_vscode_languageserver8.Range.create(import_vscode_languageserver8.Position.create(0, 0), import_vscode_languageserver8.Position.create(0, 0));
1108
+ function createTextDocument(filename) {
1109
+ const uri = import_vscode_uri3.URI.file(filename).toString();
1110
+ const content = import_fs.default.readFileSync(filename, "utf-8");
1111
+ return import_vscode_languageserver_textdocument.TextDocument.create(uri, "plaintext", 0, content);
1112
+ }
1113
+
1114
+ // src/service/marko/hover/OpenTagName.ts
1115
+ function OpenTagName2({
1116
+ document,
1117
+ lookup,
1118
+ parsed,
1119
+ node
1120
+ }) {
1121
+ const importer = getDocFile(document);
1122
+ const tag = node.parent;
1123
+ const range = parsed.locationAt(node);
1124
+ const tagDef = tag.nameText && lookup.getTag(tag.nameText);
1125
+ if (tagDef) {
1126
+ const completion = getTagNameCompletion({
1127
+ tag: tagDef,
1128
+ range: START_OF_FILE,
1129
+ importer
1130
+ });
1131
+ return {
1132
+ range,
1133
+ contents: completion.documentation
1134
+ };
1135
+ }
1136
+ }
1137
+
1138
+ // src/service/marko/hover/index.ts
1139
+ var handlers2 = {
1140
+ OpenTagName: OpenTagName2
1141
+ };
1142
+ var doHover = async (doc, params) => {
1143
+ var _a;
1144
+ const parsed = parse2(doc);
1145
+ const offset = doc.offsetAt(params.position);
1146
+ const node = parsed.nodeAt(offset);
1147
+ return await ((_a = handlers2[NodeType[node.type]]) == null ? void 0 : _a.call(handlers2, {
1148
+ document: doc,
1149
+ params,
1150
+ parsed,
1151
+ offset,
1152
+ node,
1153
+ code: doc.getText(),
1154
+ ...getCompilerInfo(doc)
1155
+ }));
1156
+ };
1157
+
1022
1158
  // src/service/marko/definition/OpenTagName.ts
1023
- var import_path5 = __toESM(require("path"));
1159
+ var import_path4 = __toESM(require("path"));
1024
1160
  var import_vscode_uri4 = require("vscode-uri");
1025
- var import_vscode_languageserver8 = require("vscode-languageserver");
1161
+ var import_vscode_languageserver9 = require("vscode-languageserver");
1026
1162
 
1027
1163
  // src/utils/regexp-builder.ts
1028
1164
  function RegExpBuilder(strings, ...expressions) {
@@ -1048,20 +1184,8 @@ function escape(val) {
1048
1184
  return String(val).replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
1049
1185
  }
1050
1186
 
1051
- // src/utils/utils.ts
1052
- var import_fs = __toESM(require("fs"));
1053
- var import_vscode_uri3 = require("vscode-uri");
1054
- var import_vscode_languageserver7 = require("vscode-languageserver");
1055
- var import_vscode_languageserver_textdocument = require("vscode-languageserver-textdocument");
1056
- var START_OF_FILE = import_vscode_languageserver7.Range.create(import_vscode_languageserver7.Position.create(0, 0), import_vscode_languageserver7.Position.create(0, 0));
1057
- function createTextDocument(filename) {
1058
- const uri = import_vscode_uri3.URI.file(filename).toString();
1059
- const content = import_fs.default.readFileSync(filename, "utf-8");
1060
- return import_vscode_languageserver_textdocument.TextDocument.create(uri, "plaintext", 0, content);
1061
- }
1062
-
1063
1187
  // src/service/marko/definition/OpenTagName.ts
1064
- function OpenTagName2({
1188
+ function OpenTagName3({
1065
1189
  lookup,
1066
1190
  parsed,
1067
1191
  node
@@ -1081,24 +1205,24 @@ function OpenTagName2({
1081
1205
  return;
1082
1206
  }
1083
1207
  const tagEntryFile = tagDef.template || tagDef.renderer || tagDef.filePath;
1084
- if (!import_path5.default.isAbsolute(tagEntryFile)) {
1208
+ if (!import_path4.default.isAbsolute(tagEntryFile)) {
1085
1209
  return;
1086
1210
  }
1087
1211
  if (/\/marko(?:-tag)?\.json$/.test(tagEntryFile)) {
1088
1212
  const tagDefDoc = createTextDocument(tagEntryFile);
1089
1213
  const match = RegExpBuilder`/"(?:<${tag.nameText}>|${tag.nameText})"\s*:\s*[^\r\n,]+/g`.exec(tagDefDoc.getText());
1090
1214
  if (match && match.index) {
1091
- range = import_vscode_languageserver8.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
1215
+ range = import_vscode_languageserver9.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
1092
1216
  }
1093
1217
  }
1094
1218
  return [
1095
- import_vscode_languageserver8.LocationLink.create(import_vscode_uri4.URI.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
1219
+ import_vscode_languageserver9.LocationLink.create(import_vscode_uri4.URI.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
1096
1220
  ];
1097
1221
  }
1098
1222
 
1099
1223
  // src/service/marko/definition/AttrName.ts
1100
1224
  var import_vscode_uri5 = require("vscode-uri");
1101
- var import_vscode_languageserver9 = require("vscode-languageserver");
1225
+ var import_vscode_languageserver10 = require("vscode-languageserver");
1102
1226
  function AttrName2({
1103
1227
  lookup,
1104
1228
  parsed,
@@ -1122,17 +1246,17 @@ function AttrName2({
1122
1246
  const tagDefDoc = createTextDocument(attrEntryFile);
1123
1247
  const match = RegExpBuilder`/"@${attrName}"\s*:\s*[^\r\n,]+/g`.exec(tagDefDoc.getText());
1124
1248
  if (match && match.index) {
1125
- range = import_vscode_languageserver9.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
1249
+ range = import_vscode_languageserver10.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
1126
1250
  }
1127
1251
  }
1128
1252
  return [
1129
- import_vscode_languageserver9.LocationLink.create(import_vscode_uri5.URI.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1253
+ import_vscode_languageserver10.LocationLink.create(import_vscode_uri5.URI.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1130
1254
  ];
1131
1255
  }
1132
1256
 
1133
1257
  // src/service/marko/definition/index.ts
1134
- var handlers2 = {
1135
- OpenTagName: OpenTagName2,
1258
+ var handlers3 = {
1259
+ OpenTagName: OpenTagName3,
1136
1260
  AttrName: AttrName2
1137
1261
  };
1138
1262
  var findDefinition = async (doc, params) => {
@@ -1140,7 +1264,7 @@ var findDefinition = async (doc, params) => {
1140
1264
  const parsed = parse2(doc);
1141
1265
  const offset = doc.offsetAt(params.position);
1142
1266
  const node = parsed.nodeAt(offset);
1143
- return await ((_a = handlers2[NodeType[node.type]]) == null ? void 0 : _a.call(handlers2, {
1267
+ return await ((_a = handlers3[NodeType[node.type]]) == null ? void 0 : _a.call(handlers3, {
1144
1268
  document: doc,
1145
1269
  params,
1146
1270
  parsed,
@@ -1152,9 +1276,9 @@ var findDefinition = async (doc, params) => {
1152
1276
  };
1153
1277
 
1154
1278
  // src/service/marko/document-links/extract.ts
1155
- var import_vscode_languageserver10 = require("vscode-languageserver");
1279
+ var import_vscode_languageserver11 = require("vscode-languageserver");
1156
1280
  var import_vscode_uri6 = require("vscode-uri");
1157
- var importTagReg = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1281
+ var importTagReg2 = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1158
1282
  function extractDocumentLinks(doc, parsed, lookup) {
1159
1283
  if (import_vscode_uri6.URI.parse(doc.uri).scheme === "untitled") {
1160
1284
  return [];
@@ -1165,14 +1289,18 @@ function extractDocumentLinks(doc, parsed, lookup) {
1165
1289
  const read = (range) => code.slice(range.start, range.end);
1166
1290
  const visit = (node) => {
1167
1291
  switch (node.type) {
1292
+ case 14 /* AttrTag */:
1293
+ if (node.body) {
1294
+ for (const child of node.body) {
1295
+ visit(child);
1296
+ }
1297
+ }
1298
+ break;
1168
1299
  case 1 /* Tag */:
1169
1300
  if (node.attrs && node.nameText) {
1170
1301
  for (const attr of node.attrs) {
1171
1302
  if (isDocumentLinkAttr(doc, node, attr)) {
1172
- links.push(import_vscode_languageserver10.DocumentLink.create({
1173
- start: parsed.positionAt(attr.value.value.start),
1174
- end: parsed.positionAt(attr.value.value.end)
1175
- }, resolveUrl(read(attr.value.value).slice(1, -1), doc.uri)));
1303
+ links.push(import_vscode_languageserver11.DocumentLink.create(parsed.locationAt(attr.value.value), resolveUrl(read(attr.value.value).slice(1, -1), doc.uri)));
1176
1304
  }
1177
1305
  }
1178
1306
  }
@@ -1186,18 +1314,18 @@ function extractDocumentLinks(doc, parsed, lookup) {
1186
1314
  };
1187
1315
  for (const item of program.static) {
1188
1316
  if (item.type === 20 /* Statement */ && code[item.start] === "i") {
1189
- importTagReg.lastIndex = 0;
1317
+ importTagReg2.lastIndex = 0;
1190
1318
  const value = parsed.read(item);
1191
- const match = importTagReg.exec(value);
1319
+ const match = importTagReg2.exec(value);
1192
1320
  if (match) {
1193
1321
  const [{ length }, , tagName] = match;
1194
1322
  const tagDef = lookup.getTag(tagName);
1195
1323
  const fileForTag = tagDef && (tagDef.template || tagDef.renderer);
1196
1324
  if (fileForTag) {
1197
- links.push(import_vscode_languageserver10.DocumentLink.create({
1198
- start: parsed.positionAt(item.start + match.index),
1199
- end: parsed.positionAt(item.start + match.index + length)
1200
- }, fileForTag));
1325
+ links.push(import_vscode_languageserver11.DocumentLink.create(parsed.locationAt({
1326
+ start: item.start + match.index,
1327
+ end: item.start + match.index + length
1328
+ }), fileForTag));
1201
1329
  }
1202
1330
  }
1203
1331
  }
@@ -1220,14 +1348,55 @@ var findDocumentLinks = async (doc) => {
1220
1348
  return result;
1221
1349
  };
1222
1350
 
1223
- // src/service/marko/format.ts
1224
- var import_vscode_languageserver11 = require("vscode-languageserver");
1351
+ // src/service/marko/document-symbols/extract.ts
1225
1352
  var import_vscode_uri7 = require("vscode-uri");
1353
+ var import_vscode_languageserver12 = require("vscode-languageserver");
1354
+ function extractDocumentSymbols(doc, parsed, lookup) {
1355
+ if (import_vscode_uri7.URI.parse(doc.uri).scheme === "untitled") {
1356
+ return [];
1357
+ }
1358
+ const symbols = [];
1359
+ const { program } = parsed;
1360
+ const visit = (node) => {
1361
+ var _a, _b;
1362
+ switch (node.type) {
1363
+ case 1 /* Tag */:
1364
+ case 14 /* AttrTag */:
1365
+ symbols.push(import_vscode_languageserver12.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) && import_vscode_languageserver12.SymbolKind.Property || import_vscode_languageserver12.SymbolKind.Class, parsed.locationAt(node), doc.uri));
1366
+ if (node.body) {
1367
+ for (const child of node.body) {
1368
+ visit(child);
1369
+ }
1370
+ }
1371
+ break;
1372
+ }
1373
+ };
1374
+ for (const item of program.body) {
1375
+ visit(item);
1376
+ }
1377
+ return symbols;
1378
+ }
1379
+
1380
+ // src/service/marko/document-symbols/index.ts
1381
+ var cache2 = /* @__PURE__ */ new WeakMap();
1382
+ var findDocumentSymbols = async (doc) => {
1383
+ const parsed = parse2(doc);
1384
+ let result = cache2.get(parsed);
1385
+ if (!result) {
1386
+ result = extractDocumentSymbols(doc, parsed, getCompilerInfo(doc).lookup);
1387
+ cache2.set(parsed, result);
1388
+ }
1389
+ return result;
1390
+ };
1391
+
1392
+ // src/service/marko/format.ts
1393
+ var import_vscode_languageserver13 = require("vscode-languageserver");
1394
+ var import_vscode_uri8 = require("vscode-uri");
1226
1395
  var prettier = __toESM(require("prettier"));
1227
1396
  var markoPrettier = __toESM(require("prettier-plugin-marko"));
1228
1397
  var format2 = async (doc, params, cancel) => {
1229
1398
  try {
1230
- const { fsPath, scheme } = import_vscode_uri7.URI.parse(doc.uri);
1399
+ const { fsPath, scheme } = import_vscode_uri8.URI.parse(doc.uri);
1231
1400
  const text = doc.getText();
1232
1401
  const options = {
1233
1402
  parser: "marko",
@@ -1242,7 +1411,7 @@ var format2 = async (doc, params, cancel) => {
1242
1411
  if (cancel.isCancellationRequested)
1243
1412
  return;
1244
1413
  return [
1245
- import_vscode_languageserver11.TextEdit.replace(import_vscode_languageserver11.Range.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1414
+ import_vscode_languageserver13.TextEdit.replace(import_vscode_languageserver13.Range.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1246
1415
  ];
1247
1416
  } catch (e) {
1248
1417
  displayError(e);
@@ -1253,13 +1422,15 @@ var format2 = async (doc, params, cancel) => {
1253
1422
  var marko_default = {
1254
1423
  doComplete,
1255
1424
  doValidate,
1425
+ doHover,
1256
1426
  findDefinition,
1257
1427
  findDocumentLinks,
1428
+ findDocumentSymbols,
1258
1429
  format: format2
1259
1430
  };
1260
1431
 
1261
1432
  // src/service/stylesheet/index.ts
1262
- var import_vscode_languageserver12 = require("vscode-languageserver");
1433
+ var import_vscode_languageserver14 = require("vscode-languageserver");
1263
1434
  var import_vscode_css_languageservice2 = require("vscode-css-languageservice");
1264
1435
  var import_vscode_languageserver_textdocument2 = require("vscode-languageserver-textdocument");
1265
1436
 
@@ -1365,6 +1536,13 @@ function extractStyleSheets(code, program, lookup) {
1365
1536
  const visit = (node) => {
1366
1537
  var _a, _b;
1367
1538
  switch (node.type) {
1539
+ case 14 /* AttrTag */:
1540
+ if (node.body) {
1541
+ for (const child of node.body) {
1542
+ visit(child);
1543
+ }
1544
+ }
1545
+ break;
1368
1546
  case 1 /* Tag */:
1369
1547
  if (node.nameText === "style" && node.concise && node.attrs) {
1370
1548
  const block = node.attrs.at(-1);
@@ -1421,7 +1599,7 @@ function extractStyleSheets(code, program, lookup) {
1421
1599
  }
1422
1600
 
1423
1601
  // src/service/stylesheet/index.ts
1424
- var cache2 = /* @__PURE__ */ new WeakMap();
1602
+ var cache3 = /* @__PURE__ */ new WeakMap();
1425
1603
  var services = {
1426
1604
  css: import_vscode_css_languageservice2.getCSSLanguageService,
1427
1605
  less: import_vscode_css_languageservice2.getLESSLanguageService,
@@ -1463,7 +1641,7 @@ var StyleSheetService = {
1463
1641
  }
1464
1642
  return result;
1465
1643
  }
1466
- return import_vscode_languageserver12.CompletionList.create([], true);
1644
+ return import_vscode_languageserver14.CompletionList.create([], true);
1467
1645
  },
1468
1646
  findDefinition(doc, params) {
1469
1647
  const infoByExt = getStyleSheetInfo(doc);
@@ -1509,15 +1687,39 @@ var StyleSheetService = {
1509
1687
  return result.length ? result : void 0;
1510
1688
  }
1511
1689
  },
1512
- findDocumentLinks(doc) {
1690
+ findDocumentSymbols(doc) {
1513
1691
  const infoByExt = getStyleSheetInfo(doc);
1514
1692
  const result = [];
1515
1693
  for (const ext in infoByExt) {
1516
1694
  const info = infoByExt[ext];
1517
1695
  const { service: service2, virtualDoc } = info;
1518
- for (const link of service2.findDocumentLinks(virtualDoc, info.parsed, {
1519
- resolveReference: resolveUrl
1520
- })) {
1696
+ for (const symbol of service2.findDocumentSymbols(virtualDoc, info.parsed)) {
1697
+ if (symbol.location.uri === doc.uri) {
1698
+ const range = getSourceRange(doc, info, symbol.location.range);
1699
+ if (range) {
1700
+ result.push({
1701
+ kind: symbol.kind,
1702
+ name: symbol.name,
1703
+ tags: symbol.tags,
1704
+ deprecated: symbol.deprecated,
1705
+ containerName: symbol.containerName,
1706
+ location: { uri: doc.uri, range }
1707
+ });
1708
+ }
1709
+ } else {
1710
+ result.push(symbol);
1711
+ }
1712
+ }
1713
+ }
1714
+ return result.length ? result : void 0;
1715
+ },
1716
+ async findDocumentLinks(doc) {
1717
+ const infoByExt = getStyleSheetInfo(doc);
1718
+ const result = [];
1719
+ for (const ext in infoByExt) {
1720
+ const info = infoByExt[ext];
1721
+ const { service: service2, virtualDoc } = info;
1722
+ for (const link of await service2.findDocumentLinks2(virtualDoc, info.parsed, { resolveReference: resolveUrl })) {
1521
1723
  const range = getSourceRange(doc, info, link.range);
1522
1724
  if (range) {
1523
1725
  result.push({
@@ -1584,7 +1786,7 @@ var StyleSheetService = {
1584
1786
  continue;
1585
1787
  const { service: service2, virtualDoc } = info;
1586
1788
  const result = [];
1587
- for (const colorPresentation of service2.getColorPresentations(virtualDoc, info.parsed, params.color, import_vscode_languageserver12.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)))) {
1789
+ for (const colorPresentation of service2.getColorPresentations(virtualDoc, info.parsed, params.color, import_vscode_languageserver14.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)))) {
1588
1790
  const textEdit = colorPresentation.textEdit && getSourceEdit(doc, info, colorPresentation.textEdit);
1589
1791
  const additionalTextEdits = colorPresentation.additionalTextEdits && getSourceEdits(doc, info, colorPresentation.additionalTextEdits);
1590
1792
  if (textEdit || additionalTextEdits) {
@@ -1642,7 +1844,7 @@ var StyleSheetService = {
1642
1844
  }
1643
1845
  if (result.documentChanges) {
1644
1846
  for (const change of result.documentChanges) {
1645
- if (import_vscode_languageserver12.TextDocumentEdit.is(change)) {
1847
+ if (import_vscode_languageserver14.TextDocumentEdit.is(change)) {
1646
1848
  if (change.textDocument.uri === doc.uri) {
1647
1849
  change.edits = getSourceEdits(doc, info, change.edits) || [];
1648
1850
  }
@@ -1665,7 +1867,7 @@ var StyleSheetService = {
1665
1867
  if (generatedOffsetEnd === void 0)
1666
1868
  continue;
1667
1869
  const { service: service2, virtualDoc } = info;
1668
- const result = service2.doCodeActions(virtualDoc, import_vscode_languageserver12.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
1870
+ const result = service2.doCodeActions(virtualDoc, import_vscode_languageserver14.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
1669
1871
  for (const command of result) {
1670
1872
  const edits = (_a = command.arguments) == null ? void 0 : _a[2];
1671
1873
  if (edits && Array.isArray(edits) && isTextEdit(edits[0])) {
@@ -1750,7 +1952,7 @@ function getSourceRange(doc, info, range) {
1750
1952
  function getStyleSheetInfo(doc) {
1751
1953
  var _a;
1752
1954
  const parsed = parse2(doc);
1753
- let cached = cache2.get(parsed);
1955
+ let cached = cache3.get(parsed);
1754
1956
  if (!cached) {
1755
1957
  const results = extractStyleSheets(doc.getText(), parsed.program, getCompilerInfo(doc).lookup);
1756
1958
  cached = {};
@@ -1771,7 +1973,7 @@ function getStyleSheetInfo(doc) {
1771
1973
  parsed: service2.parseStylesheet(virtualDoc)
1772
1974
  };
1773
1975
  }
1774
- cache2.set(parsed, cached);
1976
+ cache3.set(parsed, cached);
1775
1977
  }
1776
1978
  return cached;
1777
1979
  }
@@ -1789,51 +1991,47 @@ var service = {
1789
1991
  }));
1790
1992
  },
1791
1993
  async doComplete(doc, params, cancel) {
1792
- const result = import_vscode_languageserver13.CompletionList.create([], false);
1994
+ let items;
1995
+ let isIncomplete = false;
1793
1996
  try {
1794
- const requests = plugins.map((plugin) => {
1997
+ for (const pending of plugins.map((plugin) => {
1795
1998
  var _a;
1796
1999
  return (_a = plugin.doComplete) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1797
- });
1798
- for (const pending of requests) {
2000
+ })) {
1799
2001
  const cur = await pending;
1800
2002
  if (cancel.isCancellationRequested)
1801
2003
  return;
1802
2004
  if (cur) {
1803
- let items;
2005
+ let curItems;
1804
2006
  if (Array.isArray(cur)) {
1805
- items = cur;
2007
+ curItems = cur;
1806
2008
  } else {
1807
- items = cur.items;
1808
- result.isIncomplete || (result.isIncomplete = cur.isIncomplete);
2009
+ curItems = cur.items;
2010
+ isIncomplete || (isIncomplete = cur.isIncomplete);
1809
2011
  }
1810
- result.items.push(...items);
2012
+ items = items ? items.concat(curItems) : curItems;
1811
2013
  }
1812
2014
  }
1813
2015
  } catch (err) {
1814
- result.isIncomplete = true;
2016
+ isIncomplete = true;
1815
2017
  displayError(err);
1816
2018
  }
1817
- return result;
2019
+ if (items) {
2020
+ return import_vscode_languageserver15.CompletionList.create(items, isIncomplete);
2021
+ }
1818
2022
  },
1819
2023
  async findDefinition(doc, params, cancel) {
1820
- const result = [];
2024
+ let result;
1821
2025
  try {
1822
- const requests = plugins.map((plugin) => {
2026
+ for (const pending of plugins.map((plugin) => {
1823
2027
  var _a;
1824
2028
  return (_a = plugin.findDefinition) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1825
- });
1826
- for (const pending of requests) {
2029
+ })) {
1827
2030
  const cur = await pending;
1828
2031
  if (cancel.isCancellationRequested)
1829
2032
  return;
1830
- if (cur) {
1831
- if (Array.isArray(cur)) {
1832
- result.push(...cur);
1833
- } else {
1834
- result.push(cur);
1835
- }
1836
- }
2033
+ if (cur)
2034
+ result = (result || []).concat(cur);
1837
2035
  }
1838
2036
  } catch (err) {
1839
2037
  displayError(err);
@@ -1843,21 +2041,33 @@ var service = {
1843
2041
  async findReferences(doc, params, cancel) {
1844
2042
  let result;
1845
2043
  try {
1846
- const requests = plugins.map((plugin) => {
2044
+ for (const pending of plugins.map((plugin) => {
1847
2045
  var _a;
1848
2046
  return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1849
- });
1850
- for (const pending of requests) {
2047
+ })) {
1851
2048
  const cur = await pending;
1852
2049
  if (cancel.isCancellationRequested)
1853
2050
  return;
1854
- if (cur) {
1855
- if (result) {
1856
- result.push(...cur);
1857
- } else {
1858
- result = cur;
1859
- }
1860
- }
2051
+ if (cur)
2052
+ result = result ? result.concat(cur) : cur;
2053
+ }
2054
+ } catch (err) {
2055
+ displayError(err);
2056
+ }
2057
+ return result;
2058
+ },
2059
+ async findDocumentSymbols(doc, params, cancel) {
2060
+ let result;
2061
+ try {
2062
+ for (const pending of plugins.map((plugin) => {
2063
+ var _a;
2064
+ return (_a = plugin.findDocumentSymbols) == null ? void 0 : _a.call(plugin, doc, params, cancel);
2065
+ })) {
2066
+ const cur = await pending;
2067
+ if (cancel.isCancellationRequested)
2068
+ return;
2069
+ if (cur)
2070
+ result = result ? result.concat(cur) : cur;
1861
2071
  }
1862
2072
  } catch (err) {
1863
2073
  displayError(err);
@@ -1867,21 +2077,15 @@ var service = {
1867
2077
  async findDocumentLinks(doc, params, cancel) {
1868
2078
  let result;
1869
2079
  try {
1870
- const requests = plugins.map((plugin) => {
2080
+ for (const pending of plugins.map((plugin) => {
1871
2081
  var _a;
1872
2082
  return (_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1873
- });
1874
- for (const pending of requests) {
2083
+ })) {
1875
2084
  const cur = await pending;
1876
2085
  if (cancel.isCancellationRequested)
1877
2086
  return;
1878
- if (cur) {
1879
- if (result) {
1880
- result.push(...cur);
1881
- } else {
1882
- result = cur;
1883
- }
1884
- }
2087
+ if (cur)
2088
+ result = result ? result.concat(cur) : cur;
1885
2089
  }
1886
2090
  } catch (err) {
1887
2091
  displayError(err);
@@ -1891,21 +2095,15 @@ var service = {
1891
2095
  async findDocumentHighlights(doc, params, cancel) {
1892
2096
  let result;
1893
2097
  try {
1894
- const requests = plugins.map((plugin) => {
2098
+ for (const pending of plugins.map((plugin) => {
1895
2099
  var _a;
1896
2100
  return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1897
- });
1898
- for (const pending of requests) {
2101
+ })) {
1899
2102
  const cur = await pending;
1900
2103
  if (cancel.isCancellationRequested)
1901
2104
  return;
1902
- if (cur) {
1903
- if (result) {
1904
- result.push(...cur);
1905
- } else {
1906
- result = cur;
1907
- }
1908
- }
2105
+ if (cur)
2106
+ result = result ? result.concat(cur) : cur;
1909
2107
  }
1910
2108
  } catch (err) {
1911
2109
  displayError(err);
@@ -1915,21 +2113,15 @@ var service = {
1915
2113
  async findDocumentColors(doc, params, cancel) {
1916
2114
  let result;
1917
2115
  try {
1918
- const requests = plugins.map((plugin) => {
2116
+ for (const pending of plugins.map((plugin) => {
1919
2117
  var _a;
1920
2118
  return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1921
- });
1922
- for (const pending of requests) {
2119
+ })) {
1923
2120
  const cur = await pending;
1924
2121
  if (cancel.isCancellationRequested)
1925
2122
  return;
1926
- if (cur) {
1927
- if (result) {
1928
- result.push(...cur);
1929
- } else {
1930
- result = cur;
1931
- }
1932
- }
2123
+ if (cur)
2124
+ result = result ? result.concat(cur) : cur;
1933
2125
  }
1934
2126
  } catch (err) {
1935
2127
  displayError(err);
@@ -1939,21 +2131,15 @@ var service = {
1939
2131
  async getColorPresentations(doc, params, cancel) {
1940
2132
  let result;
1941
2133
  try {
1942
- const requests = plugins.map((plugin) => {
2134
+ for (const pending of plugins.map((plugin) => {
1943
2135
  var _a;
1944
2136
  return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1945
- });
1946
- for (const pending of requests) {
2137
+ })) {
1947
2138
  const cur = await pending;
1948
2139
  if (cancel.isCancellationRequested)
1949
2140
  return;
1950
- if (cur) {
1951
- if (result) {
1952
- result.push(...cur);
1953
- } else {
1954
- result = cur;
1955
- }
1956
- }
2141
+ if (cur)
2142
+ result = result ? result.concat(cur) : cur;
1957
2143
  }
1958
2144
  } catch (err) {
1959
2145
  displayError(err);
@@ -1979,41 +2165,32 @@ var service = {
1979
2165
  let changeAnnotations;
1980
2166
  let documentChanges;
1981
2167
  try {
1982
- const requests = plugins.map((plugin) => {
2168
+ for (const pending of plugins.map((plugin) => {
1983
2169
  var _a;
1984
2170
  return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1985
- });
1986
- for (const pending of requests) {
2171
+ })) {
1987
2172
  const cur = await pending;
1988
2173
  if (cancel.isCancellationRequested)
1989
2174
  return;
1990
2175
  if (cur) {
1991
2176
  if (cur.changes) {
1992
2177
  if (changes) {
2178
+ changes = { ...changes };
1993
2179
  for (const uri in cur.changes) {
1994
- if (changes[uri]) {
1995
- changes[uri].push(...cur.changes[uri]);
1996
- } else {
1997
- changes[uri] = cur.changes[uri];
1998
- }
2180
+ changes[uri] = changes[uri] ? changes[uri].concat(cur.changes[uri]) : cur.changes[uri];
1999
2181
  }
2000
2182
  } else {
2001
2183
  changes = cur.changes;
2002
2184
  }
2003
2185
  }
2004
2186
  if (cur.changeAnnotations) {
2005
- if (changeAnnotations) {
2006
- Object.assign(changeAnnotations, cur.changeAnnotations);
2007
- } else {
2008
- changeAnnotations = cur.changeAnnotations;
2009
- }
2187
+ changeAnnotations = changeAnnotations ? {
2188
+ ...changeAnnotations,
2189
+ ...cur.changeAnnotations
2190
+ } : cur.changeAnnotations;
2010
2191
  }
2011
2192
  if (cur.documentChanges) {
2012
- if (documentChanges) {
2013
- documentChanges.push(...cur.documentChanges);
2014
- } else {
2015
- documentChanges = cur.documentChanges;
2016
- }
2193
+ documentChanges = documentChanges ? documentChanges.concat(cur.documentChanges) : cur.documentChanges;
2017
2194
  }
2018
2195
  }
2019
2196
  }
@@ -2029,19 +2206,17 @@ var service = {
2029
2206
  }
2030
2207
  },
2031
2208
  async doCodeActions(doc, params, cancel) {
2032
- const result = [];
2209
+ let result;
2033
2210
  try {
2034
- const requests = plugins.map((plugin) => {
2211
+ for (const pending of plugins.map((plugin) => {
2035
2212
  var _a;
2036
2213
  return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
2037
- });
2038
- for (const pending of requests) {
2214
+ })) {
2039
2215
  const cur = await pending;
2040
2216
  if (cancel.isCancellationRequested)
2041
2217
  return;
2042
- if (cur) {
2043
- result.push(...cur);
2044
- }
2218
+ if (cur)
2219
+ result = result ? result.concat(cur) : cur;
2045
2220
  }
2046
2221
  } catch (err) {
2047
2222
  displayError(err);
@@ -2049,16 +2224,15 @@ var service = {
2049
2224
  return result;
2050
2225
  },
2051
2226
  async doValidate(doc) {
2052
- const result = [];
2227
+ let result;
2053
2228
  try {
2054
- const requests = plugins.map((plugin) => {
2229
+ for (const pending of plugins.map((plugin) => {
2055
2230
  var _a;
2056
2231
  return (_a = plugin.doValidate) == null ? void 0 : _a.call(plugin, doc);
2057
- });
2058
- for (const pending of requests) {
2232
+ })) {
2059
2233
  const cur = await pending;
2060
2234
  if (cur)
2061
- result.push(...cur);
2235
+ result = result ? result.concat(cur) : cur;
2062
2236
  }
2063
2237
  } catch (err) {
2064
2238
  displayError(err);
@@ -2100,6 +2274,7 @@ connection2.onInitialize(async (params) => {
2100
2274
  documentLinkProvider: { resolveProvider: false },
2101
2275
  colorProvider: true,
2102
2276
  documentHighlightProvider: true,
2277
+ documentSymbolProvider: true,
2103
2278
  completionProvider: {
2104
2279
  triggerCharacters: [
2105
2280
  ".",
@@ -2145,6 +2320,9 @@ connection2.onReferences(async (params, cancel) => {
2145
2320
  connection2.onDocumentLinks(async (params, cancel) => {
2146
2321
  return await service.findDocumentLinks(documents.get(params.textDocument.uri), params, cancel) || null;
2147
2322
  });
2323
+ connection2.onDocumentSymbol(async (params, cancel) => {
2324
+ return await service.findDocumentSymbols(documents.get(params.textDocument.uri), params, cancel) || null;
2325
+ });
2148
2326
  connection2.onDocumentHighlight(async (params, cancel) => {
2149
2327
  return await service.findDocumentHighlights(documents.get(params.textDocument.uri), params, cancel) || null;
2150
2328
  });