@volar/monaco 1.6.7 → 1.6.9
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/out/editor.js +1 -1
- package/out/worker.d.ts +3 -22
- package/out/worker.js +39 -193
- package/package.json +4 -3
package/out/editor.js
CHANGED
|
@@ -38,7 +38,7 @@ var editor;
|
|
|
38
38
|
let timer;
|
|
39
39
|
const changeSubscription = model.onDidChangeContent(() => {
|
|
40
40
|
clearTimeout(timer);
|
|
41
|
-
timer = setTimeout(() => doValidation(model),
|
|
41
|
+
timer = setTimeout(() => doValidation(model), 250);
|
|
42
42
|
});
|
|
43
43
|
const visibleSubscription = model.onDidChangeAttached(() => {
|
|
44
44
|
if (model.isAttachedToEditor()) {
|
package/out/worker.d.ts
CHANGED
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
import { type Config } from '@volar/language-service';
|
|
2
2
|
import type * as monaco from 'monaco-editor-core';
|
|
3
3
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
import * as webFs from '@volar/web-fs';
|
|
5
|
+
export * from '@volar/web-fs';
|
|
4
6
|
export declare function createLanguageService(options: {
|
|
5
7
|
workerContext: monaco.worker.IWorkerContext<any>;
|
|
6
|
-
dtsHost?:
|
|
8
|
+
dtsHost?: webFs.IDtsHost;
|
|
7
9
|
config: Config;
|
|
8
10
|
typescript?: {
|
|
9
11
|
module: typeof import('typescript/lib/tsserverlibrary');
|
|
10
12
|
compilerOptions: ts.CompilerOptions;
|
|
11
13
|
};
|
|
12
14
|
}): {};
|
|
13
|
-
export declare function createBaseDtsHost(cdn: string, versions?: Record<string, string>, flat?: (pkg: string, version: string | undefined) => Promise<string[]>, onFetch?: (fileName: string, text: string) => void): CdnDtsHost;
|
|
14
|
-
export declare function createJsDelivrDtsHost(versions?: Record<string, string>, onFetch?: (fileName: string, text: string) => void): CdnDtsHost;
|
|
15
|
-
export interface DtsHost {
|
|
16
|
-
readFile(fileName: string): Thenable<string | undefined>;
|
|
17
|
-
getVersion(): Thenable<number>;
|
|
18
|
-
}
|
|
19
|
-
declare class CdnDtsHost implements DtsHost {
|
|
20
|
-
private cdn;
|
|
21
|
-
private versions;
|
|
22
|
-
private flat?;
|
|
23
|
-
private onFetch?;
|
|
24
|
-
files: Map<string, Promise<string | undefined>>;
|
|
25
|
-
flatResult: Map<string, Promise<string[]>>;
|
|
26
|
-
lastUpdateFilesSize: number;
|
|
27
|
-
constructor(cdn: string, versions?: Record<string, string>, flat?: ((pkg: string, version: string | undefined) => Promise<string[]>) | undefined, onFetch?: ((fileName: string, text: string) => void) | undefined);
|
|
28
|
-
getVersion(): Promise<number>;
|
|
29
|
-
readFile(fileName: string): Promise<string | undefined>;
|
|
30
|
-
fetchFile(fileName: string): Promise<string | undefined>;
|
|
31
|
-
resolveRequestFileName(fileName: string): string;
|
|
32
|
-
}
|
|
33
|
-
export {};
|
package/out/worker.js
CHANGED
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
17
|
+
exports.createLanguageService = void 0;
|
|
4
18
|
const language_service_1 = require("@volar/language-service");
|
|
5
19
|
const vscode_uri_1 = require("vscode-uri");
|
|
20
|
+
const webFs = require("@volar/web-fs");
|
|
21
|
+
__exportStar(require("@volar/web-fs"), exports);
|
|
6
22
|
function createLanguageService(options) {
|
|
23
|
+
let dtsClientVersion = 0;
|
|
7
24
|
const ts = options.typescript?.module;
|
|
8
|
-
const dtsFiles = new Map();
|
|
9
25
|
const config = options.config ?? {};
|
|
10
26
|
const compilerOptions = options.typescript?.compilerOptions ?? {};
|
|
11
|
-
|
|
12
|
-
|
|
27
|
+
const host = createLanguageServiceHost();
|
|
28
|
+
const languageService = (0, language_service_1.createLanguageService)({ typescript: ts }, {
|
|
13
29
|
uriToFileName: uri => vscode_uri_1.URI.parse(uri).fsPath.replace(/\\/g, '/'),
|
|
14
30
|
fileNameToUri: fileName => vscode_uri_1.URI.file(fileName).toString(),
|
|
15
31
|
rootUri: vscode_uri_1.URI.file('/'),
|
|
16
32
|
}, config, host);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
const dtsClient = options.dtsHost ? webFs.createDtsClient(options.dtsHost) : undefined;
|
|
34
|
+
if (!dtsClient) {
|
|
35
|
+
return languageService;
|
|
36
|
+
}
|
|
20
37
|
class InnocentRabbit {
|
|
21
38
|
}
|
|
22
39
|
;
|
|
23
40
|
for (const api in languageService) {
|
|
24
41
|
const isFunction = typeof languageService[api] === 'function';
|
|
25
|
-
;
|
|
26
42
|
if (!isFunction) {
|
|
27
43
|
InnocentRabbit.prototype[api] = () => languageService[api];
|
|
28
44
|
continue;
|
|
@@ -31,35 +47,13 @@ function createLanguageService(options) {
|
|
|
31
47
|
if (!options.dtsHost) {
|
|
32
48
|
return languageService[api](...args);
|
|
33
49
|
}
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
let lastDtsClientVersion = dtsClientVersion;
|
|
51
|
+
let result = await languageService[api](...args);
|
|
52
|
+
dtsClientVersion = await dtsClient.sync();
|
|
53
|
+
while (lastDtsClientVersion !== dtsClientVersion) {
|
|
54
|
+
lastDtsClientVersion = dtsClientVersion;
|
|
38
55
|
result = await languageService[api](...args);
|
|
39
|
-
|
|
40
|
-
while (newVersion !== oldVersion) {
|
|
41
|
-
oldVersion = newVersion;
|
|
42
|
-
if (newVersion !== dtsVersion) {
|
|
43
|
-
dtsVersion = newVersion;
|
|
44
|
-
toClear.add(languageService);
|
|
45
|
-
languageService = (0, language_service_1.createLanguageService)({ typescript: ts }, {
|
|
46
|
-
rootUri: vscode_uri_1.URI.file('/'),
|
|
47
|
-
uriToFileName: (uri) => vscode_uri_1.URI.parse(uri).fsPath.replace(/\\/g, '/'),
|
|
48
|
-
fileNameToUri: (fileName) => vscode_uri_1.URI.file(fileName).toString(),
|
|
49
|
-
}, config, host);
|
|
50
|
-
}
|
|
51
|
-
result = await languageService[api](...args);
|
|
52
|
-
newVersion = await options.dtsHost.getVersion();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
runningApis--;
|
|
57
|
-
}
|
|
58
|
-
if (runningApis === 0 && toClear.size > 0) {
|
|
59
|
-
for (const languageService of toClear) {
|
|
60
|
-
languageService.dispose();
|
|
61
|
-
}
|
|
62
|
-
toClear.clear();
|
|
56
|
+
dtsClientVersion = await dtsClient.sync();
|
|
63
57
|
}
|
|
64
58
|
return result;
|
|
65
59
|
};
|
|
@@ -75,7 +69,7 @@ function createLanguageService(options) {
|
|
|
75
69
|
const models = options.workerContext.getMirrorModels();
|
|
76
70
|
if (modelVersions.size === options.workerContext.getMirrorModels().length) {
|
|
77
71
|
if (models.every(model => modelVersions.get(model) === model.version)) {
|
|
78
|
-
return projectVersion.toString();
|
|
72
|
+
return dtsClientVersion.toString() + ':' + projectVersion.toString();
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
75
|
modelVersions.clear();
|
|
@@ -83,7 +77,10 @@ function createLanguageService(options) {
|
|
|
83
77
|
modelVersions.set(model, model.version);
|
|
84
78
|
}
|
|
85
79
|
projectVersion++;
|
|
86
|
-
return projectVersion.toString();
|
|
80
|
+
return dtsClientVersion.toString() + ':' + projectVersion.toString();
|
|
81
|
+
},
|
|
82
|
+
getTypeRootsVersion() {
|
|
83
|
+
return dtsClientVersion;
|
|
87
84
|
},
|
|
88
85
|
getScriptFileNames() {
|
|
89
86
|
const models = options.workerContext.getMirrorModels();
|
|
@@ -94,11 +91,7 @@ function createLanguageService(options) {
|
|
|
94
91
|
if (model) {
|
|
95
92
|
return model.version.toString();
|
|
96
93
|
}
|
|
97
|
-
|
|
98
|
-
if (dts) {
|
|
99
|
-
return dts.length.toString();
|
|
100
|
-
}
|
|
101
|
-
return '';
|
|
94
|
+
return dtsClient?.readFile(fileName)?.length.toString() ?? '';
|
|
102
95
|
},
|
|
103
96
|
getScriptSnapshot(fileName) {
|
|
104
97
|
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
@@ -118,7 +111,7 @@ function createLanguageService(options) {
|
|
|
118
111
|
if (dtsFileSnapshot.has(fileName)) {
|
|
119
112
|
return dtsFileSnapshot.get(fileName);
|
|
120
113
|
}
|
|
121
|
-
const dtsFileText =
|
|
114
|
+
const dtsFileText = dtsClient?.readFile(fileName);
|
|
122
115
|
if (dtsFileText !== undefined) {
|
|
123
116
|
dtsFileSnapshot.set(fileName, {
|
|
124
117
|
getText: (start, end) => dtsFileText.substring(start, end),
|
|
@@ -145,165 +138,18 @@ function createLanguageService(options) {
|
|
|
145
138
|
if (model) {
|
|
146
139
|
return model.getValue();
|
|
147
140
|
}
|
|
148
|
-
return
|
|
141
|
+
return dtsClient?.readFile(fileName);
|
|
149
142
|
},
|
|
150
143
|
fileExists(fileName) {
|
|
151
144
|
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
152
145
|
if (model) {
|
|
153
146
|
return true;
|
|
154
147
|
}
|
|
155
|
-
return
|
|
148
|
+
return dtsClient?.fileExists(fileName) ?? false;
|
|
156
149
|
},
|
|
157
150
|
};
|
|
158
151
|
return host;
|
|
159
152
|
}
|
|
160
|
-
function readDtsFile(fileName) {
|
|
161
|
-
if (!dtsFiles.has(fileName) && options.dtsHost) {
|
|
162
|
-
dtsFiles.set(fileName, undefined);
|
|
163
|
-
readDtsFileAsync(fileName);
|
|
164
|
-
}
|
|
165
|
-
return dtsFiles.get(fileName);
|
|
166
|
-
}
|
|
167
|
-
async function readDtsFileAsync(fileName) {
|
|
168
|
-
const text = await options.dtsHost?.readFile(fileName);
|
|
169
|
-
dtsFiles.set(fileName, text);
|
|
170
|
-
}
|
|
171
153
|
}
|
|
172
154
|
exports.createLanguageService = createLanguageService;
|
|
173
|
-
function createBaseDtsHost(cdn, versions = {}, flat, onFetch) {
|
|
174
|
-
return new CdnDtsHost(cdn, versions, flat, onFetch);
|
|
175
|
-
}
|
|
176
|
-
exports.createBaseDtsHost = createBaseDtsHost;
|
|
177
|
-
function createJsDelivrDtsHost(versions = {}, onFetch) {
|
|
178
|
-
return new CdnDtsHost('https://cdn.jsdelivr.net/npm/', versions, async (pkg, version) => {
|
|
179
|
-
if (!version) {
|
|
180
|
-
const data = await fetchJson(`https://data.jsdelivr.com/v1/package/resolve/npm/${pkg}@latest`);
|
|
181
|
-
if (data?.version) {
|
|
182
|
-
version = data.version;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (!version) {
|
|
186
|
-
return [];
|
|
187
|
-
}
|
|
188
|
-
const flat = await fetchJson(`https://data.jsdelivr.com/v1/package/npm/${pkg}@${version}/flat`);
|
|
189
|
-
if (!flat) {
|
|
190
|
-
return [];
|
|
191
|
-
}
|
|
192
|
-
return flat.files.map(file => file.name);
|
|
193
|
-
}, onFetch);
|
|
194
|
-
}
|
|
195
|
-
exports.createJsDelivrDtsHost = createJsDelivrDtsHost;
|
|
196
|
-
class CdnDtsHost {
|
|
197
|
-
constructor(cdn, versions = {}, flat, onFetch) {
|
|
198
|
-
this.cdn = cdn;
|
|
199
|
-
this.versions = versions;
|
|
200
|
-
this.flat = flat;
|
|
201
|
-
this.onFetch = onFetch;
|
|
202
|
-
this.files = new Map();
|
|
203
|
-
this.flatResult = new Map();
|
|
204
|
-
this.lastUpdateFilesSize = 0;
|
|
205
|
-
}
|
|
206
|
-
async getVersion() {
|
|
207
|
-
while (this.files.size !== this.lastUpdateFilesSize) {
|
|
208
|
-
const newFileSize = this.files.size;
|
|
209
|
-
await Promise.all(this.files.values());
|
|
210
|
-
if (newFileSize > this.lastUpdateFilesSize) {
|
|
211
|
-
this.lastUpdateFilesSize = newFileSize;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return this.files.size;
|
|
215
|
-
}
|
|
216
|
-
async readFile(fileName) {
|
|
217
|
-
if (fileName.startsWith('/node_modules/')
|
|
218
|
-
// ignore .js because it's no help for intellisense
|
|
219
|
-
&& (fileName.endsWith('.d.ts') || fileName.endsWith('/package.json'))) {
|
|
220
|
-
if (!this.files.has(fileName)) {
|
|
221
|
-
this.files.set(fileName, this.fetchFile(fileName));
|
|
222
|
-
}
|
|
223
|
-
return await this.files.get(fileName);
|
|
224
|
-
}
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
227
|
-
async fetchFile(fileName) {
|
|
228
|
-
if (this.flat) {
|
|
229
|
-
let pkgName = fileName.split('/')[2];
|
|
230
|
-
if (pkgName.startsWith('@')) {
|
|
231
|
-
pkgName += '/' + fileName.split('/')[3];
|
|
232
|
-
}
|
|
233
|
-
if (pkgName.endsWith('.d.ts') || pkgName.endsWith('/node_modules')) {
|
|
234
|
-
return undefined;
|
|
235
|
-
}
|
|
236
|
-
// hard code for known invalid package
|
|
237
|
-
if (pkgName.startsWith('@typescript/') || pkgName.startsWith('@types/typescript__')) {
|
|
238
|
-
return undefined;
|
|
239
|
-
}
|
|
240
|
-
// don't check @types if original package already having types
|
|
241
|
-
if (pkgName.startsWith('@types/')) {
|
|
242
|
-
let originalPkgName = pkgName.slice('@types/'.length);
|
|
243
|
-
if (originalPkgName.indexOf('__') >= 0) {
|
|
244
|
-
originalPkgName = '@' + originalPkgName.replace('__', '/');
|
|
245
|
-
}
|
|
246
|
-
const packageJson = await this.readFile(`/node_modules/${originalPkgName}/package.json`);
|
|
247
|
-
if (packageJson) {
|
|
248
|
-
const packageJsonObj = JSON.parse(packageJson);
|
|
249
|
-
if (packageJsonObj.types || packageJsonObj.typings) {
|
|
250
|
-
return undefined;
|
|
251
|
-
}
|
|
252
|
-
const indexDts = await this.readFile(`/node_modules/${originalPkgName}/index.d.ts`);
|
|
253
|
-
if (indexDts) {
|
|
254
|
-
return undefined;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (!this.flatResult.has(pkgName)) {
|
|
259
|
-
this.flatResult.set(pkgName, this.flat(pkgName, this.versions[pkgName]));
|
|
260
|
-
}
|
|
261
|
-
const flat = await this.flatResult.get(pkgName);
|
|
262
|
-
const include = flat.includes(fileName.slice(`/node_modules/${pkgName}`.length));
|
|
263
|
-
if (!include) {
|
|
264
|
-
return undefined;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const requestFileName = this.resolveRequestFileName(fileName);
|
|
268
|
-
const url = this.cdn + requestFileName.slice('/node_modules/'.length);
|
|
269
|
-
const text = await fetchText(url);
|
|
270
|
-
if (text) {
|
|
271
|
-
if (this.onFetch) {
|
|
272
|
-
this.onFetch(fileName, text);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return text;
|
|
276
|
-
}
|
|
277
|
-
resolveRequestFileName(fileName) {
|
|
278
|
-
for (const [key, version] of Object.entries(this.versions)) {
|
|
279
|
-
if (fileName.startsWith(`/node_modules/${key}/`)) {
|
|
280
|
-
fileName = fileName.replace(`/node_modules/${key}/`, `/node_modules/${key}@${version}/`);
|
|
281
|
-
return fileName;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return fileName;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
async function fetchText(url) {
|
|
288
|
-
try {
|
|
289
|
-
const res = await fetch(url);
|
|
290
|
-
if (res.status === 200) {
|
|
291
|
-
return await res.text();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
catch {
|
|
295
|
-
// ignore
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
async function fetchJson(url) {
|
|
299
|
-
try {
|
|
300
|
-
const res = await fetch(url);
|
|
301
|
-
if (res.status === 200) {
|
|
302
|
-
return await res.json();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
catch {
|
|
306
|
-
// ignore
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
155
|
//# sourceMappingURL=worker.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/monaco",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.9",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
"directory": "packages/monaco"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@volar/language-service": "1.6.
|
|
18
|
+
"@volar/language-service": "1.6.9",
|
|
19
19
|
"vscode-uri": "^3.0.7"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
+
"@volar/web-fs": "1.6.9",
|
|
22
23
|
"monaco-editor-core": "latest",
|
|
23
24
|
"vscode-languageserver-protocol": "^3.17.3"
|
|
24
25
|
},
|
|
25
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "e676fa08e4186bd2f8cc14861ef65f8d8c855ea1"
|
|
26
27
|
}
|