@marko/language-server 1.0.6 → 1.0.8

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
@@ -25,95 +25,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  // src/index.ts
26
26
  var import_util2 = require("util");
27
27
  var import_node = require("vscode-languageserver/node");
28
-
29
- // src/utils/project.ts
30
- var import_path = __toESM(require("path"));
31
- var import_module = require("module");
32
- var defaultCompiler = __toESM(require("@marko/compiler"));
33
- var defaultTranslator = __toESM(require("@marko/translator-default"));
34
- var ignoreErrors = (_err) => {
35
- };
36
- var projectsByDir = /* @__PURE__ */ new Map();
37
- var projectsByCompiler = /* @__PURE__ */ new Map();
38
- var defaultProject = {
39
- cache: /* @__PURE__ */ new Map(),
40
- compiler: defaultCompiler,
41
- translator: defaultTranslator,
42
- getLookup(dir) {
43
- const key = `taglib:${dir}`;
44
- let lookup = defaultProject.cache.get(key);
45
- if (!lookup) {
46
- defaultProject.cache.set(
47
- key,
48
- lookup = defaultCompiler.taglib.buildLookup(
49
- dir,
50
- defaultTranslator,
51
- ignoreErrors
52
- )
53
- );
54
- }
55
- return lookup;
56
- }
57
- };
58
- defaultCompiler.configure({ translator: defaultTranslator });
59
- function getMarkoProject(dir) {
60
- if (!dir)
61
- return defaultProject;
62
- let project = projectsByDir.get(dir);
63
- if (!project) {
64
- project = loadProject(dir);
65
- projectsByDir.set(dir, project);
66
- }
67
- return project;
68
- }
69
- function getMarkoProjects() {
70
- return projectsByCompiler.values();
71
- }
72
- function clearMarkoProjectCaches() {
73
- for (const project of getMarkoProjects()) {
74
- project.cache.clear();
75
- project.compiler.taglib.clearCaches();
76
- }
77
- }
78
- function loadProject(dir) {
79
- try {
80
- const require2 = (0, import_module.createRequire)(dir);
81
- const compilerConfigPath = require2.resolve("@marko/compiler/config");
82
- const cachedProject = projectsByCompiler.get(compilerConfigPath);
83
- if (cachedProject)
84
- return cachedProject;
85
- const compiler = require2(import_path.default.join(compilerConfigPath, ".."));
86
- const translator = require2(interopDefault(require2(compilerConfigPath)).translator);
87
- const project = {
88
- cache: /* @__PURE__ */ new Map(),
89
- compiler,
90
- translator,
91
- getLookup(dir2) {
92
- const key = `taglib:${dir2}`;
93
- let lookup = project.cache.get(key);
94
- if (lookup === void 0) {
95
- try {
96
- lookup = compiler.taglib.buildLookup(dir2, translator, ignoreErrors);
97
- } catch {
98
- lookup = defaultProject.getLookup(dir2);
99
- }
100
- project.cache.set(key, lookup);
101
- }
102
- return lookup;
103
- }
104
- };
105
- projectsByCompiler.set(compilerConfigPath, project);
106
- return project;
107
- } catch {
108
- return defaultProject;
109
- }
110
- }
111
- function interopDefault(mod) {
112
- return mod.default || mod;
113
- }
28
+ var import_language_tools16 = require("@marko/language-tools");
114
29
 
115
30
  // src/utils/file.ts
116
- var import_path2 = __toESM(require("path"));
31
+ var import_path = __toESM(require("path"));
117
32
  var import_language_tools = require("@marko/language-tools");
118
33
  var import_vscode_uri = require("vscode-uri");
119
34
  var processorCaches = /* @__PURE__ */ new WeakMap();
