@marko/language-server 0.12.9 → 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.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 cache2 = /* @__PURE__ */ new Map();
578
+ const cache3 = /* @__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: cache2,
595
+ cache: cache3,
596
596
  get lookup() {
597
- let lookup = cache2.get(lookupKey);
597
+ let lookup = cache3.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
- cache2.set(lookupKey, lookup);
604
+ cache3.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_languageserver11 = require("vscode-languageserver");
628
+ var import_vscode_languageserver14 = require("vscode-languageserver");
629
629
 
630
630
  // src/service/marko/complete/index.ts
631
- var import_vscode_languageserver4 = 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 = 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.` : nodeModuleName ? isCoreTag ? `Core Marko [<${tag.name}>](${fileURIForTag}) tag.` : `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
@@ -842,18 +878,190 @@ function AttrName({
842
878
  return completions;
843
879
  }
844
880
 
881
+ // src/service/marko/complete/AttrValue.ts
882
+ var import_path3 = __toESM(require("path"));
883
+ var import_vscode_languageserver4 = require("vscode-languageserver");
884
+
885
+ // src/service/marko/util/is-document-link-attr.ts
886
+ var linkedAttrs = /* @__PURE__ */ new Map([
887
+ [
888
+ "src",
889
+ /* @__PURE__ */ new Set([
890
+ "audio",
891
+ "embed",
892
+ "iframe",
893
+ "img",
894
+ "input",
895
+ "script",
896
+ "source",
897
+ "track",
898
+ "video"
899
+ ])
900
+ ],
901
+ ["href", /* @__PURE__ */ new Set(["a", "area", "link"])],
902
+ ["data", /* @__PURE__ */ new Set(["object"])],
903
+ ["poster", /* @__PURE__ */ new Set(["video"])]
904
+ ]);
905
+ function isDocumentLinkAttr(doc, tag, attr) {
906
+ var _a, _b;
907
+ return tag.nameText && attr.type === 8 /* AttrNamed */ && ((_a = attr.value) == null ? void 0 : _a.type) === 11 /* AttrValue */ && /^['"]$/.test(doc.getText()[attr.value.value.start]) && ((_b = linkedAttrs.get(doc.getText().slice(attr.name.start, attr.name.end))) == null ? void 0 : _b.has(tag.nameText)) || false;
908
+ }
909
+
910
+ // src/utils/file-system.ts
911
+ var import_promises = __toESM(require("fs/promises"));
912
+ var import_vscode_css_languageservice = require("vscode-css-languageservice");
913
+ var import_url = require("url");
914
+ var file_system_default = {
915
+ stat,
916
+ readDirectory
917
+ };
918
+ async function stat(uri) {
919
+ let type = import_vscode_css_languageservice.FileType.Unknown;
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));
925
+ if (stat2.isDirectory())
926
+ type = import_vscode_css_languageservice.FileType.Directory;
927
+ else if (stat2.isFile())
928
+ type = import_vscode_css_languageservice.FileType.File;
929
+ ctime = stat2.ctimeMs;
930
+ mtime = stat2.mtimeMs;
931
+ size = stat2.size;
932
+ } catch {
933
+ }
934
+ return {
935
+ type,
936
+ ctime,
937
+ mtime,
938
+ size
939
+ };
940
+ }
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
+ }
949
+ }
950
+
951
+ // src/utils/resolve-url.ts
952
+ function resolveUrl(to, base) {
953
+ try {
954
+ const url = new URL(to, base);
955
+ if (url.protocol === "file:")
956
+ return url.toString();
957
+ } catch {
958
+ return void 0;
959
+ }
960
+ }
961
+
962
+ // src/service/marko/complete/AttrValue.ts
963
+ async function AttrValue({
964
+ document,
965
+ offset,
966
+ node,
967
+ parsed,
968
+ code
969
+ }) {
970
+ const attr = node.parent;
971
+ if (isDocumentLinkAttr(document, attr.parent, attr)) {
972
+ const start = node.value.start + 1;
973
+ if (code[start] !== ".")
974
+ return;
975
+ const end = node.value.end - 1;
976
+ const relativeOffset = offset - start;
977
+ const rawValue = parsed.read({
978
+ start,
979
+ end
980
+ });
981
+ const segmentStart = rawValue.lastIndexOf("/", relativeOffset);
982
+ if (segmentStart === -1)
983
+ return;
984
+ const req = rawValue.slice(0, segmentStart);
985
+ const uri = resolveUrl(req, document.uri);
986
+ if (uri) {
987
+ const result = [];
988
+ const curFile = req === "." ? import_path3.default.basename(document.uri) : void 0;
989
+ const replaceRange = import_vscode_languageserver4.Range.create(document.positionAt(start + segmentStart + 1), document.positionAt(start + rawValue.length));
990
+ for (const [entry, type] of await file_system_default.readDirectory(uri)) {
991
+ if (entry[0] !== "." && entry !== curFile) {
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: {
997
+ title: "Suggest",
998
+ command: "editor.action.triggerSuggest"
999
+ }
1000
+ } : {
1001
+ label: entry,
1002
+ kind: import_vscode_languageserver4.CompletionItemKind.File,
1003
+ textEdit: import_vscode_languageserver4.TextEdit.replace(replaceRange, entry)
1004
+ });
1005
+ }
1006
+ }
1007
+ return result;
1008
+ }
1009
+ }
1010
+ }
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
+
845
1051
  // src/service/marko/complete/index.ts
846
1052
  var handlers = {
847
1053
  Tag,
848
1054
  OpenTagName,
849
- AttrName
1055
+ AttrName,
1056
+ AttrValue,
1057
+ Statement
850
1058
  };
