@volar/monaco 1.4.0-alpha.0 → 1.4.0-alpha.1
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 +58 -74
- package/out/languages.js +27 -38
- package/out/utils/protocol2monaco.js +28 -23
- package/out/utils/provider.js +284 -353
- package/out/worker.d.ts +1 -1
- package/out/worker.js +38 -66
- package/package.json +3 -4
package/out/worker.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare class CdnDtsHost {
|
|
|
20
20
|
constructor(cdn: string, versions?: Record<string, string>, onFetch?: ((fileName: string, text: string) => void) | undefined);
|
|
21
21
|
getVersion(): Promise<number>;
|
|
22
22
|
readFile(fileName: string): string | Promise<string | undefined> | undefined;
|
|
23
|
-
|
|
23
|
+
fetchFile(fileName: string): Promise<string | undefined>;
|
|
24
24
|
resolveRequestFileName(fileName: string): string;
|
|
25
25
|
/**
|
|
26
26
|
* save / load with json
|
package/out/worker.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.createDtsHost = exports.createLanguageService = void 0;
|
|
12
3
|
const language_service_1 = require("@volar/language-service");
|
|
13
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
14
|
-
const axios_1 = require("axios");
|
|
15
5
|
function createLanguageService(options) {
|
|
16
|
-
var _a, _b, _c;
|
|
17
6
|
const dtsFiles = new Map();
|
|
18
7
|
const ts = options.typescript ? options.typescript.module : undefined;
|
|
19
|
-
const config =
|
|
20
|
-
const compilerOptions =
|
|
8
|
+
const config = options.config ?? {};
|
|
9
|
+
const compilerOptions = options.typescript?.compilerOptions ?? {};
|
|
21
10
|
let host = createLanguageServiceHost();
|
|
22
11
|
let languageService = (0, language_service_1.createLanguageService)({
|
|
23
12
|
host,
|
|
@@ -37,13 +26,13 @@ function createLanguageService(options) {
|
|
|
37
26
|
InnocentRabbit.prototype[api] = () => languageService[api];
|
|
38
27
|
continue;
|
|
39
28
|
}
|
|
40
|
-
InnocentRabbit.prototype[api] = (...args) =>
|
|
29
|
+
InnocentRabbit.prototype[api] = async (...args) => {
|
|
41
30
|
if (!options.dtsHost) {
|
|
42
31
|
return languageService[api](...args);
|
|
43
32
|
}
|
|
44
|
-
let oldVersion =
|
|
45
|
-
let result =
|
|
46
|
-
let newVersion =
|
|
33
|
+
let oldVersion = await options.dtsHost.getVersion();
|
|
34
|
+
let result = await languageService[api](...args);
|
|
35
|
+
let newVersion = await options.dtsHost.getVersion();
|
|
47
36
|
while (newVersion !== oldVersion) {
|
|
48
37
|
oldVersion = newVersion;
|
|
49
38
|
if (newVersion !== dtsVersion) {
|
|
@@ -57,11 +46,11 @@ function createLanguageService(options) {
|
|
|
57
46
|
fileNameToUri: (fileName) => vscode_uri_1.URI.file(fileName).toString(),
|
|
58
47
|
});
|
|
59
48
|
}
|
|
60
|
-
result =
|
|
61
|
-
newVersion =
|
|
49
|
+
result = await languageService[api](...args);
|
|
50
|
+
newVersion = await options.dtsHost.getVersion();
|
|
62
51
|
}
|
|
63
52
|
return result;
|
|
64
|
-
}
|
|
53
|
+
};
|
|
65
54
|
}
|
|
66
55
|
return new InnocentRabbit();
|
|
67
56
|
function createLanguageServiceHost() {
|
|
@@ -100,7 +89,6 @@ function createLanguageService(options) {
|
|
|
100
89
|
return '';
|
|
101
90
|
},
|
|
102
91
|
getScriptSnapshot(fileName) {
|
|
103
|
-
var _a;
|
|
104
92
|
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
105
93
|
if (model) {
|
|
106
94
|
const cache = modelSnapshot.get(model);
|
|
@@ -113,7 +101,7 @@ function createLanguageService(options) {
|
|
|
113
101
|
getLength: () => text.length,
|
|
114
102
|
getChangeRange: () => undefined,
|
|
115
103
|
}]);
|
|
116
|
-
return
|
|
104
|
+
return modelSnapshot.get(model)?.[1];
|
|
117
105
|
}
|
|
118
106
|
if (dtsFileSnapshot.has(fileName)) {
|
|
119
107
|
return dtsFileSnapshot.get(fileName);
|
|
@@ -165,12 +153,9 @@ function createLanguageService(options) {
|
|
|
165
153
|
}
|
|
166
154
|
return dtsFiles.get(fileName);
|
|
167
155
|
}
|
|
168
|
-
function readDtsFileAsync(fileName) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const text = yield ((_a = options.dtsHost) === null || _a === void 0 ? void 0 : _a.readFile(fileName));
|
|
172
|
-
dtsFiles.set(fileName, text);
|
|
173
|
-
});
|
|
156
|
+
async function readDtsFileAsync(fileName) {
|
|
157
|
+
const text = await options.dtsHost?.readFile(fileName);
|
|
158
|
+
dtsFiles.set(fileName, text);
|
|
174
159
|
}
|
|
175
160
|
}
|
|
176
161
|
exports.createLanguageService = createLanguageService;
|
|
@@ -186,14 +171,12 @@ class CdnDtsHost {
|
|
|
186
171
|
this.files = new Map();
|
|
187
172
|
this.lastUpdateFilesSize = 0;
|
|
188
173
|
}
|
|
189
|
-
getVersion() {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return this.files.size;
|
|
196
|
-
});
|
|
174
|
+
async getVersion() {
|
|
175
|
+
while (this.files.size !== this.lastUpdateFilesSize) {
|
|
176
|
+
this.lastUpdateFilesSize = this.files.size;
|
|
177
|
+
await Promise.all(this.files.values());
|
|
178
|
+
}
|
|
179
|
+
return this.files.size;
|
|
197
180
|
}
|
|
198
181
|
readFile(fileName) {
|
|
199
182
|
if (fileName.startsWith('/node_modules/')
|
|
@@ -201,31 +184,23 @@ class CdnDtsHost {
|
|
|
201
184
|
&& (fileName.endsWith('.d.ts') || fileName.endsWith('/package.json'))) {
|
|
202
185
|
if (!this.files.has(fileName)) {
|
|
203
186
|
this.files.set(fileName, undefined);
|
|
204
|
-
this.files.set(fileName, this.
|
|
187
|
+
this.files.set(fileName, this.fetchFile(fileName));
|
|
205
188
|
}
|
|
206
189
|
return this.files.get(fileName);
|
|
207
190
|
}
|
|
208
191
|
return undefined;
|
|
209
192
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
})).data) !== null && _a !== void 0 ? _a : undefined;
|
|
222
|
-
(_b = this.onFetch) === null || _b === void 0 ? void 0 : _b.call(this, fileName, text);
|
|
223
|
-
return text;
|
|
224
|
-
}
|
|
225
|
-
catch (_c) {
|
|
226
|
-
// ignore
|
|
227
|
-
}
|
|
228
|
-
});
|
|
193
|
+
async fetchFile(fileName) {
|
|
194
|
+
const requestFileName = this.resolveRequestFileName(fileName);
|
|
195
|
+
const url = this.cdn + requestFileName.slice('/node_modules/'.length);
|
|
196
|
+
try {
|
|
197
|
+
const text = await (await fetch(url)).text();
|
|
198
|
+
this.onFetch?.(fileName, text);
|
|
199
|
+
return text;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// ignore
|
|
203
|
+
}
|
|
229
204
|
}
|
|
230
205
|
resolveRequestFileName(fileName) {
|
|
231
206
|
for (const [key, version] of Object.entries(this.versions)) {
|
|
@@ -239,19 +214,16 @@ class CdnDtsHost {
|
|
|
239
214
|
/**
|
|
240
215
|
* save / load with json
|
|
241
216
|
*/
|
|
242
|
-
toJson() {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
return json;
|
|
250
|
-
});
|
|
217
|
+
async toJson() {
|
|
218
|
+
const json = {};
|
|
219
|
+
for (const [fileName, file] of this.files) {
|
|
220
|
+
json[fileName] = (await file) ?? null;
|
|
221
|
+
}
|
|
222
|
+
return json;
|
|
251
223
|
}
|
|
252
224
|
fromJson(json) {
|
|
253
225
|
for (const [fileName, file] of Object.entries(json)) {
|
|
254
|
-
this.files.set(fileName, file
|
|
226
|
+
this.files.set(fileName, file ?? undefined);
|
|
255
227
|
}
|
|
256
228
|
}
|
|
257
229
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/monaco",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.1",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
"directory": "packages/monaco"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@volar/language-service": "1.4.0-alpha.
|
|
19
|
-
"axios": "^1.3.4",
|
|
18
|
+
"@volar/language-service": "1.4.0-alpha.1",
|
|
20
19
|
"monaco-editor-core": "^0.36.0",
|
|
21
20
|
"vscode-languageserver-protocol": "^3.17.3",
|
|
22
21
|
"vscode-uri": "^3.0.7"
|
|
23
22
|
},
|
|
24
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "41ea915b137aea284e2bf5edd98a788ce21b779c"
|
|
25
24
|
}
|