@marko/language-server 1.0.2 → 1.0.4

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
@@ -1261,20 +1261,35 @@ var import_language_tools13 = require("@marko/language-tools");
1261
1261
  var import_path7 = __toESM(require("path"));
1262
1262
  var internalTypesFile = import_path7.default.join(__dirname, "marko.internal.d.ts");
1263
1263
  var defaultMarkoTypesFile = import_path7.default.join(__dirname, "marko.runtime.d.ts");
1264
- function getProjectTypeLibs(project, ts2, host) {
1264
+ function getProjectTypeLibs(rootDir, project, ts2, host) {
1265
1265
  let cached = project.cache.get(getProjectTypeLibs);
1266
1266
  if (cached === void 0) {
1267
- const { resolvedTypeReferenceDirective } = ts2.resolveTypeReferenceDirective(
1267
+ const markoRunGeneratedTypesFile = import_path7.default.join(
1268
+ rootDir,
1269
+ ".marko-run/routes.d.ts"
1270
+ );
1271
+ const resolveFromFile = import_path7.default.join(host.getCurrentDirectory(), "_.d.ts");
1272
+ const compilerOptions = host.getCompilationSettings();
1273
+ const { resolvedTypeReferenceDirective: resolvedMarkoTypes } = ts2.resolveTypeReferenceDirective(
1268
1274
  project.translator.runtimeTypes || "marko",
1269
- import_path7.default.join(host.getCurrentDirectory(), "_.d.ts"),
1270
- host.getCompilationSettings(),
1275
+ resolveFromFile,
1276
+ compilerOptions,
1277
+ host
1278
+ );
1279
+ const { resolvedTypeReferenceDirective: resolvedMarkoRunTypes } = ts2.resolveTypeReferenceDirective(
1280
+ "@marko/run",
1281
+ resolveFromFile,
1282
+ compilerOptions,
1271
1283
  host
1272
1284
  );
1273
- const markoTypesFile = (resolvedTypeReferenceDirective == null ? void 0 : resolvedTypeReferenceDirective.resolvedFileName) || defaultMarkoTypesFile;
1285
+ const markoTypesFile = (resolvedMarkoTypes == null ? void 0 : resolvedMarkoTypes.resolvedFileName) || defaultMarkoTypesFile;
1286
+ const markoRunTypesFile = resolvedMarkoRunTypes == null ? void 0 : resolvedMarkoRunTypes.resolvedFileName;
1274
1287
  cached = {
1275
1288
  internalTypesFile,
1276
1289
  markoTypesFile,
1277
- markoTypesCode: host.readFile(markoTypesFile, "utf-8") || ""
1290
+ markoTypesCode: host.readFile(markoTypesFile, "utf-8") || "",
1291
+ markoRunTypesFile,
1292
+ markoRunGeneratedTypesFile: host.fileExists(markoRunGeneratedTypesFile) ? markoRunGeneratedTypesFile : void 0
1278
1293
  };
1279
1294
  project.cache.set(getProjectTypeLibs, cached);
1280
1295
  }
@@ -1315,33 +1330,48 @@ function getComponentFilename(from) {
1315
1330
  const componentBrowserFull = `${nameNoExt}.component-browser.`;
1316
1331
  const componentPartial = isEntry ? "component." : void 0;
1317
1332
  const componentBrowserPartial = isEntry ? "component-browser." : void 0;
1318
- for (const entry of import_fs4.default.readdirSync(dir)) {
1333
+ for (const entry of tryReaddirSync(dir)) {
1319
1334
  if (entry !== from && (isEntry && entry.startsWith(componentBrowserPartial) || entry.startsWith(componentPartial)) || entry.startsWith(componentBrowserFull) || entry.startsWith(componentFull)) {
1320
1335
  return import_path8.default.join(dir, entry);
1321
1336
  }
1322
1337
  }
1323
1338
  }
1339
+ function tryReaddirSync(dir) {
1340
+ try {
1341
+ return import_fs4.default.readdirSync(dir);
1342
+ } catch {
1343
+ return [];
1344
+ }
1345
+ }
1324
1346
 
1325
1347
  // src/ts-plugin/host.ts
1326
1348
  var markoExt = ".marko";
1327
1349
  var markoExtReg = /\.marko$/;
1328
1350
  var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
1329
1351
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
1330
- function patch(ts2, scriptLang, cache, host) {
1352
+ function patch(ts2, scriptLang, cache, host, ps) {
1331
1353
  var _a, _b, _c;
1354
+ const rootDir = host.getCurrentDirectory();
1332
1355
  const projectTypeLibs = getProjectTypeLibs(
1333
- getMarkoProject(host.getCurrentDirectory()),
1356
+ rootDir,
1357
+ getMarkoProject(rootDir),
1334
1358
  ts2,
1335
1359
  host
1336
1360
  );
1361
+ const projectTypeLibsFiles = [
1362
+ projectTypeLibs.internalTypesFile,
1363
+ projectTypeLibs.markoTypesFile
1364
+ ];
1365
+ if (projectTypeLibs.markoRunTypesFile) {
1366
+ projectTypeLibsFiles.push(projectTypeLibs.markoRunTypesFile);
1367
+ }
1368
+ if (projectTypeLibs.markoRunGeneratedTypesFile) {
1369
+ projectTypeLibsFiles.push(projectTypeLibs.markoRunGeneratedTypesFile);
1370
+ }
1337
1371
  const isMarkoTSFile = (fileName) => getScriptLang(fileName, ts2, host, scriptLang) === import_language_tools13.ScriptLang.ts;
1338
1372
  const getScriptFileNames = host.getScriptFileNames.bind(host);
1339
1373
  host.getScriptFileNames = () => [
1340
- .../* @__PURE__ */ new Set([
1341
- ...getScriptFileNames(),
1342
- projectTypeLibs.internalTypesFile,
1343
- projectTypeLibs.markoTypesFile
1344
- ])
1374
+ ...new Set(projectTypeLibsFiles.concat(getScriptFileNames()))
1345
1375
  ];
1346
1376
  const getScriptKind = (_a = host.getScriptKind) == null ? void 0 : _a.bind(host);
1347
1377
  if (getScriptKind) {
@@ -1356,16 +1386,28 @@ function patch(ts2, scriptLang, cache, host) {
1356
1386
  if (!cached) {
1357
1387
  const code = host.readFile(filename, "utf-8") || "";
1358
1388
  const dir = import_path9.default.dirname(filename);
1359
- const markoProject = getMarkoProject(dir);
1360
- cached = (0, import_language_tools13.extractScript)({
1361
- ts: ts2,
1362
- parsed: (0, import_language_tools13.parse)(code, filename),
1363
- lookup: markoProject.getLookup(dir),
1364
- scriptLang: getScriptLang(filename, ts2, host, scriptLang),
1365
- runtimeTypesCode: projectTypeLibs.markoTypesCode,
1366
- componentFilename: getComponentFilename(filename)
1367
- });
1368
- cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
1389
+ try {
1390
+ const markoProject = getMarkoProject(dir);
1391
+ cached = (0, import_language_tools13.extractScript)({
1392
+ ts: ts2,
1393
+ parsed: (0, import_language_tools13.parse)(code, filename),
1394
+ lookup: markoProject.getLookup(dir),
1395
+ scriptLang: getScriptLang(filename, ts2, host, scriptLang),
1396
+ runtimeTypesCode: projectTypeLibs.markoTypesCode,
1397
+ componentFilename: getComponentFilename(filename)
1398
+ });
1399
+ cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
1400
+ } catch {
1401
+ cached = { snapshot: ts2.ScriptSnapshot.fromString("") };
1402
+ }
1403
+ ps == null ? void 0 : ps.getOrCreateScriptInfoForNormalizedPath(
1404
+ filename,
1405
+ false,
1406
+ void 0,
1407
+ ts2.ScriptKind.Deferred,
1408
+ false,
1409
+ host
1410
+ );
1369
1411
  cache.set(filename, cached);
1370
1412
  }
1371
1413
  return cached.snapshot;
@@ -1477,7 +1519,7 @@ function patch(ts2, scriptLang, cache, host) {
1477
1519
  }
1478
1520
 
1479
1521
  // src/service/script/index.ts
1480
- var IGNORE_DIAG_REG = /^(?:Expression|Identifier|['"][^\w]['"]) expected.$/;
1522
+ var IGNORE_DIAG_REG = /^(?:(?:Expression|Identifier|['"][^\w]['"]) expected|Invalid character)\b/i;
1481
1523
  var extractCache = /* @__PURE__ */ new Map();
1482
1524
  var snapshotCache = /* @__PURE__ */ new Map();
1483
1525
  var insertModuleStatementLocCache = /* @__PURE__ */ new WeakMap();
@@ -1487,6 +1529,34 @@ var optionalModifierReg = /\boptional\b/;
1487
1529
  var deprecatedModifierReg = /\bdeprecated\b/;
1488
1530
  var colorModifierReg = /\bcolor\b/;
1489
1531
  var localInternalsPrefix = "__marko_internal_";
1532
+ var requiredTSCompilerOptions = {
1533
+ module: import_tsserverlibrary.default.ModuleKind.ESNext,
1534
+ moduleResolution: import_tsserverlibrary.default.ModuleResolutionKind.NodeJs,
1535
+ noEmit: true,
1536
+ allowJs: true,
1537
+ composite: false,
1538
+ declaration: false,
1539
+ skipLibCheck: true,
1540
+ isolatedModules: true,
1541
+ resolveJsonModule: true,
1542
+ skipDefaultLibCheck: true,
1543
+ emitDeclarationOnly: false,
1544
+ allowNonTsExtensions: true,
1545
+ emitDecoratorMetadata: false
1546
+ };
1547
+ var defaultTSConfig = {
1548
+ include: [],
1549
+ compilerOptions: {
1550
+ lib: ["dom", "node", "esnext"]
1551
+ }
1552
+ };
1553
+ var extraTSCompilerExtensions = [
1554
+ {
1555
+ extension: ".marko",
1556
+ isMixedContent: false,
1557
+ scriptKind: import_tsserverlibrary.default.ScriptKind.Deferred
1558
+ }
1559
+ ];
1490
1560
  var ScriptService = {
1491
1561
  commands: {
1492
1562
  "$/showScriptOutput": async (uri) => {
@@ -1885,7 +1955,12 @@ function processScript(doc, tsProject) {
1885
1955
  parsed,
1886
1956
  lookup,
1887
1957
  scriptLang: getScriptLang(filename, import_tsserverlibrary.default, host, markoScriptLang),
1888
- runtimeTypesCode: (_a = getProjectTypeLibs(markoProject, import_tsserverlibrary.default, host)) == null ? void 0 : _a.markoTypesCode,
1958
+ runtimeTypesCode: (_a = getProjectTypeLibs(
1959
+ tsProject.rootDir,
1960
+ markoProject,
1961
+ import_tsserverlibrary.default,
1962
+ host
1963
+ )) == null ? void 0 : _a.markoTypesCode,
1889
1964
  componentFilename: getComponentFilename(filename)
1890
1965
  });
1891
1966
  }
@@ -1971,31 +2046,18 @@ function getTSProject(docFsPath) {
1971
2046
  markoProject.cache.set(getTSProject, projectCache);
1972
2047
  }
1973
2048
  const { fileNames, options, projectReferences } = import_tsserverlibrary.default.parseJsonConfigFileContent(
1974
- configPath && import_tsserverlibrary.default.readConfigFile(configPath, import_tsserverlibrary.default.sys.readFile).config || {
1975
- compilerOptions: { lib: ["dom", "node", "esnext"] },
1976
- include: []
1977
- },
2049
+ configPath && import_tsserverlibrary.default.readConfigFile(configPath, import_tsserverlibrary.default.sys.readFile).config || defaultTSConfig,
1978
2050
  import_tsserverlibrary.default.sys,
1979
2051
  rootDir,
1980
- void 0,
2052
+ requiredTSCompilerOptions,
1981
2053
  configPath,
1982
2054
  void 0,
1983
- [
1984
- {
1985
- extension: ".marko",
1986
- isMixedContent: false,
1987
- scriptKind: import_tsserverlibrary.default.ScriptKind.Deferred
1988
- }
1989
- ]
2055
+ extraTSCompilerExtensions
1990
2056
  );
2057
+ options.rootDir ??= rootDir;
1991
2058
  const potentialGlobalFiles = new Set(
1992
2059
  fileNames.filter((file) => /\.[cm]?ts$/.test(file))
1993
2060
  );
1994
- options.rootDir ??= rootDir;
1995
- options.module = import_tsserverlibrary.default.ModuleKind.ESNext;
1996
- options.moduleResolution = import_tsserverlibrary.default.ModuleResolutionKind.NodeJs;
1997
- options.declaration = false;
1998
- options.noEmit = options.allowJs = options.skipLibCheck = options.isolatedModules = options.resolveJsonModule = options.skipDefaultLibCheck = options.allowNonTsExtensions = true;
1999
2061
  const tsPkgFile = configPath && ((_a = import_tsserverlibrary.default.resolveModuleName("typescript/package.json", configPath, options, import_tsserverlibrary.default.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
2000
2062
  const defaultLibFile = import_path10.default.join(
2001
2063
  tsPkgFile ? import_path10.default.join(tsPkgFile, "../lib") : __dirname,
@@ -2090,7 +2152,12 @@ function getTSProject(docFsPath) {
2090
2152
  service: import_tsserverlibrary.default.createLanguageService(host),
2091
2153
  markoProject,
2092
2154
  markoScriptLang,
2093
- markoProjectTypeLibs: getProjectTypeLibs(markoProject, import_tsserverlibrary.default, host)
2155
+ markoProjectTypeLibs: getProjectTypeLibs(
2156
+ options.rootDir,
2157
+ markoProject,
2158
+ import_tsserverlibrary.default,
2159
+ host
2160
+ )
2094
2161
  };
2095
2162
  projectCache.set(rootDir, tsProject);
2096
2163
  return tsProject;