@marko/language-server 1.0.2 → 1.0.3
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 +102 -43
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +102 -43
- package/dist/index.mjs.map +2 -2
- package/dist/ts-plugin/host.d.ts +3 -1
- package/dist/utils/get-runtime-types.d.ts +3 -1
- package/package.json +6 -6
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
|
|
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
|
-
|
|
1270
|
-
|
|
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 = (
|
|
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,12 +1330,19 @@ 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
|
|
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";
|
|
@@ -1329,19 +1351,27 @@ var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
|
|
|
1329
1351
|
var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
|
|
1330
1352
|
function patch(ts2, scriptLang, cache, host) {
|
|
1331
1353
|
var _a, _b, _c;
|
|
1354
|
+
const rootDir = host.getCurrentDirectory();
|
|
1332
1355
|
const projectTypeLibs = getProjectTypeLibs(
|
|
1333
|
-
|
|
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
|
-
|
|
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,20 @@ 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
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
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
|
+
}
|
|
1369
1403
|
cache.set(filename, cached);
|
|
1370
1404
|
}
|
|
1371
1405
|
return cached.snapshot;
|
|
@@ -1477,7 +1511,7 @@ function patch(ts2, scriptLang, cache, host) {
|
|
|
1477
1511
|
}
|
|
1478
1512
|
|
|
1479
1513
|
// src/service/script/index.ts
|
|
1480
|
-
var IGNORE_DIAG_REG = /^(?:Expression|Identifier|['"][^\w]['"]) expected
|
|
1514
|
+
var IGNORE_DIAG_REG = /^(?:(?:Expression|Identifier|['"][^\w]['"]) expected|Invalid character)\b/i;
|
|
1481
1515
|
var extractCache = /* @__PURE__ */ new Map();
|
|
1482
1516
|
var snapshotCache = /* @__PURE__ */ new Map();
|
|
1483
1517
|
var insertModuleStatementLocCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -1487,6 +1521,34 @@ var optionalModifierReg = /\boptional\b/;
|
|
|
1487
1521
|
var deprecatedModifierReg = /\bdeprecated\b/;
|
|
1488
1522
|
var colorModifierReg = /\bcolor\b/;
|
|
1489
1523
|
var localInternalsPrefix = "__marko_internal_";
|
|
1524
|
+
var requiredTSCompilerOptions = {
|
|
1525
|
+
module: import_tsserverlibrary.default.ModuleKind.ESNext,
|
|
1526
|
+
moduleResolution: import_tsserverlibrary.default.ModuleResolutionKind.NodeJs,
|
|
1527
|
+
noEmit: true,
|
|
1528
|
+
allowJs: true,
|
|
1529
|
+
composite: false,
|
|
1530
|
+
declaration: false,
|
|
1531
|
+
skipLibCheck: true,
|
|
1532
|
+
isolatedModules: true,
|
|
1533
|
+
resolveJsonModule: true,
|
|
1534
|
+
skipDefaultLibCheck: true,
|
|
1535
|
+
emitDeclarationOnly: false,
|
|
1536
|
+
allowNonTsExtensions: true,
|
|
1537
|
+
emitDecoratorMetadata: false
|
|
1538
|
+
};
|
|
1539
|
+
var defaultTSConfig = {
|
|
1540
|
+
include: [],
|
|
1541
|
+
compilerOptions: {
|
|
1542
|
+
lib: ["dom", "node", "esnext"]
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
var extraTSCompilerExtensions = [
|
|
1546
|
+
{
|
|
1547
|
+
extension: ".marko",
|
|
1548
|
+
isMixedContent: false,
|
|
1549
|
+
scriptKind: import_tsserverlibrary.default.ScriptKind.Deferred
|
|
1550
|
+
}
|
|
1551
|
+
];
|
|
1490
1552
|
var ScriptService = {
|
|
1491
1553
|
commands: {
|
|
1492
1554
|
"$/showScriptOutput": async (uri) => {
|
|
@@ -1885,7 +1947,12 @@ function processScript(doc, tsProject) {
|
|
|
1885
1947
|
parsed,
|
|
1886
1948
|
lookup,
|
|
1887
1949
|
scriptLang: getScriptLang(filename, import_tsserverlibrary.default, host, markoScriptLang),
|
|
1888
|
-
runtimeTypesCode: (_a = getProjectTypeLibs(
|
|
1950
|
+
runtimeTypesCode: (_a = getProjectTypeLibs(
|
|
1951
|
+
tsProject.rootDir,
|
|
1952
|
+
markoProject,
|
|
1953
|
+
import_tsserverlibrary.default,
|
|
1954
|
+
host
|
|
1955
|
+
)) == null ? void 0 : _a.markoTypesCode,
|
|
1889
1956
|
componentFilename: getComponentFilename(filename)
|
|
1890
1957
|
});
|
|
1891
1958
|
}
|
|
@@ -1971,31 +2038,18 @@ function getTSProject(docFsPath) {
|
|
|
1971
2038
|
markoProject.cache.set(getTSProject, projectCache);
|
|
1972
2039
|
}
|
|
1973
2040
|
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
|
-
},
|
|
2041
|
+
configPath && import_tsserverlibrary.default.readConfigFile(configPath, import_tsserverlibrary.default.sys.readFile).config || defaultTSConfig,
|
|
1978
2042
|
import_tsserverlibrary.default.sys,
|
|
1979
2043
|
rootDir,
|
|
1980
|
-
|
|
2044
|
+
requiredTSCompilerOptions,
|
|
1981
2045
|
configPath,
|
|
1982
2046
|
void 0,
|
|
1983
|
-
|
|
1984
|
-
{
|
|
1985
|
-
extension: ".marko",
|
|
1986
|
-
isMixedContent: false,
|
|
1987
|
-
scriptKind: import_tsserverlibrary.default.ScriptKind.Deferred
|
|
1988
|
-
}
|
|
1989
|
-
]
|
|
2047
|
+
extraTSCompilerExtensions
|
|
1990
2048
|
);
|
|
2049
|
+
options.rootDir ??= rootDir;
|
|
1991
2050
|
const potentialGlobalFiles = new Set(
|
|
1992
2051
|
fileNames.filter((file) => /\.[cm]?ts$/.test(file))
|
|
1993
2052
|
);
|
|
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
2053
|
const tsPkgFile = configPath && ((_a = import_tsserverlibrary.default.resolveModuleName("typescript/package.json", configPath, options, import_tsserverlibrary.default.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
|
|
2000
2054
|
const defaultLibFile = import_path10.default.join(
|
|
2001
2055
|
tsPkgFile ? import_path10.default.join(tsPkgFile, "../lib") : __dirname,
|
|
@@ -2090,7 +2144,12 @@ function getTSProject(docFsPath) {
|
|
|
2090
2144
|
service: import_tsserverlibrary.default.createLanguageService(host),
|
|
2091
2145
|
markoProject,
|
|
2092
2146
|
markoScriptLang,
|
|
2093
|
-
markoProjectTypeLibs: getProjectTypeLibs(
|
|
2147
|
+
markoProjectTypeLibs: getProjectTypeLibs(
|
|
2148
|
+
options.rootDir,
|
|
2149
|
+
markoProject,
|
|
2150
|
+
import_tsserverlibrary.default,
|
|
2151
|
+
host
|
|
2152
|
+
)
|
|
2094
2153
|
};
|
|
2095
2154
|
projectCache.set(rootDir, tsProject);
|
|
2096
2155
|
return tsProject;
|