@marko/language-server 0.12.10 → 0.12.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -857,7 +857,7 @@ function AttrName({
857
857
  }
858
858
 
859
859
  // src/service/marko/complete/AttrValue.ts
860
- import path4 from "path";
860
+ import path3 from "path";
861
861
  import {
862
862
  CompletionItemKind as CompletionItemKind4,
863
863
  Range as Range2,
@@ -890,20 +890,20 @@ function isDocumentLinkAttr(doc, tag, attr) {
890
890
  }
891
891
 
892
892
  // src/utils/file-system.ts
893
- import path3 from "path";
894
893
  import fs from "fs/promises";
895
894
  import { FileType } from "vscode-css-languageservice";
895
+ import { fileURLToPath } from "url";
896
896
  var file_system_default = {
897
897
  stat,
898
898
  readDirectory
899
899
  };
900
- async function stat(fileName) {
901
- const stat2 = await fs.stat(fileName).catch(() => null);
900
+ async function stat(uri) {
902
901
  let type = FileType.Unknown;
903
- let ctime = 0;
904
- let mtime = 0;
905
- let size = 0;
906
- if (stat2) {
902
+ let ctime = -1;
903
+ let mtime = -1;
904
+ let size = -1;
905
+ try {
906
+ const stat2 = await fs.stat(fileURLToPath(uri));
907
907
  if (stat2.isDirectory())
908
908
  type = FileType.Directory;
909
909
  else if (stat2.isFile())
@@ -911,6 +911,7 @@ async function stat(fileName) {
911
911
  ctime = stat2.ctimeMs;
912
912
  mtime = stat2.mtimeMs;
913
913
  size = stat2.size;
914
+ } catch {
914
915
  }
915
916
  return {
916
917
  type,
@@ -919,20 +920,22 @@ async function stat(fileName) {
919
920
  size
920
921
  };
921
922
  }
922
- async function readDirectory(dir) {
923
- return (await Promise.all((await fs.readdir(dir).catch(() => [])).map(async (entry) => [entry, (await stat(path3.join(dir, entry))).type]))).filter(([, type]) => type !== FileType.Unknown);
923
+ async function readDirectory(uri) {
924
+ try {
925
+ const entries = await fs.readdir(fileURLToPath(uri));
926
+ const base = uri.at(-1) === "/" ? uri : `${uri}/`;
927
+ return (await Promise.all(entries.map(async (entry) => [entry, (await stat(new URL(entry, base).toString())).type]))).filter(([, type]) => type !== FileType.Unknown);
928
+ } catch {
929
+ return [];
930
+ }
924
931
  }
925
932
 
926
933
  // src/utils/resolve-url.ts
927
934
  function resolveUrl(to, base) {
928
935
  try {
929
- const baseUrl = new URL(base, "file://");
930
- const resolved = new URL(to, baseUrl);
931
- const { origin, protocol } = baseUrl;
932
- if (resolved.origin === origin && resolved.protocol === protocol) {
933
- return resolved.pathname + resolved.search + resolved.hash;
934
- }
935
- return resolved.toString();
936
+ const url = new URL(to, base);
937
+ if (url.protocol === "file:")
938
+ return url.toString();
936
939
  } catch {
937
940
  return void 0;
938
941
  }
@@ -957,28 +960,29 @@ async function AttrValue({
957
960
  start,
958
961
  end
959
962
  });
960
- let segmentStart = rawValue.lastIndexOf("/", relativeOffset);
963
+ const segmentStart = rawValue.lastIndexOf("/", relativeOffset);
961
964
  if (segmentStart === -1)
962
- segmentStart = relativeOffset;
963
- const resolveRequest = rawValue.slice(0, segmentStart) || ".";
964
- const dir = resolveUrl(resolveRequest, document.uri);
965
- if ((dir == null ? void 0 : dir[0]) === "/") {
965
+ return;
966
+ const req = rawValue.slice(0, segmentStart);
967
+ const uri = resolveUrl(req, document.uri);
968
+ if (uri) {
966
969
  const result = [];
967
- const curDir = resolveRequest === "." ? dir : resolveUrl(".", document.uri);
968
- const curFile = curDir === dir ? path4.basename(document.uri) : void 0;
970
+ const curFile = req === "." ? path3.basename(document.uri) : void 0;
969
971
  const replaceRange = Range2.create(document.positionAt(start + segmentStart + 1), document.positionAt(start + rawValue.length));
970
- for (const [entry, type] of await file_system_default.readDirectory(dir)) {
972
+ for (const [entry, type] of await file_system_default.readDirectory(uri)) {
971
973
  if (entry[0] !== "." && entry !== curFile) {
972
- const isDir = type === FileType.Directory;
973
- const label = isDir ? `${entry}/` : entry;
974
- result.push({
975
- label,
976
- kind: isDir ? CompletionItemKind4.Folder : CompletionItemKind4.File,
977
- textEdit: TextEdit4.replace(replaceRange, label),
978
- command: isDir ? {
974
+ result.push(type === FileType.Directory ? {
975
+ label: `${entry}/`,
976
+ kind: CompletionItemKind4.Folder,
977
+ textEdit: TextEdit4.replace(replaceRange, `${entry}/`),
978
+ command: {
979
979
  title: "Suggest",
980
980
  command: "editor.action.triggerSuggest"
981
- } : void 0
981
+ }
982
+ } : {
983
+ label: entry,
984
+ kind: CompletionItemKind4.File,
985
+ textEdit: TextEdit4.replace(replaceRange, entry)
982
986
  });
983
987
  }
984
988
  }
@@ -1038,7 +1042,7 @@ var doValidate = (doc) => {
1038
1042
  };
1039
1043
 
1040
1044
  // src/service/marko/definition/OpenTagName.ts
1041
- import path5 from "path";
1045
+ import path4 from "path";
1042
1046
  import { URI as URI4 } from "vscode-uri";
1043
1047
  import { Range as Range5, LocationLink } from "vscode-languageserver";
1044
1048
 
@@ -1099,7 +1103,7 @@ function OpenTagName2({
1099
1103
  return;
1100
1104
  }
1101
1105
  const tagEntryFile = tagDef.template || tagDef.renderer || tagDef.filePath;
1102
- if (!path5.isAbsolute(tagEntryFile)) {
1106
+ if (!path4.isAbsolute(tagEntryFile)) {
1103
1107
  return;
1104
1108
  }
1105
1109
  if (/\/marko(?:-tag)?\.json$/.test(tagEntryFile)) {
@@ -1535,15 +1539,13 @@ var StyleSheetService = {
1535
1539
  return result.length ? result : void 0;
1536
1540
  }
1537
1541
  },
1538
- findDocumentLinks(doc) {
1542
+ async findDocumentLinks(doc) {
1539
1543
  const infoByExt = getStyleSheetInfo(doc);
1540
1544
  const result = [];
1541
1545
  for (const ext in infoByExt) {
1542
1546
  const info = infoByExt[ext];
1543
1547
  const { service: service2, virtualDoc } = info;
1544
- for (const link of service2.findDocumentLinks(virtualDoc, info.parsed, {
1545
- resolveReference: resolveUrl
1546
- })) {
1548
+ for (const link of await service2.findDocumentLinks2(virtualDoc, info.parsed, { resolveReference: resolveUrl })) {
1547
1549
  const range = getSourceRange(doc, info, link.range);
1548
1550
  if (range) {
1549
1551
  result.push({