@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.mjs CHANGED
@@ -1285,20 +1285,35 @@ import {
1285
1285
  import path7 from "path";
1286
1286
  var internalTypesFile = path7.join(__dirname, "marko.internal.d.ts");
1287
1287
  var defaultMarkoTypesFile = path7.join(__dirname, "marko.runtime.d.ts");
1288
- function getProjectTypeLibs(project, ts2, host) {
1288
+ function getProjectTypeLibs(rootDir, project, ts2, host) {
1289
1289
  let cached = project.cache.get(getProjectTypeLibs);
1290
1290
  if (cached === void 0) {
1291
- const { resolvedTypeReferenceDirective } = ts2.resolveTypeReferenceDirective(
1291
+ const markoRunGeneratedTypesFile = path7.join(
1292
+ rootDir,
1293
+ ".marko-run/routes.d.ts"
1294
+ );
1295
+ const resolveFromFile = path7.join(host.getCurrentDirectory(), "_.d.ts");
1296
+ const compilerOptions = host.getCompilationSettings();
1297
+ const { resolvedTypeReferenceDirective: resolvedMarkoTypes } = ts2.resolveTypeReferenceDirective(
1292
1298
  project.translator.runtimeTypes || "marko",
1293
- path7.join(host.getCurrentDirectory(), "_.d.ts"),
1294
- host.getCompilationSettings(),
1299
+ resolveFromFile,
1300
+ compilerOptions,
1301
+ host
1302
+ );
1303
+ const { resolvedTypeReferenceDirective: resolvedMarkoRunTypes } = ts2.resolveTypeReferenceDirective(
1304
+ "@marko/run",
1305
+ resolveFromFile,
1306
+ compilerOptions,
1295
1307
  host
1296
1308
  );
1297
- const markoTypesFile = (resolvedTypeReferenceDirective == null ? void 0 : resolvedTypeReferenceDirective.resolvedFileName) || defaultMarkoTypesFile;
1309
+ const markoTypesFile = (resolvedMarkoTypes == null ? void 0 : resolvedMarkoTypes.resolvedFileName) || defaultMarkoTypesFile;
1310
+ const markoRunTypesFile = resolvedMarkoRunTypes == null ? void 0 : resolvedMarkoRunTypes.resolvedFileName;
1298
1311
  cached = {
1299
1312
  internalTypesFile,
1300
1313
  markoTypesFile,
1301
- markoTypesCode: host.readFile(markoTypesFile, "utf-8") || ""
1314
+ markoTypesCode: host.readFile(markoTypesFile, "utf-8") || "",
1315
+ markoRunTypesFile,
1316
+ markoRunGeneratedTypesFile: host.fileExists(markoRunGeneratedTypesFile) ? markoRunGeneratedTypesFile : void 0
1302
1317
  };
1303
1318
  project.cache.set(getProjectTypeLibs, cached);
1304
1319
  }
@@ -1339,33 +1354,48 @@ function getComponentFilename(from) {
1339
1354
  const componentBrowserFull = `${nameNoExt}.component-browser.`;
1340
1355
  const componentPartial = isEntry ? "component." : void 0;
1341
1356
  const componentBrowserPartial = isEntry ? "component-browser." : void 0;
1342
- for (const entry of fs5.readdirSync(dir)) {
1357
+ for (const entry of tryReaddirSync(dir)) {
1343
1358
  if (entry !== from && (isEntry && entry.startsWith(componentBrowserPartial) || entry.startsWith(componentPartial)) || entry.startsWith(componentBrowserFull) || entry.startsWith(componentFull)) {
1344
1359
  return path8.join(dir, entry);
1345
1360
  }
1346
1361
  }
1347
1362
  }
1363
+ function tryReaddirSync(dir) {
1364
+ try {
1365
+ return fs5.readdirSync(dir);
1366
+ } catch {
1367
+ return [];
1368
+ }
1369
+ }
1348
1370
 
1349
1371
  // src/ts-plugin/host.ts
1350
1372
  var markoExt = ".marko";
1351
1373
  var markoExtReg = /\.marko$/;
1352
1374
  var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
1353
1375
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
1354
- function patch(ts2, scriptLang, cache, host) {
1376
+ function patch(ts2, scriptLang, cache, host, ps) {
1355
1377
  var _a, _b, _c;
1378
+ const rootDir = host.getCurrentDirectory();
1356
1379
  const projectTypeLibs = getProjectTypeLibs(
1357
- getMarkoProject(host.getCurrentDirectory()),
1380
+ rootDir,
1381
+ getMarkoProject(rootDir),
1358
1382
  ts2,
1359
1383
  host
1360
1384
  );
1385
+ const projectTypeLibsFiles = [
1386
+ projectTypeLibs.internalTypesFile,
1387
+ projectTypeLibs.markoTypesFile
1388
+ ];
1389
+ if (projectTypeLibs.markoRunTypesFile) {
1390
+ projectTypeLibsFiles.push(projectTypeLibs.markoRunTypesFile);
1391
+ }
1392
+ if (projectTypeLibs.markoRunGeneratedTypesFile) {
1393
+ projectTypeLibsFiles.push(projectTypeLibs.markoRunGeneratedTypesFile);
1394
+ }
1361
1395
  const isMarkoTSFile = (fileName) => getScriptLang(fileName, ts2, host, scriptLang) === ScriptLang2.ts;
1362
1396
  const getScriptFileNames = host.getScriptFileNames.bind(host);
1363
1397
  host.getScriptFileNames = () => [
1364
- .../* @__PURE__ */ new Set([
1365
- ...getScriptFileNames(),
1366
- projectTypeLibs.internalTypesFile,
1367
- projectTypeLibs.markoTypesFile
1368
- ])
1398
+ ...new Set(projectTypeLibsFiles.concat(getScriptFileNames()))
1369
1399
  ];
1370
1400
  const getScriptKind = (_a = host.getScriptKind) == null ? void 0 : _a.bind(host);
1371
1401
  if (getScriptKind) {
@@ -1380,16 +1410,28 @@ function patch(ts2, scriptLang, cache, host) {
1380
1410
  if (!cached) {
1381
1411
  const code = host.readFile(filename, "utf-8") || "";
1382
1412
  const dir = path9.dirname(filename);
1383
- const markoProject = getMarkoProject(dir);
1384
- cached = extractScript({
1385
- ts: ts2,
1386
- parsed: parse2(code, filename),
1387
- lookup: markoProject.getLookup(dir),
1388
- scriptLang: getScriptLang(filename, ts2, host, scriptLang),
1389
- runtimeTypesCode: projectTypeLibs.markoTypesCode,
1390
- componentFilename: getComponentFilename(filename)
1391
- });
1392
- cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
1413
+ try {
1414
+ const markoProject = getMarkoProject(dir);
1415
+ cached = extractScript({
1416
+ ts: ts2,
1417
+ parsed: parse2(code, filename),
1418
+ lookup: markoProject.getLookup(dir),
1419
+ scriptLang: getScriptLang(filename, ts2, host, scriptLang),
1420
+ runtimeTypesCode: projectTypeLibs.markoTypesCode,
1421
+ componentFilename: getComponentFilename(filename)
1422
+ });
1423
+ cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
1424
+ } catch {
1425
+ cached = { snapshot: ts2.ScriptSnapshot.fromString("") };
1426
+ }
1427
+ ps == null ? void 0 : ps.getOrCreateScriptInfoForNormalizedPath(
1428
+ filename,
1429
+ false,
1430
+ void 0,
1431
+ ts2.ScriptKind.Deferred,
1432
+ false,
1433
+ host
1434
+ );
1393
1435
  cache.set(filename, cached);
1394
1436
  }
1395
1437
  return cached.snapshot;
@@ -1501,7 +1543,7 @@ function patch(ts2, scriptLang, cache, host) {
1501
1543
  }
1502
1544
 
1503
1545
  // src/service/script/index.ts
1504
- var IGNORE_DIAG_REG = /^(?:Expression|Identifier|['"][^\w]['"]) expected.$/;
1546
+ var IGNORE_DIAG_REG = /^(?:(?:Expression|Identifier|['"][^\w]['"]) expected|Invalid character)\b/i;
1505
1547
  var extractCache = /* @__PURE__ */ new Map();
1506
1548
  var snapshotCache = /* @__PURE__ */ new Map();
1507
1549
  var insertModuleStatementLocCache = /* @__PURE__ */ new WeakMap();
@@ -1511,6 +1553,34 @@ var optionalModifierReg = /\boptional\b/;
1511
1553
  var deprecatedModifierReg = /\bdeprecated\b/;
1512
1554
  var colorModifierReg = /\bcolor\b/;
1513
1555
  var localInternalsPrefix = "__marko_internal_";
1556
+ var requiredTSCompilerOptions = {
1557
+ module: ts.ModuleKind.ESNext,
1558
+ moduleResolution: ts.ModuleResolutionKind.NodeJs,
1559
+ noEmit: true,
1560
+ allowJs: true,
1561
+ composite: false,
1562
+ declaration: false,
1563
+ skipLibCheck: true,
1564
+ isolatedModules: true,
1565
+ resolveJsonModule: true,
1566
+ skipDefaultLibCheck: true,
1567
+ emitDeclarationOnly: false,
1568
+ allowNonTsExtensions: true,
1569
+ emitDecoratorMetadata: false
1570
+ };
1571
+ var defaultTSConfig = {
1572
+ include: [],
1573
+ compilerOptions: {
1574
+ lib: ["dom", "node", "esnext"]
1575
+ }
1576
+ };
1577
+ var extraTSCompilerExtensions = [
1578
+ {
1579
+ extension: ".marko",
1580
+ isMixedContent: false,
1581
+ scriptKind: ts.ScriptKind.Deferred
1582
+ }
1583
+ ];
1514
1584
  var ScriptService = {
1515
1585
  commands: {
1516
1586
  "$/showScriptOutput": async (uri) => {
@@ -1909,7 +1979,12 @@ function processScript(doc, tsProject) {
1909
1979
  parsed,
1910
1980
  lookup,
1911
1981
  scriptLang: getScriptLang(filename, ts, host, markoScriptLang),
1912
- runtimeTypesCode: (_a = getProjectTypeLibs(markoProject, ts, host)) == null ? void 0 : _a.markoTypesCode,
1982
+ runtimeTypesCode: (_a = getProjectTypeLibs(
1983
+ tsProject.rootDir,
1984
+ markoProject,
1985
+ ts,
1986
+ host
1987
+ )) == null ? void 0 : _a.markoTypesCode,
1913
1988
  componentFilename: getComponentFilename(filename)
1914
1989
  });
1915
1990
  }
@@ -1995,31 +2070,18 @@ function getTSProject(docFsPath) {
1995
2070
  markoProject.cache.set(getTSProject, projectCache);
1996
2071
  }
1997
2072
  const { fileNames, options, projectReferences } = ts.parseJsonConfigFileContent(
1998
- configPath && ts.readConfigFile(configPath, ts.sys.readFile).config || {
1999
- compilerOptions: { lib: ["dom", "node", "esnext"] },
2000
- include: []
2001
- },
2073
+ configPath && ts.readConfigFile(configPath, ts.sys.readFile).config || defaultTSConfig,
2002
2074
  ts.sys,
2003
2075
  rootDir,
2004
- void 0,
2076
+ requiredTSCompilerOptions,
2005
2077
  configPath,
2006
2078
  void 0,
2007
- [
2008
- {
2009
- extension: ".marko",
2010
- isMixedContent: false,
2011
- scriptKind: ts.ScriptKind.Deferred
2012
- }
2013
- ]
2079
+ extraTSCompilerExtensions
2014
2080
  );
2081
+ options.rootDir ??= rootDir;
2015
2082
  const potentialGlobalFiles = new Set(
2016
2083
  fileNames.filter((file) => /\.[cm]?ts$/.test(file))
2017
2084
  );
2018
- options.rootDir ??= rootDir;
2019
- options.module = ts.ModuleKind.ESNext;
2020
- options.moduleResolution = ts.ModuleResolutionKind.NodeJs;
2021
- options.declaration = false;
2022
- options.noEmit = options.allowJs = options.skipLibCheck = options.isolatedModules = options.resolveJsonModule = options.skipDefaultLibCheck = options.allowNonTsExtensions = true;
2023
2085
  const tsPkgFile = configPath && ((_a = ts.resolveModuleName("typescript/package.json", configPath, options, ts.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
2024
2086
  const defaultLibFile = path10.join(
2025
2087
  tsPkgFile ? path10.join(tsPkgFile, "../lib") : __dirname,
@@ -2114,7 +2176,12 @@ function getTSProject(docFsPath) {
2114
2176
  service: ts.createLanguageService(host),
2115
2177
  markoProject,
2116
2178
  markoScriptLang,
2117
- markoProjectTypeLibs: getProjectTypeLibs(markoProject, ts, host)
2179
+ markoProjectTypeLibs: getProjectTypeLibs(
2180
+ options.rootDir,
2181
+ markoProject,
2182
+ ts,
2183
+ host
2184
+ )
2118
2185
  };
2119
2186
  projectCache.set(rootDir, tsProject);
2120
2187
  return tsProject;