@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/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
- fetch(fileName: string): Promise<string | undefined>;
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 = (_a = options.config) !== null && _a !== void 0 ? _a : {};
20
- const compilerOptions = (_c = (_b = options.typescript) === null || _b === void 0 ? void 0 : _b.compilerOptions) !== null && _c !== void 0 ? _c : {};
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) => __awaiter(this, void 0, void 0, function* () {
29
+ InnocentRabbit.prototype[api] = async (...args) => {
41
30
  if (!options.dtsHost) {
42
31
  return languageService[api](...args);
43
32
  }
44
- let oldVersion = yield options.dtsHost.getVersion();
45
- let result = yield languageService[api](...args);
46
- let newVersion = yield options.dtsHost.getVersion();
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 = yield languageService[api](...args);
61
- newVersion = yield options.dtsHost.getVersion();
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 (_a = modelSnapshot.get(model)) === null || _a === void 0 ? void 0 : _a[1];
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
- var _a;
170
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
191
- while (this.files.size !== this.lastUpdateFilesSize) {
192
- this.lastUpdateFilesSize = this.files.size;
193
- yield Promise.all(this.files.values());
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.fetch(fileName));
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
- fetch(fileName) {
211
- var _a, _b;
212
- return __awaiter(this, void 0, void 0, function* () {
213
- const requestFileName = this.resolveRequestFileName(fileName);
214
- const url = this.cdn + requestFileName.slice('/node_modules/'.length);
215
- try {
216
- const text = (_a = (yield axios_1.default.get(url, {
217
- transformResponse: (res) => {
218
- // avoid parse to json object
219
- return res;
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
- var _a;
244
- return __awaiter(this, void 0, void 0, function* () {
245
- const json = {};
246
- for (const [fileName, file] of this.files) {
247
- json[fileName] = (_a = (yield file)) !== null && _a !== void 0 ? _a : null;
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 !== null && file !== void 0 ? file : undefined);
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.0",
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.0",
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": "2607410cae341cf802b446062d446ad497be2057"
23
+ "gitHead": "41ea915b137aea284e2bf5edd98a788ce21b779c"
25
24
  }