851
1059
  var doComplete = async (doc, params) => {
852
1060
  var _a;
853
1061
  const parsed = parse2(doc);
854
1062
  const offset = doc.offsetAt(params.position);
855
1063
  const node = parsed.nodeAt(offset);
856
- return import_vscode_languageserver4.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, {
857
1065
  document: doc,
858
1066
  params,
859
1067
  parsed,
@@ -865,15 +1073,15 @@ var doComplete = async (doc, params) => {
865
1073
  };
866
1074
 
867
1075
  // src/service/marko/validate.ts
868
- var import_vscode_languageserver5 = require("vscode-languageserver");
1076
+ var import_vscode_languageserver7 = require("vscode-languageserver");
869
1077
  var markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
870
1078
  var doValidate = (doc) => {
871
1079
  const fsPath = getDocFile(doc);
872
1080
  const diagnostics = [];
873
- const { compiler, translator, cache: cache2 } = getCompilerInfo(doc);
1081
+ const { compiler, translator, cache: cache3 } = getCompilerInfo(doc);
874
1082
  try {
875
1083
  compiler.compileSync(doc.getText(), fsPath || "untitled.marko", {
876
- cache: cache2,
1084
+ cache: cache3,
877
1085
  translator,
878
1086
  code: false,
879
1087
  output: "source",
@@ -885,16 +1093,16 @@ var doValidate = (doc) => {
885
1093
  const [, fileName, rawLine, rawCol, msg] = match;
886
1094
  const line = (parseInt(rawLine, 10) || 1) - 1;
887
1095
  const col = (parseInt(rawCol, 10) || 1) - 1;
888
- diagnostics.push(import_vscode_languageserver5.Diagnostic.create(import_vscode_languageserver5.Range.create(line, col, line, col), msg, import_vscode_languageserver5.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));
889
1097
  }
890
1098
  }
891
1099
  return diagnostics;
892
1100
  };
893
1101
 
894
1102
  // src/service/marko/definition/OpenTagName.ts
895
- var import_path3 = __toESM(require("path"));
1103
+ var import_path4 = __toESM(require("path"));
896
1104
  var import_vscode_uri4 = require("vscode-uri");
897
- var import_vscode_languageserver7 = require("vscode-languageserver");
1105
+ var import_vscode_languageserver9 = require("vscode-languageserver");
898
1106
 
899
1107
  // src/utils/regexp-builder.ts
900
1108
  function RegExpBuilder(strings, ...expressions) {
@@ -923,9 +1131,9 @@ function escape(val) {
923
1131
  // src/utils/utils.ts
924
1132
  var import_fs = __toESM(require("fs"));
925
1133
  var import_vscode_uri3 = require("vscode-uri");
926
- var import_vscode_languageserver6 = require("vscode-languageserver");
1134
+ var import_vscode_languageserver8 = require("vscode-languageserver");
927
1135
  var import_vscode_languageserver_textdocument = require("vscode-languageserver-textdocument");
928
- var START_OF_FILE = import_vscode_languageserver6.Range.create(import_vscode_languageserver6.Position.create(0, 0), import_vscode_languageserver6.Position.create(0, 0));
1136
+ var START_OF_FILE = import_vscode_languageserver8.Range.create(import_vscode_languageserver8.Position.create(0, 0), import_vscode_languageserver8.Position.create(0, 0));
929
1137
  function createTextDocument(filename) {
930
1138
  const uri = import_vscode_uri3.URI.file(filename).toString();
931
1139
  const content = import_fs.default.readFileSync(filename, "utf-8");
@@ -953,24 +1161,24 @@ function OpenTagName2({
953
1161
  return;
954
1162
  }
955
1163
  const tagEntryFile = tagDef.template || tagDef.renderer || tagDef.filePath;
956
- if (!import_path3.default.isAbsolute(tagEntryFile)) {
1164
+ if (!import_path4.default.isAbsolute(tagEntryFile)) {
957
1165
  return;
958
1166
  }
959
1167
  if (/\/marko(?:-tag)?\.json$/.test(tagEntryFile)) {
960
1168
  const tagDefDoc = createTextDocument(tagEntryFile);
961
1169
  const match = RegExpBuilder`/"(?:<${tag.nameText}>|${tag.nameText})"\s*:\s*[^\r\n,]+/g`.exec(tagDefDoc.getText());
962
1170
  if (match && match.index) {
963
- range = import_vscode_languageserver7.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
1171
+ range = import_vscode_languageserver9.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
964
1172
  }
965
1173
  }
966
1174
  return [
967
- import_vscode_languageserver7.LocationLink.create(import_vscode_uri4.URI.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
1175
+ import_vscode_languageserver9.LocationLink.create(import_vscode_uri4.URI.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
968
1176
  ];
969
1177
  }
970
1178
 
971
1179
  // src/service/marko/definition/AttrName.ts
972
1180
  var import_vscode_uri5 = require("vscode-uri");
973
- var import_vscode_languageserver8 = require("vscode-languageserver");
1181
+ var import_vscode_languageserver10 = require("vscode-languageserver");
974
1182
  function AttrName2({
975
1183
  lookup,
976
1184
  parsed,
@@ -994,11 +1202,11 @@ function AttrName2({
994
1202
  const tagDefDoc = createTextDocument(attrEntryFile);
995
1203
  const match = RegExpBuilder`/"@${attrName}"\s*:\s*[^\r\n,]+/g`.exec(tagDefDoc.getText());
996
1204
  if (match && match.index) {
997
- range = import_vscode_languageserver8.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
1205
+ range = import_vscode_languageserver10.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
998
1206
  }
999
1207
  }
1000
1208
  return [
1001
- import_vscode_languageserver8.LocationLink.create(import_vscode_uri5.URI.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1209
+ import_vscode_languageserver10.LocationLink.create(import_vscode_uri5.URI.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1002
1210
  ];
1003
1211
  }
1004
1212
 
@@ -1023,14 +1231,83 @@ var findDefinition = async (doc, params) => {
1023
1231
  })) || [];
1024
1232
  };
1025
1233
 
1026
- // src/service/marko/format.ts
1027
- var import_vscode_languageserver9 = require("vscode-languageserver");
1234
+ // src/service/marko/document-links/extract.ts
1235
+ var import_vscode_languageserver11 = require("vscode-languageserver");
1028
1236
  var import_vscode_uri6 = require("vscode-uri");
1237
+ var importTagReg2 = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1238
+ function extractDocumentLinks(doc, parsed, lookup) {
1239
+ if (import_vscode_uri6.URI.parse(doc.uri).scheme === "untitled") {
1240
+ return [];
1241
+ }
1242
+ const links = [];
1243
+ const { program } = parsed;
1244
+ const code = doc.getText();
1245
+ const read = (range) => code.slice(range.start, range.end);
1246
+ const visit = (node) => {
1247
+ switch (node.type) {
1248
+ case 1 /* Tag */:
1249
+ if (node.attrs && node.nameText) {
1250
+ for (const attr of node.attrs) {
1251
+ if (isDocumentLinkAttr(doc, node, attr)) {
1252
+ links.push(import_vscode_languageserver11.DocumentLink.create({
1253
+ start: parsed.positionAt(attr.value.value.start),
1254
+ end: parsed.positionAt(attr.value.value.end)
1255
+ }, resolveUrl(read(attr.value.value).slice(1, -1), doc.uri)));
1256
+ }
1257
+ }
1258
+ }
1259
+ if (node.body) {
1260
+ for (const child of node.body) {
1261
+ visit(child);
1262
+ }
1263
+ }
1264
+ break;
1265
+ }
1266
+ };
1267
+ for (const item of program.static) {
1268
+ if (item.type === 20 /* Statement */ && code[item.start] === "i") {
1269
+ importTagReg2.lastIndex = 0;
1270
+ const value = parsed.read(item);
1271
+ const match = importTagReg2.exec(value);
1272
+ if (match) {
1273
+ const [{ length }, , tagName] = match;
1274
+ const tagDef = lookup.getTag(tagName);
1275
+ const fileForTag = tagDef && (tagDef.template || tagDef.renderer);
1276
+ if (fileForTag) {
1277
+ links.push(import_vscode_languageserver11.DocumentLink.create({
1278
+ start: parsed.positionAt(item.start + match.index),
1279
+ end: parsed.positionAt(item.start + match.index + length)
1280
+ }, fileForTag));
1281
+ }
1282
+ }
1283
+ }
1284
+ }
1285
+ for (const item of program.body) {
1286
+ visit(item);
1287
+ }
1288
+ return links;
1289
+ }
1290
+
1291
+ // src/service/marko/document-links/index.ts
1292
+ var cache = /* @__PURE__ */ new WeakMap();
1293
+ var findDocumentLinks = async (doc) => {
1294
+ const parsed = parse2(doc);
1295
+ let result = cache.get(parsed);
1296
+ if (!result) {
1297
+ result = extractDocumentLinks(doc, parsed, getCompilerInfo(doc).lookup);
1298
+ cache.set(parsed, result);
1299
+ }
1300
+ return result;
1301
+ };
1302
+
1303
+ // src/service/marko/format.ts
1304
+ var import_vscode_languageserver12 = require("vscode-languageserver");
1305
+ var import_vscode_uri7 = require("vscode-uri");
1029
1306
  var prettier = __toESM(require("prettier"));
1030
1307
  var markoPrettier = __toESM(require("prettier-plugin-marko"));
1031
1308
  var format2 = async (doc, params, cancel) => {
1032
1309
  try {
1033
- const { fsPath, scheme } = import_vscode_uri6.URI.parse(doc.uri);
1310
+ const { fsPath, scheme } = import_vscode_uri7.URI.parse(doc.uri);
1034
1311
  const text = doc.getText();
1035
1312
  const options = {
1036
1313
  parser: "marko",
@@ -1045,7 +1322,7 @@ var format2 = async (doc, params, cancel) => {
1045
1322
  if (cancel.isCancellationRequested)
1046
1323
  return;
1047
1324
  return [
1048
- import_vscode_languageserver9.TextEdit.replace(import_vscode_languageserver9.Range.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1325
+ import_vscode_languageserver12.TextEdit.replace(import_vscode_languageserver12.Range.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1049
1326
  ];
1050
1327
  } catch (e) {
1051
1328
  displayError(e);
@@ -1057,12 +1334,13 @@ var marko_default = {
1057
1334
  doComplete,
1058
1335
  doValidate,
1059
1336
  findDefinition,
1337
+ findDocumentLinks,
1060
1338
  format: format2
1061
1339
  };
1062
1340
 
1063
1341
  // src/service/stylesheet/index.ts
1064
- var import_vscode_languageserver10 = require("vscode-languageserver");
1065
- var import_vscode_css_languageservice = require("vscode-css-languageservice");
1342
+ var import_vscode_languageserver13 = require("vscode-languageserver");
1343
+ var import_vscode_css_languageservice2 = require("vscode-css-languageservice");
1066
1344
  var import_vscode_languageserver_textdocument2 = require("vscode-languageserver-textdocument");
1067
1345
 
1068
1346
  // src/utils/extractor.ts
@@ -1201,7 +1479,7 @@ function extractStyleSheets(code, program, lookup) {
1201
1479
  for (const attr of node.attrs) {
1202
1480
  if (attr.type === 8 /* AttrNamed */ && ((_a = attr.value) == null ? void 0 : _a.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
1203
1481
  const name = read(attr.name);
1204
- if (name === "#style" || name === "style" && lookup && node.nameText && name === "style" && ((_b = lookup.getTag(node.nameText)) == null ? void 0 : _b.html)) {
1482
+ if (name === "#style" || name === "style" && node.nameText && name === "style" && ((_b = lookup.getTag(node.nameText)) == null ? void 0 : _b.html)) {
1205
1483
  getExtractor("css").write`:root{${{
1206
1484
  start: attr.value.value.start + 1,
1207
1485
  end: attr.value.value.end - 1
@@ -1223,13 +1501,17 @@ function extractStyleSheets(code, program, lookup) {
1223
1501
  }
1224
1502
 
1225
1503
  // src/service/stylesheet/index.ts
1226
- var cache = /* @__PURE__ */ new WeakMap();
1504
+ var cache2 = /* @__PURE__ */ new WeakMap();
1227
1505
  var services = {
1228
- css: import_vscode_css_languageservice.getCSSLanguageService,
1229
- less: import_vscode_css_languageservice.getLESSLanguageService,
1230
- scss: import_vscode_css_languageservice.getSCSSLanguageService
1506
+ css: import_vscode_css_languageservice2.getCSSLanguageService,
1507
+ less: import_vscode_css_languageservice2.getLESSLanguageService,
1508
+ scss: import_vscode_css_languageservice2.getSCSSLanguageService
1231
1509
  };
1510
+ var clientCapabilities;
1232
1511
  var StyleSheetService = {
1512
+ initialize(params) {
1513
+ clientCapabilities = params.capabilities;
1514
+ },
1233
1515
  async doComplete(doc, params) {
1234
1516
  const infoByExt = getStyleSheetInfo(doc);
1235
1517
  const sourceOffset = doc.offsetAt(params.position);
@@ -1239,28 +1521,31 @@ var StyleSheetService = {
1239
1521
  if (generatedOffset === void 0)
1240
1522
  continue;
1241
1523
  const { service: service2, virtualDoc } = info;
1242
- const result = service2.doComplete(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
1243
- for (const item of result.items) {
1244
- if (item.additionalTextEdits) {
1245
- for (const textEdit2 of item.additionalTextEdits) {
1246
- updateTextEdit(doc, info, textEdit2);
1524
+ const result = await service2.doComplete2(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed, { resolveReference: resolveUrl });
1525
+ if (result.itemDefaults) {
1526
+ const { editRange } = result.itemDefaults;
1527
+ if (editRange) {
1528
+ if ("start" in editRange) {
1529
+ result.itemDefaults.editRange = getSourceRange(doc, info, editRange);
1530
+ } else {
1531
+ editRange.insert = getSourceRange(doc, info, editRange.insert);
1532
+ editRange.replace = getSourceRange(doc, info, editRange.replace);
1247
1533
  }
1248
1534
  }
1249
- const { textEdit } = item;
1250
- if (textEdit) {
1251
- if (textEdit.range) {
1252
- updateTextEdit(doc, info, textEdit);
1253
- }
1254
- if (textEdit.insert) {
1255
- updateInsertReplaceEdit(doc, info, textEdit);
1256
- }
1535
+ }
1536
+ for (const item of result.items) {
1537
+ if (item.textEdit) {
1538
+ item.textEdit = getSourceInsertReplaceEdit(doc, info, item.textEdit);
1539
+ }
1540
+ if (item.additionalTextEdits) {
1541
+ item.additionalTextEdits = getSourceEdits(doc, info, item.additionalTextEdits);
1257
1542
  }
1258
1543
  }
1259
1544
  return result;
1260
1545
  }
1261
- return import_vscode_languageserver10.CompletionList.create([], true);
1546
+ return import_vscode_languageserver13.CompletionList.create([], true);
1262
1547
  },
1263
- async findDefinition(doc, params) {
1548
+ findDefinition(doc, params) {
1264
1549
  const infoByExt = getStyleSheetInfo(doc);
1265
1550
  const sourceOffset = doc.offsetAt(params.position);
1266
1551
  for (const ext in infoByExt) {
@@ -1270,13 +1555,19 @@ var StyleSheetService = {
1270
1555
  continue;
1271
1556
  const { service: service2, virtualDoc } = info;
1272
1557
  const result = service2.findDefinition(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
1273
- if (result && updateRange(doc, info, result.range)) {
1274
- return result;
1558
+ if (result) {
1559
+ const range = getSourceRange(doc, info, result.range);
1560
+ if (range) {
1561
+ return {
1562
+ range,
1563
+ uri: doc.uri
1564
+ };
1565
+ }
1275
1566
  }
1276
1567
  break;
1277
1568
  }
1278
1569
  },
1279
- async findReferences(doc, params) {
1570
+ findReferences(doc, params) {
1280
1571
  const infoByExt = getStyleSheetInfo(doc);
1281
1572
  const sourceOffset = doc.offsetAt(params.position);
1282
1573
  for (const ext in infoByExt) {
@@ -1287,14 +1578,38 @@ var StyleSheetService = {
1287
1578
  const { service: service2, virtualDoc } = info;
1288
1579
  const result = [];
1289
1580
  for (const location of service2.findReferences(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
1290
- if (updateRange(doc, info, location.range)) {
1291
- result.push(location);
1581
+ const range = getSourceRange(doc, info, location.range);
1582
+ if (range) {
1583
+ result.push({
1584
+ range,
1585
+ uri: location.uri
1586
+ });
1292
1587
  }
1293
1588
  }
1294
1589
  return result.length ? result : void 0;
1295
1590
  }
1296
1591
  },
1297
- async findDocumentHighlights(doc, params) {
1592
+ async findDocumentLinks(doc) {
1593
+ const infoByExt = getStyleSheetInfo(doc);
1594
+ const result = [];
1595
+ for (const ext in infoByExt) {
1596
+ const info = infoByExt[ext];
1597
+ const { service: service2, virtualDoc } = info;
1598
+ for (const link of await service2.findDocumentLinks2(virtualDoc, info.parsed, { resolveReference: resolveUrl })) {
1599
+ const range = getSourceRange(doc, info, link.range);
1600
+ if (range) {
1601
+ result.push({
1602
+ range,
1603
+ target: link.target,
1604
+ tooltip: link.tooltip,
1605
+ data: link.data
1606
+ });
1607
+ }
1608
+ }
1609
+ }
1610
+ return result.length ? result : void 0;
1611
+ },
1612
+ findDocumentHighlights(doc, params) {
1298
1613
  const infoByExt = getStyleSheetInfo(doc);
1299
1614
  const sourceOffset = doc.offsetAt(params.position);
1300
1615
  for (const ext in infoByExt) {
@@ -1305,30 +1620,36 @@ var StyleSheetService = {
1305
1620
  const { service: service2, virtualDoc } = info;
1306
1621
  const result = [];
1307
1622
  for (const highlight of service2.findDocumentHighlights(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
1308
- if (updateRange(doc, info, highlight.range)) {
1309
- result.push(highlight);
1623
+ const range = getSourceRange(doc, info, highlight.range);
1624
+ if (range) {
1625
+ result.push({
1626
+ range,
1627
+ kind: highlight.kind
1628
+ });
1310
1629
  }
1311
1630
  }
1312
1631
  return result.length ? result : void 0;
1313
1632
  }
1314
1633
  },
1315
- async findDocumentColors(doc) {
1634
+ findDocumentColors(doc) {
1316
1635
  const infoByExt = getStyleSheetInfo(doc);
1317
1636
  const result = [];
1318
1637
  for (const ext in infoByExt) {
1319
1638
  const info = infoByExt[ext];
1320
1639
  const { service: service2, virtualDoc } = info;
1321
1640
  for (const colorInfo of service2.findDocumentColors(virtualDoc, info.parsed)) {
1322
- if (updateRange(doc, info, colorInfo.range)) {
1323
- result.push(colorInfo);
1641
+ const range = getSourceRange(doc, info, colorInfo.range);
1642
+ if (range) {
1643
+ result.push({
1644
+ range,
1645
+ color: colorInfo.color
1646
+ });
1324
1647
  }
1325
1648
  }
1326
1649
  }
1327
- if (result.length) {
1328
- return result;
1329
- }
1650
+ return result.length ? result : void 0;
1330
1651
  },
1331
- async getColorPresentations(doc, params) {
1652
+ getColorPresentations(doc, params) {
1332
1653
  const infoByExt = getStyleSheetInfo(doc);
1333
1654
  const sourceOffset = doc.offsetAt(params.range.start);
1334
1655
  for (const ext in infoByExt) {
@@ -1340,21 +1661,22 @@ var StyleSheetService = {
1340
1661
  if (generatedOffsetEnd === void 0)
1341
1662
  continue;
1342
1663
  const { service: service2, virtualDoc } = info;
1343
- const result = service2.getColorPresentations(virtualDoc, info.parsed, params.color, import_vscode_languageserver10.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)));
1344
- for (const colorPresentation of result) {
1345
- if (colorPresentation.textEdit) {
1346
- updateTextEdit(doc, info, colorPresentation.textEdit);
1347
- }
1348
- if (colorPresentation.additionalTextEdits) {
1349
- for (const textEdit of colorPresentation.additionalTextEdits) {
1350
- updateTextEdit(doc, info, textEdit);
1351
- }
1664
+ const result = [];
1665
+ for (const colorPresentation of service2.getColorPresentations(virtualDoc, info.parsed, params.color, import_vscode_languageserver13.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)))) {
1666
+ const textEdit = colorPresentation.textEdit && getSourceEdit(doc, info, colorPresentation.textEdit);
1667
+ const additionalTextEdits = colorPresentation.additionalTextEdits && getSourceEdits(doc, info, colorPresentation.additionalTextEdits);
1668
+ if (textEdit || additionalTextEdits) {
1669
+ result.push({
1670
+ label: colorPresentation.label,
1671
+ textEdit,
1672
+ additionalTextEdits
1673
+ });
1352
1674
  }
1353
1675
  }
1354
- return result;
1676
+ return result.length ? result : void 0;
1355
1677
  }
1356
1678
  },
1357
- async doHover(doc, params) {
1679
+ doHover(doc, params) {
1358
1680
  const infoByExt = getStyleSheetInfo(doc);
1359
1681
  const sourceOffset = doc.offsetAt(params.position);
1360
1682
  for (const ext in infoByExt) {
@@ -1364,8 +1686,18 @@ var StyleSheetService = {
1364
1686
  continue;
1365
1687
  const { service: service2, virtualDoc } = info;
1366
1688
  const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
1367
- if (result && (!result.range || updateRange(doc, info, result.range))) {
1368
- return result;
1689
+ if (result) {
1690
+ if (result.range) {
1691
+ const range = getSourceRange(doc, info, result.range);
1692
+ if (range) {
1693
+ return {
1694
+ range,
1695
+ contents: result.contents
1696
+ };
1697
+ }
1698
+ } else {
1699
+ return result;
1700
+ }
1369
1701
  }
1370
1702
  }
1371
1703
  },
@@ -1382,19 +1714,15 @@ var StyleSheetService = {
1382
1714
  if (result.changes) {
1383
1715
  for (const uri in result.changes) {
1384
1716
  if (uri === doc.uri) {
1385
- for (const textEdit of result.changes[uri]) {
1386
- updateTextEdit(doc, info, textEdit);
1387
- }
1717
+ result.changes[uri] = getSourceEdits(doc, info, result.changes[uri]) || [];
1388
1718
  }
1389
1719
  }
1390
1720
  }
1391
1721
  if (result.documentChanges) {
1392
1722
  for (const change of result.documentChanges) {
1393
- if (import_vscode_languageserver10.TextDocumentEdit.is(change)) {
1723
+ if (import_vscode_languageserver13.TextDocumentEdit.is(change)) {
1394
1724
  if (change.textDocument.uri === doc.uri) {
1395
- for (const textEdit of change.edits) {
1396
- updateTextEdit(doc, info, textEdit);
1397
- }
1725
+ change.edits = getSourceEdits(doc, info, change.edits) || [];
1398
1726
  }
1399
1727
  }
1400
1728
  }
@@ -1402,7 +1730,7 @@ var StyleSheetService = {
1402
1730
  return result;
1403
1731
  }
1404
1732
  },
1405
- async doCodeActions(doc, params) {
1733
+ doCodeActions(doc, params) {
1406
1734
  var _a;
1407
1735
  const infoByExt = getStyleSheetInfo(doc);
1408
1736
  const sourceOffset = doc.offsetAt(params.range.start);
@@ -1415,65 +1743,100 @@ var StyleSheetService = {
1415
1743
  if (generatedOffsetEnd === void 0)
1416
1744
  continue;
1417
1745
  const { service: service2, virtualDoc } = info;
1418
- const result = service2.doCodeActions(virtualDoc, import_vscode_languageserver10.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
1419
- if (result) {
1420
- for (const command of result) {
1421
- const edits = (_a = command.arguments) == null ? void 0 : _a[2];
1422
- if (edits) {
1423
- for (const textEdit of edits) {
1424
- updateTextEdit(doc, info, textEdit);
1425
- }
1426
- }
1746
+ const result = service2.doCodeActions(virtualDoc, import_vscode_languageserver13.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
1747
+ for (const command of result) {
1748
+ const edits = (_a = command.arguments) == null ? void 0 : _a[2];
1749
+ if (edits && Array.isArray(edits) && isTextEdit(edits[0])) {
1750
+ command.arguments[2] = getSourceEdits(doc, info, edits);
1427
1751
  }
1428
- return result;
1429
1752
  }
1753
+ return result;
1430
1754
  }
1431
1755
  },
1432
- async doValidate(doc) {
1756
+ doValidate(doc) {
1433
1757
  const infoByExt = getStyleSheetInfo(doc);
1434
1758
  const result = [];
1435
1759
  for (const ext in infoByExt) {
1436
1760
  const info = infoByExt[ext];
1437
1761
  for (const diag of info.service.doValidation(info.virtualDoc, info.parsed)) {
1438
- if (updateRange(doc, info, diag.range)) {
1762
+ const range = getSourceRange(doc, info, diag.range);
1763
+ if (range) {
1764
+ diag.range = range;
1439
1765
  result.push(diag);
1440
1766
  }
1441
1767
  }
1442
1768
  }
1443
- return result;
1769
+ return result.length ? result : void 0;
1444
1770
  }
1445
1771
  };
1446
- function updateTextEdit(doc, info, textEdit) {
1447
- if (!updateRange(doc, info, textEdit.range)) {
1448
- textEdit.newText = "";
1449
- textEdit.range = START_OF_FILE;
1772
+ function getSourceEdits(doc, info, edits) {
1773
+ const result = [];
1774
+ for (const edit of edits) {
1775
+ const sourceEdit = getSourceEdit(doc, info, edit);
1776
+ if (sourceEdit) {
1777
+ result.push(sourceEdit);
1778
+ }
1450
1779
  }
1780
+ return result.length ? result : void 0;
1451
1781
  }
1452
- function updateInsertReplaceEdit(doc, info, insertReplaceEdit) {
1453
- if (!updateRange(doc, info, insertReplaceEdit.insert)) {
1454
- insertReplaceEdit.newText = "";
1455
- insertReplaceEdit.insert = START_OF_FILE;
1782
+ function getSourceEdit(doc, info, textEdit) {
1783
+ const range = getSourceRange(doc, info, textEdit.range);
1784
+ if (range) {
1785
+ return {
1786
+ newText: textEdit.newText,
1787
+ range
1788
+ };
1456
1789
  }
1457
1790
  }
1458
- function updateRange(doc, info, range) {
1791
+ function getSourceInsertReplaceEdit(doc, info, textEdit) {
1792
+ if (isTextEdit(textEdit)) {
1793
+ return getSourceEdit(doc, info, textEdit);
1794
+ } else if (textEdit.replace) {
1795
+ const range = getSourceRange(doc, info, textEdit.replace);
1796
+ if (range) {
1797
+ return {
1798
+ newText: textEdit.newText,
1799
+ replace: range
1800
+ };
1801
+ }
1802
+ } else {
1803
+ const range = getSourceRange(doc, info, textEdit.insert);
1804
+ if (range) {
1805
+ return {
1806
+ newText: textEdit.newText,
1807
+ insert: range
1808
+ };
1809
+ }
1810
+ }
1811
+ }
1812
+ function getSourceRange(doc, info, range) {
1459
1813
  const start = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.start));
1460
- const end = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.end));
1461
- if (start !== void 0 || end !== void 0) {
1462
- range.start = doc.positionAt(start ?? end);
1463
- range.end = doc.positionAt(end ?? start);
1464
- return true;
1814
+ if (start === void 0)
1815
+ return;
1816
+ let end = start;
1817
+ if (range.start.line !== range.end.line || range.start.character !== range.end.character) {
1818
+ end = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.end));
1819
+ if (end === void 0)
1820
+ return;
1465
1821
  }
1466
- return false;
1822
+ const pos = doc.positionAt(start);
1823
+ return {
1824
+ start: pos,
1825
+ end: start === end ? pos : doc.positionAt(end)
1826
+ };
1467
1827
  }
1468
1828
  function getStyleSheetInfo(doc) {
1469
1829
  var _a;
1470
1830
  const parsed = parse2(doc);
1471
- let cached = cache.get(parsed);
1831
+ let cached = cache2.get(parsed);
1472
1832
  if (!cached) {
1473
1833
  const results = extractStyleSheets(doc.getText(), parsed.program, getCompilerInfo(doc).lookup);
1474
1834
  cached = {};
1475
1835
  for (const ext in results) {
1476
- const service2 = (_a = services[ext]) == null ? void 0 : _a.call(services);
1836
+ const service2 = (_a = services[ext]) == null ? void 0 : _a.call(services, {
1837
+ fileSystemProvider: file_system_default,
1838
+ clientCapabilities
1839
+ });
1477
1840
  if (!service2)
1478
1841
  continue;
1479
1842
  const { generated, sourceOffsetAt, generatedOffsetAt } = results[ext];
@@ -1486,60 +1849,65 @@ function getStyleSheetInfo(doc) {
1486
1849
  parsed: service2.parseStylesheet(virtualDoc)
1487
1850
  };
1488
1851
  }
1489
- cache.set(parsed, cached);
1852
+ cache2.set(parsed, cached);
1490
1853
  }
1491
1854
  return cached;
1492
1855
  }
1856
+ function isTextEdit(edit) {
1857
+ return edit.range !== void 0;
1858
+ }
1493
1859
 
1494
1860
  // src/service/index.ts
1495
1861
  var plugins = [marko_default, StyleSheetService];
1496
1862
  var service = {
1863
+ async initialize(params) {
1864
+ await Promise.all(plugins.map((plugin) => {
1865
+ var _a;
1866
+ return (_a = plugin.initialize) == null ? void 0 : _a.call(plugin, params);
1867
+ }));
1868
+ },
1497
1869
  async doComplete(doc, params, cancel) {
1498
- const result = import_vscode_languageserver11.CompletionList.create([], false);
1870
+ let items;
1871
+ let isIncomplete = false;
1499
1872
  try {
1500
- const requests = plugins.map((plugin) => {
1873
+ for (const pending of plugins.map((plugin) => {
1501
1874
  var _a;
1502
1875
  return (_a = plugin.doComplete) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1503
- });
1504
- for (const pending of requests) {
1876
+ })) {
1505
1877
  const cur = await pending;
1506
1878
  if (cancel.isCancellationRequested)
1507
1879
  return;
1508
1880
  if (cur) {
1509
- let items;
1881
+ let curItems;
1510
1882
  if (Array.isArray(cur)) {
1511
- items = cur;
1883
+ curItems = cur;
1512
1884
  } else {
1513
- items = cur.items;
1514
- result.isIncomplete || (result.isIncomplete = cur.isIncomplete);
1885
+ curItems = cur.items;
1886
+ isIncomplete || (isIncomplete = cur.isIncomplete);
1515
1887
  }
1516
- result.items.push(...items);
1888
+ items = items ? items.concat(curItems) : curItems;
1517
1889
  }
1518
1890
  }
1519
1891
  } catch (err) {
1520
- result.isIncomplete = true;
1892
+ isIncomplete = true;
1521
1893
  displayError(err);
1522
1894
  }
1523
- return result;
1895
+ if (items) {
1896
+ return import_vscode_languageserver14.CompletionList.create(items, isIncomplete);
1897
+ }
1524
1898
  },
1525
1899
  async findDefinition(doc, params, cancel) {
1526
- const result = [];
1900
+ let result;
1527
1901
  try {
1528
- const requests = plugins.map((plugin) => {
1902
+ for (const pending of plugins.map((plugin) => {
1529
1903
  var _a;
1530
1904
  return (_a = plugin.findDefinition) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1531
- });
1532
- for (const pending of requests) {
1905
+ })) {
1533
1906
  const cur = await pending;
1534
1907
  if (cancel.isCancellationRequested)
1535
1908
  return;
1536
- if (cur) {
1537
- if (Array.isArray(cur)) {
1538
- result.push(...cur);
1539
- } else {
1540
- result.push(cur);
1541
- }
1542
- }
1909
+ if (cur)
1910
+ result = (result || []).concat(cur);
1543
1911
  }
1544
1912
  } catch (err) {
1545
1913
  displayError(err);
@@ -1549,21 +1917,33 @@ var service = {
1549
1917
  async findReferences(doc, params, cancel) {
1550
1918
  let result;
1551
1919
  try {
1552
- const requests = plugins.map((plugin) => {
1920
+ for (const pending of plugins.map((plugin) => {
1553
1921
  var _a;
1554
1922
  return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1555
- });
1556
- for (const pending of requests) {
1923
+ })) {
1557
1924
  const cur = await pending;
1558
1925
  if (cancel.isCancellationRequested)
1559
1926
  return;
1560
- if (cur) {
1561
- if (result) {
1562
- result.push(...cur);
1563
- } else {
1564
- result = cur;
1565
- }
1566
- }
1927
+ if (cur)
1928
+ result = result ? result.concat(cur) : cur;
1929
+ }
1930
+ } catch (err) {
1931
+ displayError(err);
1932
+ }
1933
+ return result;
1934
+ },
1935
+ async findDocumentLinks(doc, params, cancel) {
1936
+ let result;
1937
+ try {
1938
+ for (const pending of plugins.map((plugin) => {
1939
+ var _a;
1940
+ return (_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1941
+ })) {
1942
+ const cur = await pending;
1943
+ if (cancel.isCancellationRequested)
1944
+ return;
1945
+ if (cur)
1946
+ result = result ? result.concat(cur) : cur;
1567
1947
  }
1568
1948
  } catch (err) {
1569
1949
  displayError(err);
@@ -1573,21 +1953,15 @@ var service = {
1573
1953
  async findDocumentHighlights(doc, params, cancel) {
1574
1954
  let result;
1575
1955
  try {
1576
- const requests = plugins.map((plugin) => {
1956
+ for (const pending of plugins.map((plugin) => {
1577
1957
  var _a;
1578
1958
  return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1579
- });
1580
- for (const pending of requests) {
1959
+ })) {
1581
1960
  const cur = await pending;
1582
1961
  if (cancel.isCancellationRequested)
1583
1962
  return;
1584
- if (cur) {
1585
- if (result) {
1586
- result.push(...cur);
1587
- } else {
1588
- result = cur;
1589
- }
1590
- }
1963
+ if (cur)
1964
+ result = result ? result.concat(cur) : cur;
1591
1965
  }
1592
1966
  } catch (err) {
1593
1967
  displayError(err);
@@ -1597,21 +1971,15 @@ var service = {
1597
1971
  async findDocumentColors(doc, params, cancel) {
1598
1972
  let result;
1599
1973
  try {
1600
- const requests = plugins.map((plugin) => {
1974
+ for (const pending of plugins.map((plugin) => {
1601
1975
  var _a;
1602
1976
  return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1603
- });
1604
- for (const pending of requests) {
1977
+ })) {
1605
1978
  const cur = await pending;
1606
1979
  if (cancel.isCancellationRequested)
1607
1980
  return;
1608
- if (cur) {
1609
- if (result) {
1610
- result.push(...cur);
1611
- } else {
1612
- result = cur;
1613
- }
1614
- }
1981
+ if (cur)
1982
+ result = result ? result.concat(cur) : cur;
1615
1983
  }
1616
1984
  } catch (err) {
1617
1985
  displayError(err);
@@ -1621,21 +1989,15 @@ var service = {
1621
1989
  async getColorPresentations(doc, params, cancel) {
1622
1990
  let result;
1623
1991
  try {
1624
- const requests = plugins.map((plugin) => {
1992
+ for (const pending of plugins.map((plugin) => {
1625
1993
  var _a;
1626
1994
  return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1627
- });
1628
- for (const pending of requests) {
1995
+ })) {
1629
1996
  const cur = await pending;
1630
1997
  if (cancel.isCancellationRequested)
1631
1998
  return;
1632
- if (cur) {
1633
- if (result) {
1634
- result.push(...cur);
1635
- } else {
1636
- result = cur;
1637
- }
1638
- }
1999
+ if (cur)
2000
+ result = result ? result.concat(cur) : cur;
1639
2001
  }
1640
2002
  } catch (err) {
1641
2003
  displayError(err);
@@ -1661,41 +2023,32 @@ var service = {
1661
2023
  let changeAnnotations;
1662
2024
  let documentChanges;
1663
2025
  try {
1664
- const requests = plugins.map((plugin) => {
2026
+ for (const pending of plugins.map((plugin) => {
1665
2027
  var _a;
1666
2028
  return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1667
- });
1668
- for (const pending of requests) {
2029
+ })) {
1669
2030
  const cur = await pending;
1670
2031
  if (cancel.isCancellationRequested)
1671
2032
  return;
1672
2033
  if (cur) {
1673
2034
  if (cur.changes) {
1674
2035
  if (changes) {
2036
+ changes = { ...changes };
1675
2037
  for (const uri in cur.changes) {
1676
- if (changes[uri]) {
1677
- changes[uri].push(...cur.changes[uri]);
1678
- } else {
1679
- changes[uri] = cur.changes[uri];
1680
- }
2038
+ changes[uri] = changes[uri] ? changes[uri].concat(cur.changes[uri]) : cur.changes[uri];
1681
2039
  }
1682
2040
  } else {
1683
2041
  changes = cur.changes;
1684
2042
  }
1685
2043
  }
1686
2044
  if (cur.changeAnnotations) {
1687
- if (changeAnnotations) {
1688
- Object.assign(changeAnnotations, cur.changeAnnotations);
1689
- } else {
1690
- changeAnnotations = cur.changeAnnotations;
1691
- }
2045
+ changeAnnotations = changeAnnotations ? {
2046
+ ...changeAnnotations,
2047
+ ...cur.changeAnnotations
2048
+ } : cur.changeAnnotations;
1692
2049
  }
1693
2050
  if (cur.documentChanges) {
1694
- if (documentChanges) {
1695
- documentChanges.push(...cur.documentChanges);
1696
- } else {
1697
- documentChanges = cur.documentChanges;
1698
- }
2051
+ documentChanges = documentChanges ? documentChanges.concat(cur.documentChanges) : cur.documentChanges;
1699
2052
  }
1700
2053
  }
1701
2054
  }
@@ -1711,19 +2064,17 @@ var service = {
1711
2064
  }
1712
2065
  },
1713
2066
  async doCodeActions(doc, params, cancel) {
1714
- const result = [];
2067
+ let result;
1715
2068
  try {
1716
- const requests = plugins.map((plugin) => {
2069
+ for (const pending of plugins.map((plugin) => {
1717
2070
  var _a;
1718
2071
  return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1719
- });
1720
- for (const pending of requests) {
2072
+ })) {
1721
2073
  const cur = await pending;
1722
2074
  if (cancel.isCancellationRequested)
1723
2075
  return;
1724
- if (cur) {
1725
- result.push(...cur);
1726
- }
2076
+ if (cur)
2077
+ result = result ? result.concat(cur) : cur;
1727
2078
  }
1728
2079
  } catch (err) {
1729
2080
  displayError(err);
@@ -1731,16 +2082,15 @@ var service = {
1731
2082
  return result;
1732
2083
  },
1733
2084
  async doValidate(doc) {
1734
- const result = [];
2085
+ let result;
1735
2086
  try {
1736
- const requests = plugins.map((plugin) => {
2087
+ for (const pending of plugins.map((plugin) => {
1737
2088
  var _a;
1738
2089
  return (_a = plugin.doValidate) == null ? void 0 : _a.call(plugin, doc);
1739
- });
1740
- for (const pending of requests) {
2090
+ })) {
1741
2091
  const cur = await pending;
1742
2092
  if (cur)
1743
- result.push(...cur);
2093
+ result = result ? result.concat(cur) : cur;
1744
2094
  }
1745
2095
  } catch (err) {
1746
2096
  displayError(err);
@@ -1767,8 +2117,9 @@ console.error = (...args) => {
1767
2117
  };
1768
2118
  process.on("uncaughtException", console.error);
1769
2119
  process.on("unhandledRejection", console.error);
1770
- connection2.onInitialize(() => {
2120
+ connection2.onInitialize(async (params) => {
1771
2121
  setup(connection2);
2122
+ await service.initialize(params);
1772
2123
  return {
1773
2124
  capabilities: {
1774
2125
  textDocumentSync: import_node.TextDocumentSyncKind.Incremental,
@@ -1778,6 +2129,7 @@ connection2.onInitialize(() => {
1778
2129
  renameProvider: true,
1779
2130
  codeActionProvider: true,
1780
2131
  referencesProvider: true,
2132
+ documentLinkProvider: { resolveProvider: false },
1781
2133
  colorProvider: true,
1782
2134
  documentHighlightProvider: true,
1783
2135
  completionProvider: {
@@ -1822,6 +2174,9 @@ connection2.onDefinition(async (params, cancel) => {
1822
2174
  connection2.onReferences(async (params, cancel) => {
1823
2175
  return await service.findReferences(documents.get(params.textDocument.uri), params, cancel) || null;
1824
2176
  });
2177
+ connection2.onDocumentLinks(async (params, cancel) => {
2178
+ return await service.findDocumentLinks(documents.get(params.textDocument.uri), params, cancel) || null;
2179
+ });
1825
2180
  connection2.onDocumentHighlight(async (params, cancel) => {
1826
2181
  return await service.findDocumentHighlights(documents.get(params.textDocument.uri), params, cancel) || null;
1827
2182
  });