@volar/monaco 1.4.0-alpha.0 → 1.4.0-alpha.10
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 +55 -75
- package/out/index.js +1 -0
- package/out/languages.js +30 -38
- package/out/utils/markers.js +1 -0
- package/out/utils/monaco2protocol.js +1 -0
- package/out/utils/protocol2monaco.js +29 -23
- package/out/utils/provider.js +311 -352
- package/out/worker.d.ts +1 -1
- package/out/worker.js +42 -68
- 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,25 +1,16 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
"use strict";
|
|
10
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
exports.createDtsHost = exports.createLanguageService = void 0;
|
|
12
4
|
const language_service_1 = require("@volar/language-service");
|
|
13
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
14
|
-
const axios_1 = require("axios");
|
|
15
6
|
function createLanguageService(options) {
|
|
16
|
-
|
|
7
|
+
const ts = options.typescript?.module;
|
|
17
8
|
const dtsFiles = new Map();
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const compilerOptions = (_c = (_b = options.typescript) === null || _b === void 0 ? void 0 : _b.compilerOptions) !== null && _c !== void 0 ? _c : {};
|
|
9
|
+
const config = options.config ?? {};
|
|
10
|
+
const compilerOptions = options.typescript?.compilerOptions ?? {};
|
|
21
11
|
let host = createLanguageServiceHost();
|
|
22
12
|
let languageService = (0, language_service_1.createLanguageService)({
|
|
13
|
+
modules: { typescript: ts },
|
|
23
14
|
host,
|
|
24
15
|
config,
|
|
25
16
|
uriToFileName: (uri) => vscode_uri_1.URI.parse(uri).fsPath.replace(/\\/g, '/'),
|
|
@@ -37,19 +28,20 @@ function createLanguageService(options) {
|
|
|
37
28
|
InnocentRabbit.prototype[api] = () => languageService[api];
|
|
38
29
|
continue;
|
|
39
30
|
}
|
|
40
|
-
InnocentRabbit.prototype[api] = (...args) =>
|
|
31
|
+
InnocentRabbit.prototype[api] = async (...args) => {
|
|
41
32
|
if (!options.dtsHost) {
|
|
42
33
|
return languageService[api](...args);
|
|
43
34
|
}
|
|
44
|
-
let oldVersion =
|
|
45
|
-
let result =
|
|
46
|
-
let newVersion =
|
|
35
|
+
let oldVersion = await options.dtsHost.getVersion();
|
|
36
|
+
let result = await languageService[api](...args);
|
|
37
|
+
let newVersion = await options.dtsHost.getVersion();
|
|
47
38
|
while (newVersion !== oldVersion) {
|
|
48
39
|
oldVersion = newVersion;
|
|
49
40
|
if (newVersion !== dtsVersion) {
|
|
50
41
|
dtsVersion = newVersion;
|
|
51
42
|
languageService.dispose();
|
|
52
43
|
languageService = (0, language_service_1.createLanguageService)({
|
|
44
|
+
modules: { typescript: ts },
|
|
53
45
|
host,
|
|
54
46
|
config,
|
|
55
47
|
rootUri: vscode_uri_1.URI.file('/'),
|
|
@@ -57,11 +49,11 @@ function createLanguageService(options) {
|
|
|
57
49
|
fileNameToUri: (fileName) => vscode_uri_1.URI.file(fileName).toString(),
|
|
58
50
|
});
|
|
59
51
|
}
|
|
60
|
-
result =
|
|
61
|
-
newVersion =
|
|
52
|
+
result = await languageService[api](...args);
|
|
53
|
+
newVersion = await options.dtsHost.getVersion();
|
|
62
54
|
}
|
|
63
55
|
return result;
|
|
64
|
-
}
|
|
56
|
+
};
|
|
65
57
|
}
|
|
66
58
|
return new InnocentRabbit();
|
|
67
59
|
function createLanguageServiceHost() {
|
|
@@ -100,7 +92,6 @@ function createLanguageService(options) {
|
|
|
100
92
|
return '';
|
|
101
93
|
},
|
|
102
94
|
getScriptSnapshot(fileName) {
|
|
103
|
-
var _a;
|
|
104
95
|
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
105
96
|
if (model) {
|
|
106
97
|
const cache = modelSnapshot.get(model);
|
|
@@ -113,7 +104,7 @@ function createLanguageService(options) {
|
|
|
113
104
|
getLength: () => text.length,
|
|
114
105
|
getChangeRange: () => undefined,
|
|
115
106
|
}]);
|
|
116
|
-
return
|
|
107
|
+
return modelSnapshot.get(model)?.[1];
|
|
117
108
|
}
|
|
118
109
|
if (dtsFileSnapshot.has(fileName)) {
|
|
119
110
|
return dtsFileSnapshot.get(fileName);
|
|
@@ -154,7 +145,6 @@ function createLanguageService(options) {
|
|
|
154
145
|
}
|
|
155
146
|
return readDtsFile(fileName) !== undefined;
|
|
156
147
|
},
|
|
157
|
-
getTypeScriptModule: ts ? (() => ts) : undefined,
|
|
158
148
|
};
|
|
159
149
|
return host;
|
|
160
150
|
}
|
|
@@ -165,12 +155,9 @@ function createLanguageService(options) {
|
|
|
165
155
|
}
|
|
166
156
|
return dtsFiles.get(fileName);
|
|
167
157
|
}
|
|
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
|
-
});
|
|
158
|
+
async function readDtsFileAsync(fileName) {
|
|
159
|
+
const text = await options.dtsHost?.readFile(fileName);
|
|
160
|
+
dtsFiles.set(fileName, text);
|
|
174
161
|
}
|
|
175
162
|
}
|
|
176
163
|
exports.createLanguageService = createLanguageService;
|
|
@@ -186,14 +173,12 @@ class CdnDtsHost {
|
|
|
186
173
|
this.files = new Map();
|
|
187
174
|
this.lastUpdateFilesSize = 0;
|
|
188
175
|
}
|
|
189
|
-
getVersion() {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return this.files.size;
|
|
196
|
-
});
|
|
176
|
+
async getVersion() {
|
|
177
|
+
while (this.files.size !== this.lastUpdateFilesSize) {
|
|
178
|
+
this.lastUpdateFilesSize = this.files.size;
|
|
179
|
+
await Promise.all(this.files.values());
|
|
180
|
+
}
|
|
181
|
+
return this.files.size;
|
|
197
182
|
}
|
|
198
183
|
readFile(fileName) {
|
|
199
184
|
if (fileName.startsWith('/node_modules/')
|
|
@@ -201,31 +186,23 @@ class CdnDtsHost {
|
|
|
201
186
|
&& (fileName.endsWith('.d.ts') || fileName.endsWith('/package.json'))) {
|
|
202
187
|
if (!this.files.has(fileName)) {
|
|
203
188
|
this.files.set(fileName, undefined);
|
|
204
|
-
this.files.set(fileName, this.
|
|
189
|
+
this.files.set(fileName, this.fetchFile(fileName));
|
|
205
190
|
}
|
|
206
191
|
return this.files.get(fileName);
|
|
207
192
|
}
|
|
208
193
|
return undefined;
|
|
209
194
|
}
|
|
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
|
-
});
|
|
195
|
+
async fetchFile(fileName) {
|
|
196
|
+
const requestFileName = this.resolveRequestFileName(fileName);
|
|
197
|
+
const url = this.cdn + requestFileName.slice('/node_modules/'.length);
|
|
198
|
+
try {
|
|
199
|
+
const text = await (await fetch(url)).text();
|
|
200
|
+
this.onFetch?.(fileName, text);
|
|
201
|
+
return text;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// ignore
|
|
205
|
+
}
|
|
229
206
|
}
|
|
230
207
|
resolveRequestFileName(fileName) {
|
|
231
208
|
for (const [key, version] of Object.entries(this.versions)) {
|
|
@@ -239,19 +216,16 @@ class CdnDtsHost {
|
|
|
239
216
|
/**
|
|
240
217
|
* save / load with json
|
|
241
218
|
*/
|
|
242
|
-
toJson() {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
return json;
|
|
250
|
-
});
|
|
219
|
+
async toJson() {
|
|
220
|
+
const json = {};
|
|
221
|
+
for (const [fileName, file] of this.files) {
|
|
222
|
+
json[fileName] = (await file) ?? null;
|
|
223
|
+
}
|
|
224
|
+
return json;
|
|
251
225
|
}
|
|
252
226
|
fromJson(json) {
|
|
253
227
|
for (const [fileName, file] of Object.entries(json)) {
|
|
254
|
-
this.files.set(fileName, file
|
|
228
|
+
this.files.set(fileName, file ?? undefined);
|
|
255
229
|
}
|
|
256
230
|
}
|
|
257
231
|
}
|
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.10",
|
|
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.10",
|
|
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": "715bc5f17a0d1cadd4190712dcaff732989eb330"
|
|
25
24
|
}
|