modern-monaco 0.1.8 → 0.2.0
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/README.md +2 -4
- package/dist/{cache.js → cache.mjs} +1 -1
- package/dist/{core.js → core.mjs} +23 -46
- package/dist/{editor-core.js → editor-core.mjs} +108795 -88348
- package/dist/editor-worker-main.mjs +5 -0
- package/dist/{editor-worker.js → editor-worker.mjs} +5854 -4779
- package/dist/{index.js → index.mjs} +17 -15
- package/dist/lsp/css/{setup.js → setup.mjs} +19 -12
- package/dist/lsp/css/{worker.js → worker.mjs} +18 -23
- package/dist/lsp/html/{setup.js → setup.mjs} +19 -12
- package/dist/lsp/html/{worker.js → worker.mjs} +18 -23
- package/dist/lsp/json/{setup.js → setup.mjs} +19 -12
- package/dist/lsp/json/{worker.js → worker.mjs} +19 -24
- package/dist/lsp/{language-service.js → language-service.mjs} +7 -7
- package/dist/lsp/typescript/{setup.js → setup.mjs} +22 -15
- package/dist/lsp/typescript/{worker.js → worker.mjs} +22 -26
- package/dist/{shiki-wasm.js → shiki-wasm.mjs} +1 -1
- package/dist/{shiki.js → shiki.mjs} +13 -10
- package/dist/ssr/{index.js → index.mjs} +4 -4
- package/dist/ssr/{workerd.js → workerd.mjs} +3 -3
- package/dist/{workspace.js → workspace.mjs} +16 -12
- package/package.json +19 -19
- package/types/core.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/lsp.d.ts +2 -5
- package/types/monaco.d.ts +652 -278
- package/types/workspace.d.ts +5 -1
- /package/dist/lsp/typescript/{libs.js → libs.mjs} +0 -0
- /package/dist/{util.js → util.mjs} +0 -0
|
@@ -94,11 +94,11 @@ function isSameImports(a, b) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// src/lsp/typescript/setup.ts
|
|
97
|
-
import { cache } from "../../cache.
|
|
98
|
-
import { ErrorNotFound } from "../../workspace.
|
|
99
|
-
import * as ls from "../language-service.
|
|
97
|
+
import { cache } from "../../cache.mjs";
|
|
98
|
+
import { ErrorNotFound } from "../../workspace.mjs";
|
|
99
|
+
import * as ls from "../language-service.mjs";
|
|
100
100
|
var worker = null;
|
|
101
|
-
async function setup(monaco, languageId,
|
|
101
|
+
async function setup(monaco, languageId, languageSettings, formattingOptions, workspace) {
|
|
102
102
|
if (!worker) {
|
|
103
103
|
worker = createWorker(monaco, workspace, languageSettings, formattingOptions);
|
|
104
104
|
}
|
|
@@ -110,12 +110,6 @@ async function setup(monaco, languageId, workspace, languageSettings, formatting
|
|
|
110
110
|
ls.registerSignatureHelp(languageId, worker, ["(", ","]);
|
|
111
111
|
ls.registerCodeAction(languageId, worker);
|
|
112
112
|
}
|
|
113
|
-
function getWorkerUrl() {
|
|
114
|
-
const i = () => import("./worker.js");
|
|
115
|
-
const m = getWorkerUrl.toString().match(/import\(['"](.+?)['"]\)/);
|
|
116
|
-
if (!m) throw new Error("worker url not found", { cause: i });
|
|
117
|
-
return new URL(m[1], import.meta.url);
|
|
118
|
-
}
|
|
119
113
|
async function createWorker(monaco, workspace, languageSettings, formattingOptions) {
|
|
120
114
|
const fs = workspace?.fs;
|
|
121
115
|
const defaultCompilerOptions = {
|
|
@@ -173,13 +167,12 @@ async function createWorker(monaco, workspace, languageSettings, formattingOptio
|
|
|
173
167
|
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: insertSpaces
|
|
174
168
|
},
|
|
175
169
|
importMap,
|
|
176
|
-
types: typesStore.types
|
|
170
|
+
types: typesStore.types,
|
|
171
|
+
workspace: !!workspace
|
|
177
172
|
};
|
|
178
173
|
const worker2 = monaco.editor.createWebWorker({
|
|
179
|
-
|
|
180
|
-
label: "typescript",
|
|
174
|
+
worker: getWorker(createData),
|
|
181
175
|
keepIdleModels: true,
|
|
182
|
-
createData,
|
|
183
176
|
host: {
|
|
184
177
|
openModel: async (uri) => {
|
|
185
178
|
if (!workspace) {
|
|
@@ -284,6 +277,21 @@ async function createWorker(monaco, workspace, languageSettings, formattingOptio
|
|
|
284
277
|
});
|
|
285
278
|
return worker2;
|
|
286
279
|
}
|
|
280
|
+
function createWebWorker() {
|
|
281
|
+
const workerUrl = new URL("./worker.mjs", import.meta.url);
|
|
282
|
+
if (workerUrl.origin !== location.origin) {
|
|
283
|
+
return new Worker(
|
|
284
|
+
URL.createObjectURL(new Blob([`import "${workerUrl.href}"`], { type: "application/javascript" })),
|
|
285
|
+
{ type: "module" }
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
return new Worker(new URL("./worker.mjs", import.meta.url), { type: "module" });
|
|
289
|
+
}
|
|
290
|
+
function getWorker(createData) {
|
|
291
|
+
const worker2 = createWebWorker();
|
|
292
|
+
worker2.postMessage(createData);
|
|
293
|
+
return worker2;
|
|
294
|
+
}
|
|
287
295
|
var TypesSet = class {
|
|
288
296
|
_types = {};
|
|
289
297
|
_removedtypes = {};
|
|
@@ -418,7 +426,6 @@ function parseJsonc(text) {
|
|
|
418
426
|
}
|
|
419
427
|
}
|
|
420
428
|
export {
|
|
421
|
-
getWorkerUrl,
|
|
422
429
|
loadImportMap,
|
|
423
430
|
setup
|
|
424
431
|
};
|
|
@@ -1466,14 +1466,15 @@ function getWellformedEdit(textEdit) {
|
|
|
1466
1466
|
|
|
1467
1467
|
// src/lsp/worker-base.ts
|
|
1468
1468
|
var WorkerBase = class {
|
|
1469
|
-
constructor(_ctx, _createLanguageDocument) {
|
|
1469
|
+
constructor(_ctx, _createData, _createLanguageDocument) {
|
|
1470
1470
|
this._ctx = _ctx;
|
|
1471
|
+
this._createData = _createData;
|
|
1471
1472
|
this._createLanguageDocument = _createLanguageDocument;
|
|
1472
1473
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1474
|
+
#documentCache = /* @__PURE__ */ new Map();
|
|
1475
|
+
#fs;
|
|
1475
1476
|
get hasFileSystemProvider() {
|
|
1476
|
-
return !!this.
|
|
1477
|
+
return !!this._createData.workspace;
|
|
1477
1478
|
}
|
|
1478
1479
|
get host() {
|
|
1479
1480
|
return this._ctx.host;
|
|
@@ -1506,17 +1507,17 @@ var WorkerBase = class {
|
|
|
1506
1507
|
if (!model) {
|
|
1507
1508
|
return null;
|
|
1508
1509
|
}
|
|
1509
|
-
const cached = this.
|
|
1510
|
+
const cached = this.#documentCache.get(uri);
|
|
1510
1511
|
if (cached && cached[0] === model.version) {
|
|
1511
1512
|
return cached[1];
|
|
1512
1513
|
}
|
|
1513
1514
|
const document2 = TextDocument2.create(uri, "-", model.version, model.getValue());
|
|
1514
|
-
this.
|
|
1515
|
+
this.#documentCache.set(uri, [model.version, document2, void 0]);
|
|
1515
1516
|
return document2;
|
|
1516
1517
|
}
|
|
1517
1518
|
getLanguageDocument(document2) {
|
|
1518
1519
|
const { uri, version } = document2;
|
|
1519
|
-
const cached = this.
|
|
1520
|
+
const cached = this.#documentCache.get(uri);
|
|
1520
1521
|
if (cached && cached[0] === version && cached[2]) {
|
|
1521
1522
|
return cached[2];
|
|
1522
1523
|
}
|
|
@@ -1524,14 +1525,13 @@ var WorkerBase = class {
|
|
|
1524
1525
|
throw new Error("createLanguageDocument is not provided");
|
|
1525
1526
|
}
|
|
1526
1527
|
const languageDocument = this._createLanguageDocument(document2);
|
|
1527
|
-
this.
|
|
1528
|
+
this.#documentCache.set(uri, [version, document2, languageDocument]);
|
|
1528
1529
|
return languageDocument;
|
|
1529
1530
|
}
|
|
1530
1531
|
readDir(uri, extensions) {
|
|
1531
1532
|
const entries = [];
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
for (const [path, type] of fsTree) {
|
|
1533
|
+
if (this.#fs) {
|
|
1534
|
+
for (const [path, type] of this.#fs) {
|
|
1535
1535
|
if (path.startsWith(uri)) {
|
|
1536
1536
|
const name = path.slice(uri.length);
|
|
1537
1537
|
if (!name.includes("/")) {
|
|
@@ -1567,30 +1567,25 @@ var WorkerBase = class {
|
|
|
1567
1567
|
resolveReference(ref, baseUrl) {
|
|
1568
1568
|
const url = new URL(ref, baseUrl);
|
|
1569
1569
|
const href = url.href;
|
|
1570
|
-
if (url.protocol === "file:" && this.
|
|
1571
|
-
|
|
1572
|
-
return void 0;
|
|
1573
|
-
}
|
|
1570
|
+
if (url.protocol === "file:" && url.pathname !== "/" && this.#fs && !this.#fs.has(href.endsWith("/") ? href.slice(0, -1) : href)) {
|
|
1571
|
+
return void 0;
|
|
1574
1572
|
}
|
|
1575
1573
|
return href;
|
|
1576
1574
|
}
|
|
1577
1575
|
// #region methods used by the host
|
|
1578
1576
|
async removeDocumentCache(uri) {
|
|
1579
|
-
this.
|
|
1580
|
-
}
|
|
1581
|
-
async syncFSEntries(entries) {
|
|
1582
|
-
this._fsEntries = new Map(entries);
|
|
1577
|
+
this.#documentCache.delete(uri);
|
|
1583
1578
|
}
|
|
1584
1579
|
async fsNotify(kind, path, type) {
|
|
1585
1580
|
const url = "file://" + path;
|
|
1586
|
-
const entries = this
|
|
1581
|
+
const entries = this.#fs ?? (this.#fs = /* @__PURE__ */ new Map());
|
|
1587
1582
|
if (kind === "create") {
|
|
1588
1583
|
if (type) {
|
|
1589
1584
|
entries.set(url, type);
|
|
1590
1585
|
}
|
|
1591
1586
|
} else if (kind === "remove") {
|
|
1592
1587
|
if (entries.get(url) === 1 /* File */) {
|
|
1593
|
-
this.
|
|
1588
|
+
this.#documentCache.delete(url);
|
|
1594
1589
|
}
|
|
1595
1590
|
entries.delete(url);
|
|
1596
1591
|
}
|
|
@@ -1599,17 +1594,17 @@ var WorkerBase = class {
|
|
|
1599
1594
|
};
|
|
1600
1595
|
|
|
1601
1596
|
// src/lsp/typescript/worker.ts
|
|
1602
|
-
import libs from "./libs.
|
|
1603
|
-
import { cache } from "../../cache.
|
|
1604
|
-
import { initializeWorker } from "../../editor-worker.
|
|
1597
|
+
import libs from "./libs.mjs";
|
|
1598
|
+
import { cache } from "../../cache.mjs";
|
|
1599
|
+
import { initializeWorker } from "../../editor-worker.mjs";
|
|
1605
1600
|
var TypeScriptWorker = class extends WorkerBase {
|
|
1606
1601
|
#compilerOptions;
|
|
1602
|
+
#languageService;
|
|
1607
1603
|
#formatOptions;
|
|
1608
1604
|
#importMap;
|
|
1609
1605
|
#importMapVersion;
|
|
1610
1606
|
#isBlankImportMap;
|
|
1611
1607
|
#types;
|
|
1612
|
-
#languageService = ts.createLanguageService(this);
|
|
1613
1608
|
#urlMappings = /* @__PURE__ */ new Map();
|
|
1614
1609
|
#typesMappings = /* @__PURE__ */ new Map();
|
|
1615
1610
|
#httpLibs = /* @__PURE__ */ new Map();
|
|
@@ -1622,8 +1617,9 @@ var TypeScriptWorker = class extends WorkerBase {
|
|
|
1622
1617
|
#fetchPromises = /* @__PURE__ */ new Map();
|
|
1623
1618
|
#httpDocumentCache = /* @__PURE__ */ new Map();
|
|
1624
1619
|
constructor(ctx, createData) {
|
|
1625
|
-
super(ctx);
|
|
1620
|
+
super(ctx, createData);
|
|
1626
1621
|
this.#compilerOptions = ts.convertCompilerOptionsFromJson(createData.compilerOptions, ".").options;
|
|
1622
|
+
this.#languageService = ts.createLanguageService(this);
|
|
1627
1623
|
this.#importMap = createData.importMap;
|
|
1628
1624
|
this.#importMapVersion = 0;
|
|
1629
1625
|
this.#isBlankImportMap = isBlankImportMap(createData.importMap);
|