@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.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
|
|
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
|
-
|
|
1294
|
-
|
|
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 = (
|
|
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,12 +1354,19 @@ 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
|
|
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";
|
|
@@ -1353,19 +1375,27 @@ var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
|
|
|
1353
1375
|
var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
|
|
1354
1376
|
function patch(ts2, scriptLang, cache, host) {
|
|
1355
1377
|
var _a, _b, _c;
|
|
1378
|
+
const rootDir = host.getCurrentDirectory();
|
|
1356
1379
|
const projectTypeLibs = getProjectTypeLibs(
|
|
1357
|
-
|
|
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
|
-
|
|
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,20 @@ 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
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
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
|
+
}
|
|
1393
1427
|
cache.set(filename, cached);
|
|
1394
1428
|
}
|
|
1395
1429
|
return cached.snapshot;
|
|
@@ -1501,7 +1535,7 @@ function patch(ts2, scriptLang, cache, host) {
|
|
|
1501
1535
|
}
|
|
1502
1536
|
|
|
1503
1537
|
// src/service/script/index.ts
|
|
1504
|
-
var IGNORE_DIAG_REG = /^(?:Expression|Identifier|['"][^\w]['"]) expected
|
|
1538
|
+
var IGNORE_DIAG_REG = /^(?:(?:Expression|Identifier|['"][^\w]['"]) expected|Invalid character)\b/i;
|
|
1505
1539
|
var extractCache = /* @__PURE__ */ new Map();
|
|
1506
1540
|
var snapshotCache = /* @__PURE__ */ new Map();
|
|
1507
1541
|
var insertModuleStatementLocCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -1511,6 +1545,34 @@ var optionalModifierReg = /\boptional\b/;
|
|
|
1511
1545
|
var deprecatedModifierReg = /\bdeprecated\b/;
|
|
1512
1546
|
var colorModifierReg = /\bcolor\b/;
|
|
1513
1547
|
var localInternalsPrefix = "__marko_internal_";
|
|
1548
|
+
var requiredTSCompilerOptions = {
|
|
1549
|
+
module: ts.ModuleKind.ESNext,
|
|
1550
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
1551
|
+
noEmit: true,
|
|
1552
|
+
allowJs: true,
|
|
1553
|
+
composite: false,
|
|
1554
|
+
declaration: false,
|
|
1555
|
+
skipLibCheck: true,
|
|
1556
|
+
isolatedModules: true,
|
|
1557
|
+
resolveJsonModule: true,
|
|
1558
|
+
skipDefaultLibCheck: true,
|
|
1559
|
+
emitDeclarationOnly: false,
|
|
1560
|
+
allowNonTsExtensions: true,
|
|
1561
|
+
emitDecoratorMetadata: false
|
|
1562
|
+
};
|
|
1563
|
+
var defaultTSConfig = {
|
|
1564
|
+
include: [],
|
|
1565
|
+
compilerOptions: {
|
|
1566
|
+
lib: ["dom", "node", "esnext"]
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
var extraTSCompilerExtensions = [
|
|
1570
|
+
{
|
|
1571
|
+
extension: ".marko",
|
|
1572
|
+
isMixedContent: false,
|
|
1573
|
+
scriptKind: ts.ScriptKind.Deferred
|
|
1574
|
+
}
|
|
1575
|
+
];
|
|
1514
1576
|
var ScriptService = {
|
|
1515
1577
|
commands: {
|
|
1516
1578
|
"$/showScriptOutput": async (uri) => {
|
|
@@ -1909,7 +1971,12 @@ function processScript(doc, tsProject) {
|
|
|
1909
1971
|
parsed,
|
|
1910
1972
|
lookup,
|
|
1911
1973
|
scriptLang: getScriptLang(filename, ts, host, markoScriptLang),
|
|
1912
|
-
runtimeTypesCode: (_a = getProjectTypeLibs(
|
|
1974
|
+
runtimeTypesCode: (_a = getProjectTypeLibs(
|
|
1975
|
+
tsProject.rootDir,
|
|
1976
|
+
markoProject,
|
|
1977
|
+
ts,
|
|
1978
|
+
host
|
|
1979
|
+
)) == null ? void 0 : _a.markoTypesCode,
|
|
1913
1980
|
componentFilename: getComponentFilename(filename)
|
|
1914
1981
|
});
|
|
1915
1982
|
}
|
|
@@ -1995,31 +2062,18 @@ function getTSProject(docFsPath) {
|
|
|
1995
2062
|
markoProject.cache.set(getTSProject, projectCache);
|
|
1996
2063
|
}
|
|
1997
2064
|
const { fileNames, options, projectReferences } = ts.parseJsonConfigFileContent(
|
|
1998
|
-
configPath && ts.readConfigFile(configPath, ts.sys.readFile).config ||
|
|
1999
|
-
compilerOptions: { lib: ["dom", "node", "esnext"] },
|
|
2000
|
-
include: []
|
|
2001
|
-
},
|
|
2065
|
+
configPath && ts.readConfigFile(configPath, ts.sys.readFile).config || defaultTSConfig,
|
|
2002
2066
|
ts.sys,
|
|
2003
2067
|
rootDir,
|
|
2004
|
-
|
|
2068
|
+
requiredTSCompilerOptions,
|
|
2005
2069
|
configPath,
|
|
2006
2070
|
void 0,
|
|
2007
|
-
|
|
2008
|
-
{
|
|
2009
|
-
extension: ".marko",
|
|
2010
|
-
isMixedContent: false,
|
|
2011
|
-
scriptKind: ts.ScriptKind.Deferred
|
|
2012
|
-
}
|
|
2013
|
-
]
|
|
2071
|
+
extraTSCompilerExtensions
|
|
2014
2072
|
);
|
|
2073
|
+
options.rootDir ??= rootDir;
|
|
2015
2074
|
const potentialGlobalFiles = new Set(
|
|
2016
2075
|
fileNames.filter((file) => /\.[cm]?ts$/.test(file))
|
|
2017
2076
|
);
|
|
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
2077
|
const tsPkgFile = configPath && ((_a = ts.resolveModuleName("typescript/package.json", configPath, options, ts.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
|
|
2024
2078
|
const defaultLibFile = path10.join(
|
|
2025
2079
|
tsPkgFile ? path10.join(tsPkgFile, "../lib") : __dirname,
|
|
@@ -2114,7 +2168,12 @@ function getTSProject(docFsPath) {
|
|
|
2114
2168
|
service: ts.createLanguageService(host),
|
|
2115
2169
|
markoProject,
|
|
2116
2170
|
markoScriptLang,
|
|
2117
|
-
markoProjectTypeLibs: getProjectTypeLibs(
|
|
2171
|
+
markoProjectTypeLibs: getProjectTypeLibs(
|
|
2172
|
+
options.rootDir,
|
|
2173
|
+
markoProject,
|
|
2174
|
+
ts,
|
|
2175
|
+
host
|
|
2176
|
+
)
|
|
2118
2177
|
};
|
|
2119
2178
|
projectCache.set(rootDir, tsProject);
|
|
2120
2179
|
return tsProject;
|