modern-monaco 0.2.0 → 0.2.2
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/cache.mjs +3 -3
- package/dist/core.mjs +78 -56
- package/dist/editor-core.mjs +2 -2
- package/dist/index.mjs +2 -26
- package/dist/lsp/{language-service.mjs → client.mjs} +2 -8
- package/dist/lsp/css/setup.mjs +10 -9
- package/dist/lsp/css/worker.mjs +42 -27
- package/dist/lsp/html/setup.mjs +12 -11
- package/dist/lsp/html/worker.mjs +42 -27
- package/dist/lsp/index.mjs +20 -0
- package/dist/lsp/json/setup.mjs +9 -8
- package/dist/lsp/json/worker.mjs +42 -27
- package/dist/lsp/typescript/setup.mjs +9 -9
- package/dist/lsp/typescript/worker.mjs +45 -30
- package/dist/shiki.mjs +3 -3
- package/dist/util.mjs +15 -12
- package/dist/workspace.mjs +22 -17
- package/package.json +7 -1
- package/types/workspace.d.ts +16 -7
package/dist/cache.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/cache.ts
|
|
2
|
-
import { defineProperty, openIDB, promisifyIDBRequest
|
|
2
|
+
import { defineProperty, normalizeURL, openIDB, promisifyIDBRequest } from "./util.mjs";
|
|
3
3
|
var IndexedDB = class {
|
|
4
4
|
#db;
|
|
5
5
|
constructor(name) {
|
|
@@ -43,7 +43,7 @@ var Cache = class {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
async fetch(url) {
|
|
46
|
-
url =
|
|
46
|
+
url = normalizeURL(url);
|
|
47
47
|
const storedRes = await this.query(url);
|
|
48
48
|
if (storedRes) {
|
|
49
49
|
return storedRes;
|
|
@@ -75,7 +75,7 @@ var Cache = class {
|
|
|
75
75
|
return res;
|
|
76
76
|
}
|
|
77
77
|
async query(key) {
|
|
78
|
-
const url =
|
|
78
|
+
const url = normalizeURL(key).href;
|
|
79
79
|
const file = await this._db.get(url);
|
|
80
80
|
if (file && file.headers) {
|
|
81
81
|
const headers = new Headers(file.headers);
|
package/dist/core.mjs
CHANGED
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// node_modules/.pnpm/@esm.sh+import-map@0.1.1/node_modules/@esm.sh/import-map/dist/import-map.mjs
|
|
2
|
+
function parseImportMapFromJson(json, baseURL) {
|
|
3
|
+
const importMap = {
|
|
4
|
+
$baseURL: new URL(baseURL ?? ".", "file:///").href,
|
|
5
|
+
imports: {},
|
|
6
|
+
scopes: {}
|
|
7
|
+
};
|
|
8
|
+
const v = JSON.parse(json);
|
|
9
|
+
if (isObject(v)) {
|
|
10
|
+
const { imports, scopes } = v;
|
|
11
|
+
if (isObject(imports)) {
|
|
12
|
+
validateImports(imports);
|
|
13
|
+
importMap.imports = imports;
|
|
14
|
+
}
|
|
15
|
+
if (isObject(scopes)) {
|
|
16
|
+
validateScopes(scopes);
|
|
17
|
+
importMap.scopes = scopes;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return importMap;
|
|
12
21
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
22
|
+
function validateImports(imports) {
|
|
23
|
+
for (const [k, v] of Object.entries(imports)) {
|
|
24
|
+
if (!v || typeof v !== "string") {
|
|
25
|
+
delete imports[k];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
15
28
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
function validateScopes(imports) {
|
|
30
|
+
for (const [k, v] of Object.entries(imports)) {
|
|
31
|
+
if (isObject(v)) {
|
|
32
|
+
validateImports(v);
|
|
33
|
+
} else {
|
|
34
|
+
delete imports[k];
|
|
21
35
|
}
|
|
22
|
-
|
|
23
|
-
timer = null;
|
|
24
|
-
fn();
|
|
25
|
-
}, delay);
|
|
26
|
-
};
|
|
36
|
+
}
|
|
27
37
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
let reject;
|
|
31
|
-
const promise = new Promise((res, rej) => {
|
|
32
|
-
resolve = res;
|
|
33
|
-
reject = rej;
|
|
34
|
-
});
|
|
35
|
-
return { promise, resolve, reject };
|
|
38
|
+
function isObject(v) {
|
|
39
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
// package.json
|
|
43
|
+
var version = "0.2.2";
|
|
44
|
+
|
|
38
45
|
// src/core.ts
|
|
39
|
-
import {
|
|
46
|
+
import { getExtnameFromLanguageId, getLanguageIdFromPath, grammars, initShiki, setDefaultWasmLoader, themes } from "./shiki.mjs";
|
|
47
|
+
import { initShikiMonacoTokenizer, registerShikiMonacoTokenizer } from "./shiki.mjs";
|
|
48
|
+
import { render } from "./shiki.mjs";
|
|
49
|
+
import { getWasmInstance } from "./shiki-wasm.mjs";
|
|
50
|
+
import { ErrorNotFound, Workspace } from "./workspace.mjs";
|
|
51
|
+
import { debunce, decode, isDigital } from "./util.mjs";
|
|
52
|
+
import { init as initLspClient } from "./lsp/client.mjs";
|
|
40
53
|
var editorProps = [
|
|
41
54
|
"autoDetectHighContrast",
|
|
42
55
|
"automaticLayout",
|
|
@@ -71,9 +84,9 @@ var editorProps = [
|
|
|
71
84
|
var errors = {
|
|
72
85
|
NotFound: ErrorNotFound
|
|
73
86
|
};
|
|
87
|
+
var cdnUrl = `https://esm.sh/modern-monaco@${version}`;
|
|
74
88
|
var syntaxes = [];
|
|
75
89
|
var lspProviders = {};
|
|
76
|
-
var { promise: editorWorkerPromise, resolve: onDidEditorWorkerResolve } = promiseWithResolvers();
|
|
77
90
|
var attr = (el, name) => el.getAttribute(name);
|
|
78
91
|
var style = (el, style2) => Object.assign(el.style, style2);
|
|
79
92
|
async function init(options) {
|
|
@@ -243,7 +256,7 @@ async function lazy(options) {
|
|
|
243
256
|
}
|
|
244
257
|
}
|
|
245
258
|
}
|
|
246
|
-
|
|
259
|
+
{
|
|
247
260
|
const monaco = await (monacoPromise ?? (monacoPromise = loadMonaco(highlighter, workspace, options?.lsp)));
|
|
248
261
|
const editor = monaco.editor.create(containerEl, renderOptions);
|
|
249
262
|
if (workspace) {
|
|
@@ -300,34 +313,49 @@ async function lazy(options) {
|
|
|
300
313
|
editor.setModel(monaco.editor.createModel(""));
|
|
301
314
|
}
|
|
302
315
|
if (prerenderEl) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}, 100);
|
|
312
|
-
});
|
|
316
|
+
setTimeout(() => {
|
|
317
|
+
const animate = prerenderEl.animate?.([{ opacity: 1 }, { opacity: 0 }], { duration: 200 });
|
|
318
|
+
if (animate) {
|
|
319
|
+
animate.finished.then(() => prerenderEl.remove());
|
|
320
|
+
} else {
|
|
321
|
+
setTimeout(() => prerenderEl.remove(), 200);
|
|
322
|
+
}
|
|
323
|
+
}, 200);
|
|
313
324
|
}
|
|
314
325
|
}
|
|
315
|
-
await createEditor();
|
|
316
326
|
}
|
|
317
327
|
}
|
|
318
328
|
);
|
|
319
329
|
}
|
|
320
|
-
await editorWorkerPromise;
|
|
321
330
|
}
|
|
322
331
|
function hydrate(options) {
|
|
323
332
|
return lazy(options);
|
|
324
333
|
}
|
|
325
334
|
async function loadMonaco(highlighter, workspace, lsp) {
|
|
326
|
-
|
|
327
|
-
|
|
335
|
+
let importmap = null;
|
|
336
|
+
let editorCoreModuleUrl = `${cdnUrl}/es2022/editor-core.mjs`;
|
|
337
|
+
let lspModuleUrl = `${cdnUrl}/es2022/lsp.mjs`;
|
|
338
|
+
if (importmap = document.querySelector("script[type='importmap']")) {
|
|
339
|
+
try {
|
|
340
|
+
const { imports = {} } = parseImportMapFromJson(importmap.textContent);
|
|
341
|
+
if (imports["modern-monaco/editor-core"]) {
|
|
342
|
+
editorCoreModuleUrl = imports["modern-monaco/editor-core"];
|
|
343
|
+
}
|
|
344
|
+
if (imports["modern-monaco/lsp"]) {
|
|
345
|
+
lspModuleUrl = imports["modern-monaco/lsp"];
|
|
346
|
+
}
|
|
347
|
+
} catch (error) {
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const builtinLSP = globalThis.MonacoEnvironment?.builtinLSP;
|
|
351
|
+
const [monaco, { builtinLSPProviders }] = await Promise.all([
|
|
352
|
+
import(editorCoreModuleUrl),
|
|
353
|
+
builtinLSP ? import(lspModuleUrl) : Promise.resolve({ builtinLSPProviders: {} })
|
|
354
|
+
]);
|
|
355
|
+
const lspProviderMap = { ...builtinLSPProviders, ...lspProviders, ...lsp?.providers };
|
|
328
356
|
workspace?.setupMonaco(monaco);
|
|
329
357
|
if (Object.keys(lspProviderMap).length > 0) {
|
|
330
|
-
|
|
358
|
+
initLspClient(monaco);
|
|
331
359
|
}
|
|
332
360
|
if (!document.getElementById("monaco-editor-core-css")) {
|
|
333
361
|
const styleEl = document.createElement("style");
|
|
@@ -339,13 +367,7 @@ async function loadMonaco(highlighter, workspace, lsp) {
|
|
|
339
367
|
Reflect.set(globalThis, "MonacoEnvironment", {
|
|
340
368
|
getWorker: async (_workerId, label) => {
|
|
341
369
|
if (label === "editorWorkerService") {
|
|
342
|
-
|
|
343
|
-
const onMessage = (e) => {
|
|
344
|
-
worker.removeEventListener("message", onMessage);
|
|
345
|
-
onDidEditorWorkerResolve();
|
|
346
|
-
};
|
|
347
|
-
worker.addEventListener("message", onMessage);
|
|
348
|
-
return worker;
|
|
370
|
+
return monaco.createEditorWorkerMain();
|
|
349
371
|
}
|
|
350
372
|
},
|
|
351
373
|
getLanguageIdFromUri: (uri) => getLanguageIdFromPath(uri.path),
|
package/dist/editor-core.mjs
CHANGED
|
@@ -198377,10 +198377,10 @@ function createEditorWorkerMain() {
|
|
|
198377
198377
|
if (workerUrl.origin !== location.origin) {
|
|
198378
198378
|
return new Worker(
|
|
198379
198379
|
URL.createObjectURL(new Blob([`import "${workerUrl.href}"`], { type: "application/javascript" })),
|
|
198380
|
-
{ type: "module" }
|
|
198380
|
+
{ type: "module", name: "editor-worker-main" }
|
|
198381
198381
|
);
|
|
198382
198382
|
}
|
|
198383
|
-
return new Worker(
|
|
198383
|
+
return new Worker(workerUrl, { type: "module", name: "editor-worker-main" });
|
|
198384
198384
|
}
|
|
198385
198385
|
export {
|
|
198386
198386
|
CancellationTokenSource2 as CancellationTokenSource,
|
package/dist/index.mjs
CHANGED
|
@@ -693,28 +693,6 @@ var vitesse_dark_default = {
|
|
|
693
693
|
type: "dark"
|
|
694
694
|
};
|
|
695
695
|
|
|
696
|
-
// src/lsp/index.ts
|
|
697
|
-
var builtinLSPProviders = {
|
|
698
|
-
html: {
|
|
699
|
-
// @ts-expect-error 'setup.js' is generated at build time
|
|
700
|
-
import: () => import("./lsp/html/setup.mjs")
|
|
701
|
-
},
|
|
702
|
-
css: {
|
|
703
|
-
aliases: ["less", "sass"],
|
|
704
|
-
// @ts-expect-error 'setup.js' is generated at build time
|
|
705
|
-
import: () => import("./lsp/css/setup.mjs")
|
|
706
|
-
},
|
|
707
|
-
json: {
|
|
708
|
-
// @ts-expect-error 'setup.js' is generated at build time
|
|
709
|
-
import: () => import("./lsp/json/setup.mjs")
|
|
710
|
-
},
|
|
711
|
-
typescript: {
|
|
712
|
-
aliases: ["javascript", "jsx", "tsx"],
|
|
713
|
-
// @ts-expect-error 'setup.js' is generated at build time
|
|
714
|
-
import: () => import("./lsp/typescript/setup.mjs")
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
|
-
|
|
718
696
|
// node_modules/.pnpm/tm-grammars@1.24.10/node_modules/tm-grammars/grammars/html.json
|
|
719
697
|
var html_default = {
|
|
720
698
|
displayName: "HTML",
|
|
@@ -29343,15 +29321,13 @@ var syntaxes = [
|
|
|
29343
29321
|
];
|
|
29344
29322
|
|
|
29345
29323
|
// src/index.ts
|
|
29346
|
-
import {
|
|
29324
|
+
import { registerSyntax, registerTheme } from "./core.mjs";
|
|
29347
29325
|
import { errors, hydrate, init, lazy, Workspace } from "./core.mjs";
|
|
29348
|
-
for (const [lang, provider] of Object.entries(builtinLSPProviders)) {
|
|
29349
|
-
registerLSPProvider(lang, provider);
|
|
29350
|
-
}
|
|
29351
29326
|
for (const syntax of syntaxes) {
|
|
29352
29327
|
registerSyntax(syntax);
|
|
29353
29328
|
}
|
|
29354
29329
|
registerTheme(vitesse_dark_default);
|
|
29330
|
+
Reflect.set(globalThis, "MonacoEnvironment", { builtinLSP: true });
|
|
29355
29331
|
export {
|
|
29356
29332
|
Workspace,
|
|
29357
29333
|
errors,
|
|
@@ -1181,7 +1181,7 @@ var Is;
|
|
|
1181
1181
|
Is2.typedArray = typedArray;
|
|
1182
1182
|
})(Is || (Is = {}));
|
|
1183
1183
|
|
|
1184
|
-
// src/lsp/
|
|
1184
|
+
// src/lsp/client.ts
|
|
1185
1185
|
import { cache } from "../cache.mjs";
|
|
1186
1186
|
var monaco;
|
|
1187
1187
|
function init(monacoNS) {
|
|
@@ -1222,7 +1222,7 @@ function registerBasicFeatures(languageId, worker, completionTriggerCharacters,
|
|
|
1222
1222
|
const { editor, languages } = monaco;
|
|
1223
1223
|
const onDispose = async (model) => {
|
|
1224
1224
|
const workerProxy = await worker.withSyncedResources([]);
|
|
1225
|
-
workerProxy.
|
|
1225
|
+
workerProxy.releaseDocument(model.uri.toString());
|
|
1226
1226
|
};
|
|
1227
1227
|
editor.onDidChangeModelLanguage(({ model, oldLanguage }) => {
|
|
1228
1228
|
if (oldLanguage === languageId) {
|
|
@@ -1263,12 +1263,6 @@ function registerBasicFeatures(languageId, worker, completionTriggerCharacters,
|
|
|
1263
1263
|
worker.getProxy().then((proxy) => proxy.fsNotify(kind, path, type));
|
|
1264
1264
|
}
|
|
1265
1265
|
});
|
|
1266
|
-
(async () => {
|
|
1267
|
-
const workerProxy = await worker.getProxy();
|
|
1268
|
-
for await (const [path, type] of workspace.fs.walk()) {
|
|
1269
|
-
workerProxy.fsNotify("create", path, type);
|
|
1270
|
-
}
|
|
1271
|
-
})();
|
|
1272
1266
|
}
|
|
1273
1267
|
}
|
|
1274
1268
|
function registerDiagnostics(languageId, worker) {
|
package/dist/lsp/css/setup.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/lsp/css/setup.ts
|
|
2
|
-
import
|
|
2
|
+
import { walk } from "../../workspace.mjs";
|
|
3
|
+
import * as client from "../client.mjs";
|
|
3
4
|
async function setup(monaco, languageId, languageSettings, formattingOptions, workspace) {
|
|
4
5
|
const { tabSize, insertSpaces, insertFinalNewline, trimFinalNewlines } = formattingOptions ?? {};
|
|
5
6
|
const createData = {
|
|
@@ -18,26 +19,26 @@ async function setup(monaco, languageId, languageSettings, formattingOptions, wo
|
|
|
18
19
|
spaceAroundSelectorSeparator: false,
|
|
19
20
|
braceStyle: "collapse"
|
|
20
21
|
},
|
|
21
|
-
workspace:
|
|
22
|
+
fs: workspace ? await walk(workspace.fs, "/") : void 0
|
|
22
23
|
};
|
|
23
24
|
const worker = monaco.editor.createWebWorker({
|
|
24
25
|
worker: getWorker(createData),
|
|
25
|
-
host:
|
|
26
|
+
host: client.createHost(workspace)
|
|
26
27
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
client.registerBasicFeatures(languageId, worker, ["/", "-", ":", "("], workspace);
|
|
29
|
+
client.registerCodeAction(languageId, worker);
|
|
30
|
+
client.registerColorPresentation(languageId, worker);
|
|
31
|
+
client.registerDocumentLinks(languageId, worker);
|
|
31
32
|
}
|
|
32
33
|
function createWebWorker() {
|
|
33
34
|
const workerUrl = new URL("./worker.mjs", import.meta.url);
|
|
34
35
|
if (workerUrl.origin !== location.origin) {
|
|
35
36
|
return new Worker(
|
|
36
37
|
URL.createObjectURL(new Blob([`import "${workerUrl.href}"`], { type: "application/javascript" })),
|
|
37
|
-
{ type: "module" }
|
|
38
|
+
{ type: "module", name: "css-worker" }
|
|
38
39
|
);
|
|
39
40
|
}
|
|
40
|
-
return new Worker(
|
|
41
|
+
return new Worker(workerUrl, { type: "module", name: "css-worker" });
|
|
41
42
|
}
|
|
42
43
|
function getWorker(createData) {
|
|
43
44
|
const worker = createWebWorker();
|
package/dist/lsp/css/worker.mjs
CHANGED
|
@@ -48125,21 +48125,36 @@ function getLESSLanguageService(options = defaultLanguageServiceOptions) {
|
|
|
48125
48125
|
|
|
48126
48126
|
// src/lsp/worker-base.ts
|
|
48127
48127
|
var WorkerBase = class {
|
|
48128
|
-
|
|
48129
|
-
this._ctx = _ctx;
|
|
48130
|
-
this._createData = _createData;
|
|
48131
|
-
this._createLanguageDocument = _createLanguageDocument;
|
|
48132
|
-
}
|
|
48133
|
-
#documentCache = /* @__PURE__ */ new Map();
|
|
48128
|
+
#ctx;
|
|
48134
48129
|
#fs;
|
|
48130
|
+
#documentCache = /* @__PURE__ */ new Map();
|
|
48131
|
+
#createLanguageDocument;
|
|
48132
|
+
constructor(ctx, createData, createLanguageDocument) {
|
|
48133
|
+
this.#ctx = ctx;
|
|
48134
|
+
if (createData.fs) {
|
|
48135
|
+
const dirs = /* @__PURE__ */ new Set(["/"]);
|
|
48136
|
+
this.#fs = new Map(createData.fs.map((path) => {
|
|
48137
|
+
const dir = path.slice(0, path.lastIndexOf("/"));
|
|
48138
|
+
if (dir) {
|
|
48139
|
+
dirs.add(dir);
|
|
48140
|
+
}
|
|
48141
|
+
return ["file://" + path, 1];
|
|
48142
|
+
}));
|
|
48143
|
+
for (const dir of dirs) {
|
|
48144
|
+
this.#fs.set("file://" + dir, 2);
|
|
48145
|
+
}
|
|
48146
|
+
createData.fs.length = 0;
|
|
48147
|
+
}
|
|
48148
|
+
this.#createLanguageDocument = createLanguageDocument;
|
|
48149
|
+
}
|
|
48135
48150
|
get hasFileSystemProvider() {
|
|
48136
|
-
return !!this
|
|
48151
|
+
return !!this.#fs;
|
|
48137
48152
|
}
|
|
48138
48153
|
get host() {
|
|
48139
|
-
return this.
|
|
48154
|
+
return this.#ctx.host;
|
|
48140
48155
|
}
|
|
48141
48156
|
getMirrorModels() {
|
|
48142
|
-
return this.
|
|
48157
|
+
return this.#ctx.getMirrorModels();
|
|
48143
48158
|
}
|
|
48144
48159
|
hasModel(fileName) {
|
|
48145
48160
|
const models = this.getMirrorModels();
|
|
@@ -48180,10 +48195,10 @@ var WorkerBase = class {
|
|
|
48180
48195
|
if (cached && cached[0] === version && cached[2]) {
|
|
48181
48196
|
return cached[2];
|
|
48182
48197
|
}
|
|
48183
|
-
if (!this
|
|
48198
|
+
if (!this.#createLanguageDocument) {
|
|
48184
48199
|
throw new Error("createLanguageDocument is not provided");
|
|
48185
48200
|
}
|
|
48186
|
-
const languageDocument = this
|
|
48201
|
+
const languageDocument = this.#createLanguageDocument(document);
|
|
48187
48202
|
this.#documentCache.set(uri, [version, document, languageDocument]);
|
|
48188
48203
|
return languageDocument;
|
|
48189
48204
|
}
|
|
@@ -48194,10 +48209,12 @@ var WorkerBase = class {
|
|
|
48194
48209
|
if (path.startsWith(uri)) {
|
|
48195
48210
|
const name = path.slice(uri.length);
|
|
48196
48211
|
if (!name.includes("/")) {
|
|
48197
|
-
if (type ===
|
|
48198
|
-
|
|
48199
|
-
|
|
48200
|
-
|
|
48212
|
+
if (type === 1) {
|
|
48213
|
+
if (!extensions || extensions.some((ext) => name.endsWith(ext))) {
|
|
48214
|
+
entries.push([name, 1]);
|
|
48215
|
+
}
|
|
48216
|
+
} else if (type === 2) {
|
|
48217
|
+
entries.push([name, 2]);
|
|
48201
48218
|
}
|
|
48202
48219
|
}
|
|
48203
48220
|
}
|
|
@@ -48206,8 +48223,8 @@ var WorkerBase = class {
|
|
|
48206
48223
|
return entries;
|
|
48207
48224
|
}
|
|
48208
48225
|
getFileSystemProvider() {
|
|
48209
|
-
if (this
|
|
48210
|
-
const host = this.
|
|
48226
|
+
if (this.#fs) {
|
|
48227
|
+
const host = this.#ctx.host;
|
|
48211
48228
|
return {
|
|
48212
48229
|
readDirectory: (uri) => {
|
|
48213
48230
|
return Promise.resolve(this.readDir(uri));
|
|
@@ -48224,29 +48241,27 @@ var WorkerBase = class {
|
|
|
48224
48241
|
}
|
|
48225
48242
|
// resolveReference implementes the `DocumentContext` interface
|
|
48226
48243
|
resolveReference(ref, baseUrl) {
|
|
48227
|
-
const
|
|
48228
|
-
|
|
48229
|
-
if (url.protocol === "file:" && url.pathname !== "/" && this.#fs && !this.#fs.has(href.endsWith("/") ? href.slice(0, -1) : href)) {
|
|
48244
|
+
const { protocol, pathname, href } = new URL(ref, baseUrl);
|
|
48245
|
+
if (protocol === "file:" && pathname !== "/" && this.#fs && !this.#fs.has(href.endsWith("/") ? href.slice(0, -1) : href)) {
|
|
48230
48246
|
return void 0;
|
|
48231
48247
|
}
|
|
48232
48248
|
return href;
|
|
48233
48249
|
}
|
|
48234
48250
|
// #region methods used by the host
|
|
48235
|
-
async
|
|
48251
|
+
async releaseDocument(uri) {
|
|
48236
48252
|
this.#documentCache.delete(uri);
|
|
48237
48253
|
}
|
|
48238
48254
|
async fsNotify(kind, path, type) {
|
|
48239
|
-
const
|
|
48240
|
-
const entries = this.#fs ?? (this.#fs = /* @__PURE__ */ new Map());
|
|
48255
|
+
const fs = this.#fs ?? (this.#fs = /* @__PURE__ */ new Map());
|
|
48241
48256
|
if (kind === "create") {
|
|
48242
48257
|
if (type) {
|
|
48243
|
-
|
|
48258
|
+
fs.set(path, type);
|
|
48244
48259
|
}
|
|
48245
48260
|
} else if (kind === "remove") {
|
|
48246
|
-
if (
|
|
48247
|
-
this.#documentCache.delete(
|
|
48261
|
+
if (fs.get(path) === 1) {
|
|
48262
|
+
this.#documentCache.delete(path);
|
|
48248
48263
|
}
|
|
48249
|
-
|
|
48264
|
+
fs.delete(path);
|
|
48250
48265
|
}
|
|
48251
48266
|
}
|
|
48252
48267
|
// #endregion
|
package/dist/lsp/html/setup.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/lsp/html/setup.ts
|
|
2
|
-
import
|
|
2
|
+
import { walk } from "../../workspace.mjs";
|
|
3
|
+
import * as client from "../client.mjs";
|
|
3
4
|
async function setup(monaco, languageId, languageSettings, formattingOptions, workspace) {
|
|
4
5
|
const { editor, languages } = monaco;
|
|
5
6
|
const { tabSize, insertSpaces, insertFinalNewline, trimFinalNewlines } = formattingOptions ?? {};
|
|
@@ -26,18 +27,18 @@ async function setup(monaco, languageId, languageSettings, formattingOptions, wo
|
|
|
26
27
|
useDefaultDataProvider: true,
|
|
27
28
|
dataProviders: Array.isArray(languageSettings?.customTags) ? { custom: { version: 1.1, tags: languageSettings.customTags } } : void 0
|
|
28
29
|
},
|
|
29
|
-
workspace:
|
|
30
|
+
fs: workspace ? await walk(workspace.fs, "/") : void 0
|
|
30
31
|
};
|
|
31
32
|
const htmlWorker = editor.createWebWorker({
|
|
32
33
|
worker: getWorker(createData),
|
|
33
|
-
host:
|
|
34
|
+
host: client.createHost(workspace)
|
|
34
35
|
});
|
|
35
|
-
const workerWithEmbeddedLanguages =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
const workerWithEmbeddedLanguages = client.createWorkerWithEmbeddedLanguages(htmlWorker);
|
|
37
|
+
client.registerEmbedded(languageId, workerWithEmbeddedLanguages, ["css", "javascript", "importmap"]);
|
|
38
|
+
client.registerBasicFeatures(languageId, workerWithEmbeddedLanguages, ["<", "/", "=", '"'], workspace);
|
|
39
|
+
client.registerAutoComplete(languageId, workerWithEmbeddedLanguages, [">", "/", "="]);
|
|
40
|
+
client.registerColorPresentation(languageId, workerWithEmbeddedLanguages);
|
|
41
|
+
client.registerDocumentLinks(languageId, workerWithEmbeddedLanguages);
|
|
41
42
|
languages.registerCodeLensProvider(languageId, {
|
|
42
43
|
provideCodeLenses: (model, _token) => {
|
|
43
44
|
const m = model.findNextMatch(
|
|
@@ -81,10 +82,10 @@ function createWebWorker() {
|
|
|
81
82
|
if (workerUrl.origin !== location.origin) {
|
|
82
83
|
return new Worker(
|
|
83
84
|
URL.createObjectURL(new Blob([`import "${workerUrl.href}"`], { type: "application/javascript" })),
|
|
84
|
-
{ type: "module" }
|
|
85
|
+
{ type: "module", name: "html-worker" }
|
|
85
86
|
);
|
|
86
87
|
}
|
|
87
|
-
return new Worker(
|
|
88
|
+
return new Worker(workerUrl, { type: "module", name: "html-worker" });
|
|
88
89
|
}
|
|
89
90
|
function getWorker(createData) {
|
|
90
91
|
const worker = createWebWorker();
|
package/dist/lsp/html/worker.mjs
CHANGED
|
@@ -22052,21 +22052,36 @@ function getAttributeLanguage(attributeName) {
|
|
|
22052
22052
|
|
|
22053
22053
|
// src/lsp/worker-base.ts
|
|
22054
22054
|
var WorkerBase = class {
|
|
22055
|
-
|
|
22056
|
-
this._ctx = _ctx;
|
|
22057
|
-
this._createData = _createData;
|
|
22058
|
-
this._createLanguageDocument = _createLanguageDocument;
|
|
22059
|
-
}
|
|
22060
|
-
#documentCache = /* @__PURE__ */ new Map();
|
|
22055
|
+
#ctx;
|
|
22061
22056
|
#fs;
|
|
22057
|
+
#documentCache = /* @__PURE__ */ new Map();
|
|
22058
|
+
#createLanguageDocument;
|
|
22059
|
+
constructor(ctx, createData, createLanguageDocument) {
|
|
22060
|
+
this.#ctx = ctx;
|
|
22061
|
+
if (createData.fs) {
|
|
22062
|
+
const dirs = /* @__PURE__ */ new Set(["/"]);
|
|
22063
|
+
this.#fs = new Map(createData.fs.map((path) => {
|
|
22064
|
+
const dir = path.slice(0, path.lastIndexOf("/"));
|
|
22065
|
+
if (dir) {
|
|
22066
|
+
dirs.add(dir);
|
|
22067
|
+
}
|
|
22068
|
+
return ["file://" + path, 1];
|
|
22069
|
+
}));
|
|
22070
|
+
for (const dir of dirs) {
|
|
22071
|
+
this.#fs.set("file://" + dir, 2);
|
|
22072
|
+
}
|
|
22073
|
+
createData.fs.length = 0;
|
|
22074
|
+
}
|
|
22075
|
+
this.#createLanguageDocument = createLanguageDocument;
|
|
22076
|
+
}
|
|
22062
22077
|
get hasFileSystemProvider() {
|
|
22063
|
-
return !!this
|
|
22078
|
+
return !!this.#fs;
|
|
22064
22079
|
}
|
|
22065
22080
|
get host() {
|
|
22066
|
-
return this.
|
|
22081
|
+
return this.#ctx.host;
|
|
22067
22082
|
}
|
|
22068
22083
|
getMirrorModels() {
|
|
22069
|
-
return this.
|
|
22084
|
+
return this.#ctx.getMirrorModels();
|
|
22070
22085
|
}
|
|
22071
22086
|
hasModel(fileName) {
|
|
22072
22087
|
const models = this.getMirrorModels();
|
|
@@ -22107,10 +22122,10 @@ var WorkerBase = class {
|
|
|
22107
22122
|
if (cached && cached[0] === version && cached[2]) {
|
|
22108
22123
|
return cached[2];
|
|
22109
22124
|
}
|
|
22110
|
-
if (!this
|
|
22125
|
+
if (!this.#createLanguageDocument) {
|
|
22111
22126
|
throw new Error("createLanguageDocument is not provided");
|
|
22112
22127
|
}
|
|
22113
|
-
const languageDocument = this
|
|
22128
|
+
const languageDocument = this.#createLanguageDocument(document);
|
|
22114
22129
|
this.#documentCache.set(uri, [version, document, languageDocument]);
|
|
22115
22130
|
return languageDocument;
|
|
22116
22131
|
}
|
|
@@ -22121,10 +22136,12 @@ var WorkerBase = class {
|
|
|
22121
22136
|
if (path.startsWith(uri)) {
|
|
22122
22137
|
const name = path.slice(uri.length);
|
|
22123
22138
|
if (!name.includes("/")) {
|
|
22124
|
-
if (type ===
|
|
22125
|
-
|
|
22126
|
-
|
|
22127
|
-
|
|
22139
|
+
if (type === 1) {
|
|
22140
|
+
if (!extensions || extensions.some((ext) => name.endsWith(ext))) {
|
|
22141
|
+
entries.push([name, 1]);
|
|
22142
|
+
}
|
|
22143
|
+
} else if (type === 2) {
|
|
22144
|
+
entries.push([name, 2]);
|
|
22128
22145
|
}
|
|
22129
22146
|
}
|
|
22130
22147
|
}
|
|
@@ -22133,8 +22150,8 @@ var WorkerBase = class {
|
|
|
22133
22150
|
return entries;
|
|
22134
22151
|
}
|
|
22135
22152
|
getFileSystemProvider() {
|
|
22136
|
-
if (this
|
|
22137
|
-
const host = this.
|
|
22153
|
+
if (this.#fs) {
|
|
22154
|
+
const host = this.#ctx.host;
|
|
22138
22155
|
return {
|
|
22139
22156
|
readDirectory: (uri) => {
|
|
22140
22157
|
return Promise.resolve(this.readDir(uri));
|
|
@@ -22151,29 +22168,27 @@ var WorkerBase = class {
|
|
|
22151
22168
|
}
|
|
22152
22169
|
// resolveReference implementes the `DocumentContext` interface
|
|
22153
22170
|
resolveReference(ref, baseUrl) {
|
|
22154
|
-
const
|
|
22155
|
-
|
|
22156
|
-
if (url.protocol === "file:" && url.pathname !== "/" && this.#fs && !this.#fs.has(href.endsWith("/") ? href.slice(0, -1) : href)) {
|
|
22171
|
+
const { protocol, pathname, href } = new URL(ref, baseUrl);
|
|
22172
|
+
if (protocol === "file:" && pathname !== "/" && this.#fs && !this.#fs.has(href.endsWith("/") ? href.slice(0, -1) : href)) {
|
|
22157
22173
|
return void 0;
|
|
22158
22174
|
}
|
|
22159
22175
|
return href;
|
|
22160
22176
|
}
|
|
22161
22177
|
// #region methods used by the host
|
|
22162
|
-
async
|
|
22178
|
+
async releaseDocument(uri) {
|
|
22163
22179
|
this.#documentCache.delete(uri);
|
|
22164
22180
|
}
|
|
22165
22181
|
async fsNotify(kind, path, type) {
|
|
22166
|
-
const
|
|
22167
|
-
const entries = this.#fs ?? (this.#fs = /* @__PURE__ */ new Map());
|
|
22182
|
+
const fs = this.#fs ?? (this.#fs = /* @__PURE__ */ new Map());
|
|
22168
22183
|
if (kind === "create") {
|
|
22169
22184
|
if (type) {
|
|
22170
|
-
|
|
22185
|
+
fs.set(path, type);
|
|
22171
22186
|
}
|
|
22172
22187
|
} else if (kind === "remove") {
|
|
22173
|
-
if (
|
|
22174
|
-
this.#documentCache.delete(
|
|
22188
|
+
if (fs.get(path) === 1) {
|
|
22189
|
+
this.#documentCache.delete(path);
|
|
22175
22190
|
}
|
|
22176
|
-
|
|
22191
|
+
fs.delete(path);
|
|
22177
22192
|
}
|
|
22178
22193
|
}
|
|
22179
22194
|
// #endregion
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/lsp/index.ts
|
|
2
|
+
var builtinLSPProviders = {
|
|
3
|
+
html: {
|
|
4
|
+
import: () => import("./html/setup.mjs")
|
|
5
|
+
},
|
|
6
|
+
css: {
|
|
7
|
+
aliases: ["less", "sass"],
|
|
8
|
+
import: () => import("./css/setup.mjs")
|
|
9
|
+
},
|
|
10
|
+
json: {
|
|
11
|
+
import: () => import("./json/setup.mjs")
|
|
12
|
+
},
|
|
13
|
+
typescript: {
|
|
14
|
+
aliases: ["javascript", "jsx", "tsx"],
|
|
15
|
+
import: () => import("./typescript/setup.mjs")
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
builtinLSPProviders
|
|
20
|
+
};
|