@@ -123,19 +38,17 @@ function getFSPath(doc) {
123
38
  function getMarkoFile(doc) {
124
39
  const { uri } = doc;
125
40
  const { fsPath: filename, scheme } = import_vscode_uri.URI.parse(uri);
126
- const dirname = filename && import_path2.default.dirname(filename);
127
- const project = getMarkoProject(dirname);
128
- const cache = project.cache;
41
+ const dirname = filename && import_path.default.dirname(filename);
42
+ const cache = import_language_tools.Project.getCache(dirname);
129
43
  let file = cache.get(doc);
130
44
  if (!file) {
131
45
  const { version } = doc;
132
46
  const code = doc.getText();
133
47
  const parsed = (0, import_language_tools.parse)(code, filename);
134
- const lookup = project.getLookup(dirname);
48
+ const lookup = import_language_tools.Project.getTagLookup(dirname);
135
49
  cache.set(
136
50
  doc,
137
51
  file = {
138
- project,
139
52
  uri,
140
53
  scheme,
141
54
  version,
@@ -151,9 +64,8 @@ function getMarkoFile(doc) {
151
64
  }
152
65
  function clearMarkoCacheForFile(doc) {
153
66
  const { fsPath: filename } = import_vscode_uri.URI.parse(doc.uri);
154
- const dirname = filename && import_path2.default.dirname(filename);
155
- const project = getMarkoProject(dirname);
156
- const cache = project.cache;
67
+ const dirname = filename && import_path.default.dirname(filename);
68
+ const cache = import_language_tools.Project.getCache(dirname);
157
69
  cache.delete(doc);
158
70
  }
159
71
  function processDoc(doc, process2) {
@@ -481,7 +393,7 @@ function isExternalModule(file) {
481
393
  }
482
394
 
483
395
  // src/service/marko/complete/AttrValue.ts
484
- var import_path3 = __toESM(require("path"));
396
+ var import_path2 = __toESM(require("path"));
485
397
  var import_vscode_languageserver3 = require("vscode-languageserver");
486
398
 
487
399
  // src/service/marko/util/is-document-link-attr.ts
@@ -591,7 +503,7 @@ async function AttrValue({
591
503
  const resolved = resolveUrl(req, uri);
592
504
  if (resolved) {
593
505
  const result = [];
594
- const curFile = req === "." ? import_path3.default.basename(uri) : void 0;
506
+ const curFile = req === "." ? import_path2.default.basename(uri) : void 0;
595
507
  const replaceRange = parsed.locationAt({
596
508
  start: start + segmentStart + 1,
597
509
  end: start + rawValue.length
@@ -624,7 +536,7 @@ async function AttrValue({
624
536
  var import_vscode_languageserver5 = require("vscode-languageserver");
625
537
 
626
538
  // src/service/marko/util/get-tag-name-completion.ts
627
- var import_path4 = __toESM(require("path"));
539
+ var import_path3 = __toESM(require("path"));
628
540
  var import_vscode_languageserver4 = require("vscode-languageserver");
629
541
  var import_vscode_uri3 = require("vscode-uri");
630
542
  var deprecated = [import_vscode_languageserver4.CompletionItemTag.Deprecated];
@@ -647,7 +559,7 @@ function getTagNameCompletion({
647
559
  kind: import_vscode_languageserver4.MarkupKind.Markdown,
648
560
  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:
649
561
 
650
- [${importer ? import_path4.default.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
562
+ [${importer ? import_path3.default.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
651
563
  };
652
564
  if (tag.description) {
653
565
  documentation.value += `
@@ -833,32 +745,32 @@ var doComplete = async (doc, params) => {
833
745
  };
834
746
 
835
747
  // src/service/marko/validate.ts
836
- var import_path5 = __toESM(require("path"));
748
+ var import_path4 = __toESM(require("path"));
749
+ var import_language_tools6 = require("@marko/language-tools");
837
750
  var import_vscode_languageserver7 = require("vscode-languageserver");
838
751
  var markoErrorRegExp = /^(.+?)\.marko(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
839
752
  var doValidate = (doc) => {
840
753
  const filename = getFSPath(doc);
841
754
  const diagnostics = [];
842
- const { compiler, translator, cache } = getMarkoProject(
843
- filename && import_path5.default.dirname(filename)
844
- );
845
755
  try {
846
- compiler.compileSync(doc.getText(), filename || "untitled.marko", {
847
- cache,
848
- translator,
849
- code: false,
850
- output: "source",
851
- sourceMaps: false,
852
- babelConfig: {
853
- caller: {
854
- name: "@marko/language-server",
855
- supportsStaticESM: true,
856
- supportsDynamicImport: true,
857
- supportsTopLevelAwait: true,
858
- supportsExportNamespaceFrom: true
756
+ import_language_tools6.Project.getCompiler(filename && import_path4.default.dirname(filename)).compileSync(
757
+ doc.getText(),
758
+ filename || "untitled.marko",
759
+ {
760
+ code: false,
761
+ output: "source",
762
+ sourceMaps: false,
763
+ babelConfig: {
764
+ caller: {
765
+ name: "@marko/language-server",
766
+ supportsStaticESM: true,
767
+ supportsDynamicImport: true,
768
+ supportsTopLevelAwait: true,
769
+ supportsExportNamespaceFrom: true
770
+ }
859
771
  }
860
772
  }
861
- });
773
+ );
862
774
  } catch (e) {
863
775
  let match;
864
776
  while (match = markoErrorRegExp.exec(e.message)) {
@@ -881,7 +793,7 @@ var doValidate = (doc) => {
881
793
  };
882
794
 
883
795
  // src/service/marko/hover/index.ts
884
- var import_language_tools6 = require("@marko/language-tools");
796
+ var import_language_tools7 = require("@marko/language-tools");
885
797
 
886
798
  // src/utils/constants.ts
887
799
  var START_POSITION = {
@@ -925,7 +837,7 @@ var doHover = async (doc, params) => {
925
837
  const file = getMarkoFile(doc);
926
838
  const offset = doc.offsetAt(params.position);
927
839
  const node = file.parsed.nodeAt(offset);
928
- return await ((_a = handlers2[import_language_tools6.NodeType[node.type]]) == null ? void 0 : _a.call(handlers2, {
840
+ return await ((_a = handlers2[import_language_tools7.NodeType[node.type]]) == null ? void 0 : _a.call(handlers2, {
929
841
  file,
930
842
  params,
931
843
  offset,
@@ -934,12 +846,12 @@ var doHover = async (doc, params) => {
934
846
  };
935
847
 
936
848
  // src/service/marko/definition/index.ts
937
- var import_language_tools9 = require("@marko/language-tools");
849
+ var import_language_tools10 = require("@marko/language-tools");
938
850
 
939
851
  // src/service/marko/definition/AttrName.ts
940
852
  var import_fs2 = __toESM(require("fs"));
941
853
  var import_vscode_uri4 = require("vscode-uri");
942
- var import_language_tools7 = require("@marko/language-tools");
854
+ var import_language_tools8 = require("@marko/language-tools");
943
855
 
944
856
  // src/utils/regexp-builder.ts
945
857
  function RegExpBuilder(strings, ...expressions) {
@@ -988,8 +900,8 @@ function AttrName2({
988
900
  tagDefSource
989
901
  );
990
902
  if (match && match.index) {
991
- range = (0, import_language_tools7.getLocation)(
992
- (0, import_language_tools7.getLines)(tagDefSource),
903
+ range = (0, import_language_tools8.getLocation)(
904
+ (0, import_language_tools8.getLines)(tagDefSource),
993
905
  match.index,
994
906
  match.index + match[0].length
995
907
  );
@@ -1007,9 +919,9 @@ function AttrName2({
1007
919
 
1008
920
  // src/service/marko/definition/OpenTagName.ts
1009
921
  var import_fs3 = __toESM(require("fs"));
1010
- var import_path6 = __toESM(require("path"));
922
+ var import_path5 = __toESM(require("path"));
1011
923
  var import_vscode_uri5 = require("vscode-uri");
1012
- var import_language_tools8 = require("@marko/language-tools");
924
+ var import_language_tools9 = require("@marko/language-tools");
1013
925
  function OpenTagName3({
1014
926
  node,
1015
927
  file: { parsed, lookup }
@@ -1017,9 +929,9 @@ function OpenTagName3({
1017
929
  const tag = node.parent;
1018
930
  let tagDef;
1019
931
  let range = START_LOCATION;
1020
- if (tag.type === import_language_tools8.NodeType.AttrTag) {
932
+ if (tag.type === import_language_tools9.NodeType.AttrTag) {
1021
933
  let parentTag = tag.owner;
1022
- while ((parentTag == null ? void 0 : parentTag.type) === import_language_tools8.NodeType.AttrTag)
934
+ while ((parentTag == null ? void 0 : parentTag.type) === import_language_tools9.NodeType.AttrTag)
1023
935
  parentTag = parentTag.owner;
1024
936
  tagDef = parentTag && parentTag.nameText ? lookup.getTag(parentTag.nameText) : void 0;
1025
937
  } else {
@@ -1029,7 +941,7 @@ function OpenTagName3({
1029
941
  return;
1030
942
  }
1031
943
  const tagEntryFile = tagDef.template || tagDef.renderer || tagDef.filePath;
1032
- if (!import_path6.default.isAbsolute(tagEntryFile)) {
944
+ if (!import_path5.default.isAbsolute(tagEntryFile)) {
1033
945
  return;
1034
946
  }
1035
947
  if (/\/marko(?:-tag)?\.json$/.test(tagEntryFile)) {
@@ -1038,8 +950,8 @@ function OpenTagName3({
1038
950
  tagDefSource
1039
951
  );
1040
952
  if (match && match.index) {
1041
- range = (0, import_language_tools8.getLocation)(
1042
- (0, import_language_tools8.getLines)(tagDefSource),
953
+ range = (0, import_language_tools9.getLocation)(
954
+ (0, import_language_tools9.getLines)(tagDefSource),
1043
955
  match.index,
1044
956
  match.index + match[0].length
1045
957
  );
@@ -1065,7 +977,7 @@ var findDefinition = async (doc, params) => {
1065
977
  const file = getMarkoFile(doc);
1066
978
  const offset = doc.offsetAt(params.position);
1067
979
  const node = file.parsed.nodeAt(offset);
1068
- return await ((_a = handlers3[import_language_tools9.NodeType[node.type]]) == null ? void 0 : _a.call(handlers3, {
980
+ return await ((_a = handlers3[import_language_tools10.NodeType[node.type]]) == null ? void 0 : _a.call(handlers3, {
1069
981
  file,
1070
982
  params,
1071
983
  offset,
@@ -1074,7 +986,7 @@ var findDefinition = async (doc, params) => {
1074
986
  };
1075
987
 
1076
988
  // src/service/marko/document-links.ts
1077
- var import_language_tools10 = require("@marko/language-tools");
989
+ var import_language_tools11 = require("@marko/language-tools");
1078
990
  var importTagReg2 = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
1079
991
  var findDocumentLinks = async (doc) => {
1080
992
  return processDoc(doc, extractDocumentLinks);
@@ -1093,14 +1005,14 @@ function extractDocumentLinks({
1093
1005
  const { program, read } = parsed;
1094
1006
  const visit = (node) => {
1095
1007
  switch (node.type) {
1096
- case import_language_tools10.NodeType.AttrTag:
1008
+ case import_language_tools11.NodeType.AttrTag:
1097
1009
  if (node.body) {
1098
1010
  for (const child of node.body) {
1099
1011
  visit(child);
1100
1012
  }
1101
1013
  }
1102
1014
  break;
1103
- case import_language_tools10.NodeType.Tag:
1015
+ case import_language_tools11.NodeType.Tag:
1104
1016
  if (node.attrs && node.nameText) {
1105
1017
  for (const attr of node.attrs) {
1106
1018
  if (isDocumentLinkAttr(code, node, attr)) {
@@ -1126,7 +1038,7 @@ function extractDocumentLinks({
1126
1038
  }
1127
1039
  };
1128
1040
  for (const node of program.static) {
1129
- if (node.type === import_language_tools10.NodeType.Import) {
1041
+ if (node.type === import_language_tools11.NodeType.Import) {
1130
1042
  importTagReg2.lastIndex = 0;
1131
1043
  const value = parsed.read(node);
1132
1044
  const match = importTagReg2.exec(value);
@@ -1154,7 +1066,7 @@ function extractDocumentLinks({
1154
1066
 
1155
1067
  // src/service/marko/document-symbols.ts
1156
1068
  var import_vscode_languageserver8 = require("vscode-languageserver");
1157
- var import_language_tools11 = require("@marko/language-tools");
1069
+ var import_language_tools12 = require("@marko/language-tools");
1158
1070
  var findDocumentSymbols = async (doc) => processDoc(doc, extractDocumentSymbols);
1159
1071
  function extractDocumentSymbols({
1160
1072
  uri,
@@ -1170,10 +1082,10 @@ function extractDocumentSymbols({
1170
1082
  const visit = (node) => {
1171
1083
  var _a, _b;
1172
1084
  switch (node.type) {
1173
- case import_language_tools11.NodeType.Tag:
1174
- case import_language_tools11.NodeType.AttrTag:
1085
+ case import_language_tools12.NodeType.Tag:
1086
+ case import_language_tools12.NodeType.AttrTag:
1175
1087
  symbols.push({
1176
- name: (node.type === import_language_tools11.NodeType.AttrTag ? (_a = node.nameText) == null ? void 0 : _a.slice(node.nameText.indexOf("@")) : node.nameText) || "<${...}>",
1088
+ name: (node.type === import_language_tools12.NodeType.AttrTag ? (_a = node.nameText) == null ? void 0 : _a.slice(node.nameText.indexOf("@")) : node.nameText) || "<${...}>",
1177
1089
  kind: node.nameText && ((_b = lookup.getTag(node.nameText)) == null ? void 0 : _b.html) && import_vscode_languageserver8.SymbolKind.Property || import_vscode_languageserver8.SymbolKind.Class,
1178
1090
  location: {
1179
1091
  uri,
@@ -1241,7 +1153,7 @@ var marko_default = {
1241
1153
  };
1242
1154
 
1243
1155
  // src/service/script/index.ts
1244
- var import_path10 = __toESM(require("path"));
1156
+ var import_path7 = __toESM(require("path"));
1245
1157
  var import_relative_import_path = require("relative-import-path");
1246
1158
  var import_tsserverlibrary = __toESM(require("typescript/lib/tsserverlibrary"));
1247
1159
  var import_vscode_languageserver10 = require("vscode-languageserver");
@@ -1250,209 +1162,109 @@ var prettier2 = __toESM(require("prettier"));
1250
1162
  var import_language_tools14 = require("@marko/language-tools");
1251
1163
 
1252
1164
  // src/ts-plugin/host.ts
1253
- var import_path9 = __toESM(require("path"));
1165
+ var import_path6 = __toESM(require("path"));
1254
1166
  var import_language_tools13 = require("@marko/language-tools");
1255
-
1256
- // src/utils/get-runtime-types.ts
1257
- var import_path7 = __toESM(require("path"));
1258
- var internalTypesFile = import_path7.default.join(__dirname, "marko.internal.d.ts");
1259
- var defaultMarkoTypesFile = import_path7.default.join(__dirname, "marko.runtime.d.ts");
1260
- function getProjectTypeLibs(rootDir, project, ts2, host) {
1261
- let cached = project.cache.get(getProjectTypeLibs);
1262
- if (cached === void 0) {
1263
- const markoRunGeneratedTypesFile = import_path7.default.join(
1264
- rootDir,
1265
- ".marko-run/routes.d.ts"
1266
- );
1267
- const resolveFromFile = import_path7.default.join(host.getCurrentDirectory(), "_.d.ts");
1268
- const compilerOptions = host.getCompilationSettings();
1269
- const { resolvedTypeReferenceDirective: resolvedMarkoTypes } = ts2.resolveTypeReferenceDirective(
1270
- project.translator.runtimeTypes || "marko",
1271
- resolveFromFile,
1272
- compilerOptions,
1273
- host
1274
- );
1275
- const { resolvedTypeReferenceDirective: resolvedMarkoRunTypes } = ts2.resolveTypeReferenceDirective(
1276
- "@marko/run",
1277
- resolveFromFile,
1278
- compilerOptions,
1279
- host
1280
- );
1281
- const markoTypesFile = (resolvedMarkoTypes == null ? void 0 : resolvedMarkoTypes.resolvedFileName) || defaultMarkoTypesFile;
1282
- const markoRunTypesFile = resolvedMarkoRunTypes == null ? void 0 : resolvedMarkoRunTypes.resolvedFileName;
1283
- cached = {
1284
- internalTypesFile,
1285
- markoTypesFile,
1286
- markoTypesCode: host.readFile(markoTypesFile, "utf-8") || "",
1287
- markoRunTypesFile,
1288
- markoRunGeneratedTypesFile: host.fileExists(markoRunGeneratedTypesFile) ? markoRunGeneratedTypesFile : void 0
1289
- };
1290
- project.cache.set(getProjectTypeLibs, cached);
1291
- }
1292
- return cached;
1293
- }
1294
-
1295
- // src/utils/get-script-lang.ts
1296
- var import_language_tools12 = require("@marko/language-tools");
1297
- function getScriptLang(filename, ts2, host, projectScriptLang) {
1298
- const configPath = ts2.findConfigFile(
1299
- filename,
1300
- host.fileExists.bind(host),
1301
- "marko.json"
1302
- );
1303
- if (configPath) {
1304
- try {
1305
- const markoConfig = JSON.parse(
1306
- host.readFile(configPath, "utf-8") || "{}"
1307
- );
1308
- const scriptLang = markoConfig["script-lang"] || markoConfig.scriptLang;
1309
- if (scriptLang !== void 0) {
1310
- return scriptLang === import_language_tools12.ScriptLang.ts ? import_language_tools12.ScriptLang.ts : import_language_tools12.ScriptLang.js;
1311
- }
1312
- } catch {
1313
- }
1314
- }
1315
- return /[/\\]node_modules[/\\]/.test(filename) ? import_language_tools12.ScriptLang.js : projectScriptLang;
1316
- }
1317
-
1318
- // src/utils/get-component-filename.ts
1319
- var import_fs4 = __toESM(require("fs"));
1320
- var import_path8 = __toESM(require("path"));
1321
- function getComponentFilename(from) {
1322
- const dir = import_path8.default.dirname(from);
1323
- const nameNoExt = import_path8.default.basename(from, ".marko");
1324
- const isEntry = nameNoExt === "index";
1325
- const componentFull = `${nameNoExt}.component.`;
1326
- const componentBrowserFull = `${nameNoExt}.component-browser.`;
1327
- const componentPartial = isEntry ? "component." : void 0;
1328
- const componentBrowserPartial = isEntry ? "component-browser." : void 0;
1329
- for (const entry of tryReaddirSync(dir)) {
1330
- if (entry !== from && (isEntry && entry.startsWith(componentBrowserPartial) || entry.startsWith(componentPartial)) || entry.startsWith(componentBrowserFull) || entry.startsWith(componentFull)) {
1331
- return import_path8.default.join(dir, entry);
1332
- }
1333
- }
1334
- }
1335
- function tryReaddirSync(dir) {
1336
- try {
1337
- return import_fs4.default.readdirSync(dir);
1338
- } catch {
1339
- return [];
1340
- }
1341
- }
1342
-
1343
- // src/ts-plugin/host.ts
1344
- var markoExt = ".marko";
1345
- var markoExtReg = /\.marko$/;
1346
- var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
1347
1167
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
1348
- function patch(ts2, scriptLang, cache, host, ps) {
1168
+ var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
1169
+ import_language_tools13.Project.setDefaultTypePaths({
1170
+ internalTypesFile: import_path6.default.join(__dirname, "marko.internal.d.ts"),
1171
+ markoTypesFile: import_path6.default.join(__dirname, "marko.runtime.d.ts")
1172
+ });
1173
+ function patch(ts2, configFile, extractCache2, resolutionCache, host, ps) {
1349
1174
  var _a, _b, _c;
1350
- const rootDir = host.getCurrentDirectory();
1351
- const projectTypeLibs = getProjectTypeLibs(
1352
- rootDir,
1353
- getMarkoProject(rootDir),
1354
- ts2,
1355
- host
1356
- );
1357
- const projectTypeLibsFiles = [
1358
- projectTypeLibs.internalTypesFile,
1359
- projectTypeLibs.markoTypesFile
1360
- ];
1361
- if (projectTypeLibs.markoRunTypesFile) {
1362
- projectTypeLibsFiles.push(projectTypeLibs.markoRunTypesFile);
1363
- }
1364
- if (projectTypeLibs.markoRunGeneratedTypesFile) {
1365
- projectTypeLibsFiles.push(projectTypeLibs.markoRunGeneratedTypesFile);
1366
- }
1367
- const isMarkoTSFile = (fileName) => getScriptLang(fileName, ts2, host, scriptLang) === import_language_tools13.ScriptLang.ts;
1175
+ const processors = import_language_tools13.Processors.create({
1176
+ ts: ts2,
1177
+ host,
1178
+ configFile
1179
+ });
1180
+ const rootNames = Object.values(processors).map((processor) => {
1181
+ var _a2;
1182
+ return (_a2 = processor.getRootNames) == null ? void 0 : _a2.call(processor);
1183
+ }).flat().filter(Boolean);
1368
1184
  const getScriptFileNames = host.getScriptFileNames.bind(host);
1369
1185
  host.getScriptFileNames = () => [
1370
- ...new Set(projectTypeLibsFiles.concat(getScriptFileNames()))
1186
+ ...new Set(rootNames.concat(getScriptFileNames()))
1371
1187
  ];
1372
1188
  const getScriptKind = (_a = host.getScriptKind) == null ? void 0 : _a.bind(host);
1373
1189
  if (getScriptKind) {
1374
1190
  host.getScriptKind = (fileName) => {
1375
- return markoExtReg.test(fileName) ? isMarkoTSFile(fileName) ? ts2.ScriptKind.TS : ts2.ScriptKind.JS : getScriptKind(fileName);
1191
+ const processor = getProcessor(fileName);
1192
+ if (processor)
1193
+ return processor.getScriptKind(fileName);
1194
+ return getScriptKind(fileName);
1376
1195
  };
1377
1196
  }
1378
1197
  const getScriptSnapshot = host.getScriptSnapshot.bind(host);
1379
- host.getScriptSnapshot = (filename) => {
1380
- if (markoExtReg.test(filename)) {
1381
- let cached = cache.get(filename);
1198
+ host.getScriptSnapshot = (fileName) => {
1199
+ const processor = getProcessor(fileName);
1200
+ if (processor) {
1201
+ let cached = extractCache2.get(fileName);
1382
1202
  if (!cached) {
1383
- const code = host.readFile(filename, "utf-8") || "";
1384
- const dir = import_path9.default.dirname(filename);
1203
+ const code = host.readFile(fileName, "utf-8") || "";
1385
1204
  try {
1386
- const markoProject = getMarkoProject(dir);
1387
- cached = (0, import_language_tools13.extractScript)({
1388
- ts: ts2,
1389
- parsed: (0, import_language_tools13.parse)(code, filename),
1390
- lookup: markoProject.getLookup(dir),
1391
- scriptLang: getScriptLang(filename, ts2, host, scriptLang),
1392
- runtimeTypesCode: projectTypeLibs.markoTypesCode,
1393
- componentFilename: getComponentFilename(filename)
1394
- });
1205
+ cached = processor.extract(fileName, code);
1395
1206
  cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
1396
1207
  } catch {
1397
1208
  cached = { snapshot: ts2.ScriptSnapshot.fromString("") };
1398
1209
  }
1399
1210
  ps == null ? void 0 : ps.getOrCreateScriptInfoForNormalizedPath(
1400
- filename,
1401
- false,
1211
+ fileName,
1212
+ true,
1402
1213
  void 0,
1403
1214
  ts2.ScriptKind.Deferred,
1404
1215
  false,
1405
1216
  host
1406
1217
  );
1407
- cache.set(filename, cached);
1218
+ extractCache2.set(fileName, cached);
1408
1219
  }
1409
1220
  return cached.snapshot;
1410
1221
  }
1411
- return getScriptSnapshot(filename);
1222
+ return getScriptSnapshot(fileName);
1412
1223
  };
1413
1224
  if (host.getProjectVersion) {
1414
1225
  const getScriptVersion = host.getScriptVersion.bind(host);
1415
- host.getScriptVersion = (filename) => {
1416
- if (markoExtReg.test(filename)) {
1226
+ host.getScriptVersion = (fileName) => {
1227
+ const processor = getProcessor(fileName);
1228
+ if (processor)
1417
1229
  return host.getProjectVersion();
1418
- }
1419
- return getScriptVersion(filename);
1230
+ return getScriptVersion(fileName);
1420
1231
  };
1421
1232
  }
1422
1233
  const readDirectory2 = (_b = host.readDirectory) == null ? void 0 : _b.bind(host);
1423
1234
  if (readDirectory2) {
1424
- host.readDirectory = (path11, extensions, exclude, include, depth) => {
1235
+ host.readDirectory = (path8, extensions, exclude, include, depth) => {
1425
1236
  return readDirectory2(
1426
- path11,
1427
- extensions == null ? void 0 : extensions.concat(markoExt),
1237
+ path8,
1238
+ extensions == null ? void 0 : extensions.concat(import_language_tools13.Processors.extensions),
1428
1239
  exclude,
1429
1240
  include,
1430
1241
  depth
1431
1242
  );
1432
1243
  };
1433
1244
  }
1434
- const resolveModuleNames = (_c = host.resolveModuleNames) == null ? void 0 : _c.bind(host);
1435
- if (resolveModuleNames) {
1436
- host.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, options, sourceFile) => {
1437
- let normalModuleNames = moduleNames;
1245
+ const resolveModuleNameLiterals = (_c = host.resolveModuleNameLiterals) == null ? void 0 : _c.bind(host);
1246
+ if (resolveModuleNameLiterals) {
1247
+ host.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) => {
1248
+ let normalModuleLiterals = moduleLiterals;
1438
1249
  let resolvedModules;
1439
- for (let i = 0; i < moduleNames.length; i++) {
1440
- const moduleName = moduleNames[i];
1441
- const shouldProcess = moduleName[0] !== "*" ? markoExtReg.test(moduleName) : void 0;
1442
- if (shouldProcess) {
1250
+ for (let i = 0; i < moduleLiterals.length; i++) {
1251
+ const moduleName = moduleLiterals[i].text;
1252
+ const processor = moduleName[0] !== "*" ? getProcessor(moduleName) : void 0;
1253
+ if (processor) {
1443
1254
  let resolvedFileName;
1444
1255
  if (fsPathReg.test(moduleName)) {
1445
- resolvedFileName = import_path9.default.resolve(containingFile, "..", moduleName);
1256
+ resolvedFileName = import_path6.default.resolve(containingFile, "..", moduleName);
1446
1257
  } else {
1447
1258
  const [, nodeModuleName, relativeModulePath] = modulePartsReg.exec(moduleName);
1448
- const { resolvedModule } = ts2.resolveModuleName(
1259
+ const { resolvedModule } = ts2.bundlerModuleNameResolver(
1449
1260
  `${nodeModuleName}/package.json`,
1450
1261
  containingFile,
1451
1262
  options,
1452
- host
1263
+ host,
1264
+ resolutionCache
1453
1265
  );
1454
1266
  if (resolvedModule) {
1455
- resolvedFileName = import_path9.default.join(
1267
+ resolvedFileName = import_path6.default.join(
1456
1268
  resolvedModule.resolvedFileName,
1457
1269
  "..",
1458
1270
  relativeModulePath
@@ -1461,47 +1273,54 @@ function patch(ts2, scriptLang, cache, host, ps) {
1461
1273
  }
1462
1274
  if (!resolvedModules) {
1463
1275
  resolvedModules = [];
1464
- normalModuleNames = [];
1276
+ normalModuleLiterals = [];
1465
1277
  for (let j = 0; j < i; j++) {
1466
1278
  resolvedModules.push(void 0);
1467
- normalModuleNames.push(moduleNames[j]);
1279
+ normalModuleLiterals.push(moduleLiterals[j]);
1280
+ }
1281
+ }
1282
+ if (resolvedFileName) {
1283
+ if ((0, import_language_tools13.isDefinitionFile)(resolvedFileName)) {
1284
+ if (!host.fileExists(resolvedFileName)) {
1285
+ resolvedFileName = void 0;
1286
+ }
1287
+ } else {
1288
+ const ext = (0, import_language_tools13.getExt)(resolvedFileName);
1289
+ const definitionFile = `${resolvedFileName.slice(
1290
+ 0,
1291
+ -ext.length
1292
+ )}.d${ext}`;
1293
+ if (host.fileExists(definitionFile)) {
1294
+ resolvedFileName = definitionFile;
1295
+ } else if (!host.fileExists(resolvedFileName)) {
1296
+ resolvedFileName = void 0;
1297
+ }
1468
1298
  }
1469
1299
  }
1470
- resolvedModules.push(
1471
- resolvedFileName && host.fileExists(resolvedFileName) ? {
1300
+ resolvedModules.push({
1301
+ resolvedModule: resolvedFileName ? {
1472
1302
  resolvedFileName,
1473
- extension: isMarkoTSFile(resolvedFileName) ? ts2.Extension.Ts : ts2.Extension.Js,
1303
+ extension: processor.getScriptExtension(resolvedFileName),
1474
1304
  isExternalLibraryImport: false
1475
- } : null
1476
- );
1305
+ } : void 0
1306
+ });
1477
1307
  } else if (resolvedModules) {
1478
1308
  resolvedModules.push(void 0);
1479
1309
  }
1480
1310
  }
1481
- const normalResolvedModules = normalModuleNames.length ? resolveModuleNames(
1482
- normalModuleNames,
1311
+ const normalResolvedModules = normalModuleLiterals.length ? resolveModuleNameLiterals(
1312
+ normalModuleLiterals,
1483
1313
  containingFile,
1484
- reusedNames,
1485
1314
  redirectedReference,
1486
1315
  options,
1487
- sourceFile
1316
+ containingSourceFile,
1317
+ reusedNames
1488
1318
  ) : void 0;
1489
1319
  if (resolvedModules) {
1490
1320
  if (normalResolvedModules) {
1491
1321
  for (let i = 0, j = 0; i < resolvedModules.length; i++) {
1492
- switch (resolvedModules[i]) {
1493
- case void 0:
1494
- resolvedModules[i] = normalResolvedModules[j++];
1495
- break;
1496
- case null:
1497
- resolvedModules[i] = void 0;
1498
- break;
1499
- }
1500
- }
1501
- } else {
1502
- for (let i = resolvedModules.length; i--; ) {
1503
- if (resolvedModules[i] === null) {
1504
- resolvedModules[i] = void 0;
1322
+ if (!resolvedModules[i]) {
1323
+ resolvedModules[i] = normalResolvedModules[j++];
1505
1324
  }
1506
1325
  }
1507
1326
  }
@@ -1512,6 +1331,10 @@ function patch(ts2, scriptLang, cache, host, ps) {
1512
1331
  };
1513
1332
  }
1514
1333
  return host;
1334
+ function getProcessor(fileName) {
1335
+ const ext = (0, import_language_tools13.getExt)(fileName);
1336
+ return ext ? processors[ext] : void 0;
1337
+ }
1515
1338
  }
1516
1339
 
1517
1340
  // src/service/script/index.ts
@@ -1527,12 +1350,13 @@ var colorModifierReg = /\bcolor\b/;
1527
1350
  var localInternalsPrefix = "__marko_internal_";
1528
1351
  var requiredTSCompilerOptions = {
1529
1352
  module: import_tsserverlibrary.default.ModuleKind.ESNext,
1530
- moduleResolution: import_tsserverlibrary.default.ModuleResolutionKind.NodeJs,
1353
+ moduleResolution: import_tsserverlibrary.default.ModuleResolutionKind.Bundler,
1531
1354
  noEmit: true,
1532
1355
  allowJs: true,
1533
1356
  composite: false,
1534
1357
  declaration: false,
1535
1358
  skipLibCheck: true,
1359
+ importHelpers: false,
1536
1360
  isolatedModules: true,
1537
1361
  resolveJsonModule: true,
1538
1362
  skipDefaultLibCheck: true,
@@ -1562,13 +1386,13 @@ var ScriptService = {
1562
1386
  const filename = getFSPath(doc);
1563
1387
  if (!filename)
1564
1388
  return;
1565
- const project = getTSProject(filename);
1566
- const extracted = processScript(doc, project);
1567
- const lang = getScriptLang(
1389
+ const tsProject = getTSProject(filename);
1390
+ const extracted = processScript(doc, tsProject);
1391
+ const lang = import_language_tools14.Project.getScriptLang(
1568
1392
  filename,
1393
+ tsProject.markoScriptLang,
1569
1394
  import_tsserverlibrary.default,
1570
- project.host,
1571
- project.markoScriptLang
1395
+ tsProject.host
1572
1396
  );
1573
1397
  const generated = extracted.toString();
1574
1398
  const content = (() => {
@@ -1637,7 +1461,7 @@ var ScriptService = {
1637
1461
  let source = completion.source;
1638
1462
  if (source && completion.hasAction) {
1639
1463
  if (source[0] === ".") {
1640
- source = import_path10.default.resolve(fileName, "..", source);
1464
+ source = import_path7.default.resolve(fileName, "..", source);
1641
1465
  }
1642
1466
  detail = (0, import_relative_import_path.relativeImportPath)(fileName, source);
1643
1467
  sortText = `\uFFFF${sortText}`;
@@ -1941,26 +1765,17 @@ ${documentation}`;
1941
1765
  }
1942
1766
  };
1943
1767
  function processScript(doc, tsProject) {
1944
- return processDoc(
1945
- doc,
1946
- ({ filename, parsed, lookup, project: markoProject }) => {
1947
- var _a;
1948
- const { host, markoScriptLang } = tsProject;
1949
- return (0, import_language_tools14.extractScript)({
1950
- ts: import_tsserverlibrary.default,
1951
- parsed,
1952
- lookup,
1953
- scriptLang: getScriptLang(filename, import_tsserverlibrary.default, host, markoScriptLang),
1954
- runtimeTypesCode: (_a = getProjectTypeLibs(
1955
- tsProject.rootDir,
1956
- markoProject,
1957
- import_tsserverlibrary.default,
1958
- host
1959
- )) == null ? void 0 : _a.markoTypesCode,
1960
- componentFilename: getComponentFilename(filename)
1961
- });
1962
- }
1963
- );
1768
+ return processDoc(doc, ({ filename, parsed, lookup }) => {
1769
+ var _a;
1770
+ const { host, markoScriptLang } = tsProject;
1771
+ return (0, import_language_tools14.extractScript)({
1772
+ ts: import_tsserverlibrary.default,
1773
+ parsed,
1774
+ lookup,
1775
+ scriptLang: import_language_tools14.Project.getScriptLang(filename, markoScriptLang, import_tsserverlibrary.default, host),
1776
+ runtimeTypesCode: (_a = import_language_tools14.Project.getTypeLibs(tsProject.rootDir, import_tsserverlibrary.default, host)) == null ? void 0 : _a.markoTypesCode
1777
+ });
1778
+ });
1964
1779
  }
1965
1780
  function getInsertModuleStatementOffset(parsed) {
1966
1781
  const { program } = parsed;
@@ -2011,27 +1826,27 @@ function docLocationAtTextSpan(doc, { start, length }) {
2011
1826
  }
2012
1827
  function getTSProject(docFsPath) {
2013
1828
  var _a;
2014
- let configPath;
1829
+ let configFile;
2015
1830
  let markoScriptLang = import_language_tools14.ScriptLang.js;
2016
1831
  if (docFsPath) {
2017
- configPath = import_tsserverlibrary.default.findConfigFile(
1832
+ configFile = import_tsserverlibrary.default.findConfigFile(
2018
1833
  docFsPath,
2019
1834
  import_tsserverlibrary.default.sys.fileExists,
2020
1835
  "tsconfig.json"
2021
1836
  );
2022
- if (configPath) {
1837
+ if (configFile) {
2023
1838
  markoScriptLang = import_language_tools14.ScriptLang.ts;
2024
1839
  } else {
2025
- configPath = import_tsserverlibrary.default.findConfigFile(
1840
+ configFile = import_tsserverlibrary.default.findConfigFile(
2026
1841
  docFsPath,
2027
1842
  import_tsserverlibrary.default.sys.fileExists,
2028
1843
  "jsconfig.json"
2029
1844
  );
2030
1845
  }
2031
1846
  }
2032
- const rootDir = configPath && import_path10.default.dirname(configPath) || process.cwd();
2033
- const markoProject = getMarkoProject(configPath && rootDir);
2034
- let projectCache = markoProject.cache.get(getTSProject);
1847
+ const rootDir = configFile && import_path7.default.dirname(configFile) || process.cwd();
1848
+ const cache = import_language_tools14.Project.getCache(configFile && rootDir);
1849
+ let projectCache = cache.get(getTSProject);
2035
1850
  let cached;
2036
1851
  if (projectCache) {
2037
1852
  cached = projectCache.get(rootDir);
@@ -2039,14 +1854,14 @@ function getTSProject(docFsPath) {
2039
1854
  return cached;
2040
1855
  } else {
2041
1856
  projectCache = /* @__PURE__ */ new Map();
2042
- markoProject.cache.set(getTSProject, projectCache);
1857
+ cache.set(getTSProject, projectCache);
2043
1858
  }
2044
1859
  const { fileNames, options, projectReferences } = import_tsserverlibrary.default.parseJsonConfigFileContent(
2045
- configPath && import_tsserverlibrary.default.readConfigFile(configPath, import_tsserverlibrary.default.sys.readFile).config || defaultTSConfig,
1860
+ configFile && import_tsserverlibrary.default.readConfigFile(configFile, import_tsserverlibrary.default.sys.readFile).config || defaultTSConfig,
2046
1861
  import_tsserverlibrary.default.sys,
2047
1862
  rootDir,
2048
1863
  requiredTSCompilerOptions,
2049
- configPath,
1864
+ configFile,
2050
1865
  void 0,
2051
1866
  extraTSCompilerExtensions
2052
1867
  );
@@ -2054,15 +1869,21 @@ function getTSProject(docFsPath) {
2054
1869
  const potentialGlobalFiles = new Set(
2055
1870
  fileNames.filter((file) => /\.[cm]?ts$/.test(file))
2056
1871
  );
2057
- const tsPkgFile = configPath && ((_a = import_tsserverlibrary.default.resolveModuleName("typescript/package.json", configPath, options, import_tsserverlibrary.default.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
2058
- const defaultLibFile = import_path10.default.join(
2059
- tsPkgFile ? import_path10.default.join(tsPkgFile, "../lib") : __dirname,
1872
+ const tsPkgFile = configFile && ((_a = import_tsserverlibrary.default.resolveModuleName("typescript/package.json", configFile, options, import_tsserverlibrary.default.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
1873
+ const defaultLibFile = import_path7.default.join(
1874
+ tsPkgFile ? import_path7.default.join(tsPkgFile, "../lib") : __dirname,
2060
1875
  import_tsserverlibrary.default.getDefaultLibFileName(options)
2061
1876
  );
1877
+ const resolutionCache = import_tsserverlibrary.default.createModuleResolutionCache(
1878
+ rootDir,
1879
+ getCanonicalFileName,
1880
+ options
1881
+ );
2062
1882
  const host = patch(
2063
1883
  import_tsserverlibrary.default,
2064
- markoScriptLang,
1884
+ configFile,
2065
1885
  extractCache,
1886
+ resolutionCache,
2066
1887
  {
2067
1888
  getNewLine() {
2068
1889
  return import_tsserverlibrary.default.sys.newLine;
@@ -2085,9 +1906,16 @@ function getTSProject(docFsPath) {
2085
1906
  getProjectReferences() {
2086
1907
  return projectReferences;
2087
1908
  },
2088
- resolveModuleNames(moduleNames, containingFile) {
2089
- return moduleNames.map((moduleName) => {
2090
- return import_tsserverlibrary.default.resolveModuleName(moduleName, containingFile, options, host).resolvedModule;
1909
+ resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options2, _containingSourceFile, _reusedNames) {
1910
+ return moduleLiterals.map((moduleLiteral) => {
1911
+ return import_tsserverlibrary.default.bundlerModuleNameResolver(
1912
+ moduleLiteral.text,
1913
+ containingFile,
1914
+ options2,
1915
+ host,
1916
+ resolutionCache,
1917
+ redirectedReference
1918
+ );
2091
1919
  });
2092
1920
  },
2093
1921
  readDirectory: import_tsserverlibrary.default.sys.readDirectory,
@@ -2110,7 +1938,7 @@ function getTSProject(docFsPath) {
2110
1938
  return `${((_a2 = get(filenameToURI(filename))) == null ? void 0 : _a2.version) ?? -1}`;
2111
1939
  },
2112
1940
  getScriptKind(filename) {
2113
- switch (import_path10.default.extname(filename)) {
1941
+ switch (import_path7.default.extname(filename)) {
2114
1942
  case import_tsserverlibrary.default.Extension.Js:
2115
1943
  case import_tsserverlibrary.default.Extension.Cjs:
2116
1944
  case import_tsserverlibrary.default.Extension.Mjs:
@@ -2146,14 +1974,7 @@ function getTSProject(docFsPath) {
2146
1974
  host,
2147
1975
  rootDir: options.rootDir,
2148
1976
  service: import_tsserverlibrary.default.createLanguageService(host),
2149
- markoProject,
2150
- markoScriptLang,
2151
- markoProjectTypeLibs: getProjectTypeLibs(
2152
- options.rootDir,
2153
- markoProject,
2154
- import_tsserverlibrary.default,
2155
- host
2156
- )
1977
+ markoScriptLang
2157
1978
  };
2158
1979
  projectCache.set(rootDir, tsProject);
2159
1980
  return tsProject;
@@ -2311,6 +2132,9 @@ function getTSTriggerChar(char) {
2311
2132
  if (char && tsTriggerChars.has(char))
2312
2133
  return char;
2313
2134
  }
2135
+ function getCanonicalFileName(fileName) {
2136
+ return import_tsserverlibrary.default.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
2137
+ }
2314
2138
 
2315
2139
  // src/service/style/index.ts
2316
2140
  var import_vscode_css_languageservice2 = require("vscode-css-languageservice");
@@ -3195,7 +3019,7 @@ for (const command in service.commands) {
3195
3019
  }
3196
3020
  function validateDocs() {
3197
3021
  queueDiagnostic();
3198
- clearMarkoProjectCaches();
3022
+ import_language_tools16.Project.clearCaches();
3199
3023
  }
3200
3024
  function queueDiagnostic() {
3201
3025
  clearTimeout(diagnosticTimeout);