@volar/monaco 1.4.0-alpha.0 → 1.4.0-alpha.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/out/editor.js CHANGED
@@ -1,15 +1,5 @@
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.editor = void 0;
12
- const language_service_1 = require("@volar/language-service");
13
3
  const monaco_editor_core_1 = require("monaco-editor-core");
14
4
  const markers_1 = require("./utils/markers");
15
5
  const protocol2monaco = require("./utils/protocol2monaco");
@@ -34,11 +24,10 @@ var editor;
34
24
  }
35
25
  return { dispose: () => disposables.forEach((d) => d.dispose()) };
36
26
  function stopHostingMarkers(model) {
37
- var _a;
38
27
  editor.setModelMarkers(model, markersOwn, []);
39
28
  const key = model.uri.toString();
40
29
  if (listener.has(key)) {
41
- (_a = listener.get(key)) === null || _a === void 0 ? void 0 : _a.dispose();
30
+ listener.get(key)?.dispose();
42
31
  listener.delete(key);
43
32
  }
44
33
  }
@@ -68,29 +57,25 @@ var editor;
68
57
  });
69
58
  doValidation(model);
70
59
  }
71
- function doValidation(model) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- if (model.isDisposed()) {
74
- return;
75
- }
76
- if (!model.isAttachedToEditor()) {
77
- return;
78
- }
79
- const version = model.getVersionId();
80
- const languageService = yield worker.withSyncedResources(getSyncUris());
81
- const diagnostics = yield languageService.doValidation(model.uri.toString(), {
82
- get isCancellationRequested() {
83
- return model.getVersionId() !== version;
84
- },
85
- onCancellationRequested: language_service_1.Event.None,
86
- }, 'all');
87
- const result = diagnostics.map(error => {
88
- const marker = protocol2monaco.asMarkerData(error);
89
- markers_1.markers.set(marker, error);
90
- return marker;
91
- });
92
- editor.setModelMarkers(model, markersOwn, result);
60
+ async function doValidation(model) {
61
+ if (model.isDisposed()) {
62
+ return;
63
+ }
64
+ if (!model.isAttachedToEditor()) {
65
+ return;
66
+ }
67
+ const version = model.getVersionId();
68
+ const languageService = await worker.withSyncedResources(getSyncUris());
69
+ const diagnostics = await languageService.doValidation(model.uri.toString(), 'all');
70
+ if (model.getVersionId() !== version) {
71
+ return;
72
+ }
73
+ const result = diagnostics.map(error => {
74
+ const marker = protocol2monaco.asMarkerData(error);
75
+ markers_1.markers.set(marker, error);
76
+ return marker;
93
77
  });
78
+ editor.setModelMarkers(model, markersOwn, result);
94
79
  }
95
80
  }
96
81
  editor_1.activateMarkers = activateMarkers;
@@ -114,9 +99,8 @@ var editor;
114
99
  }
115
100
  return { dispose: () => disposables.forEach((d) => d.dispose()) };
116
101
  function stopHostingAutoInsertion(model) {
117
- var _a;
118
102
  if (listener.has(model)) {
119
- (_a = listener.get(model)) === null || _a === void 0 ? void 0 : _a.dispose();
103
+ listener.get(model)?.dispose();
120
104
  listener.delete(model);
121
105
  }
122
106
  }
@@ -138,47 +122,42 @@ var editor;
138
122
  doAutoInsert(model, lastChange);
139
123
  }));
140
124
  }
141
- function doAutoInsert(model, lastChange) {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- if (timeout) {
144
- clearTimeout(timeout);
145
- timeout = undefined;
146
- }
147
- const version = model.getVersionId();
148
- timeout = setTimeout(() => {
149
- (() => __awaiter(this, void 0, void 0, function* () {
150
- var _a;
151
- if (model.getVersionId() !== version) {
152
- return;
125
+ async function doAutoInsert(model, lastChange) {
126
+ if (timeout) {
127
+ clearTimeout(timeout);
128
+ timeout = undefined;
129
+ }
130
+ const version = model.getVersionId();
131
+ timeout = setTimeout(() => {
132
+ (async () => {
133
+ if (model.getVersionId() !== version) {
134
+ return;
135
+ }
136
+ const position = new monaco_editor_core_1.Position(lastChange.range.startLineNumber, lastChange.range.startColumn + lastChange.text.length);
137
+ const languageService = await worker.withSyncedResources(getSyncUris());
138
+ const edit = await languageService.doAutoInsert(model.uri.toString(), monaco2protocol.asPosition(position), {
139
+ lastChange: {
140
+ range: monaco2protocol.asRange(lastChange.range),
141
+ rangeLength: lastChange.rangeLength,
142
+ text: lastChange.text,
143
+ rangeOffset: lastChange.rangeOffset,
144
+ },
145
+ });
146
+ if (model.getVersionId() !== version) {
147
+ return;
148
+ }
149
+ const codeEditor = editor.getEditors().find((e) => e.getModel() === model);
150
+ if (codeEditor && edit && model.getVersionId() === version) {
151
+ if (typeof edit === 'string') {
152
+ codeEditor?.getContribution('snippetController2')?.insert(edit);
153
153
  }
154
- const position = new monaco_editor_core_1.Position(lastChange.range.startLineNumber, lastChange.range.startColumn + lastChange.text.length);
155
- const languageService = yield worker.withSyncedResources(getSyncUris());
156
- const edit = yield languageService.doAutoInsert(model.uri.toString(), monaco2protocol.asPosition(position), {
157
- lastChange: {
158
- range: monaco2protocol.asRange(lastChange.range),
159
- rangeLength: lastChange.rangeLength,
160
- text: lastChange.text,
161
- rangeOffset: lastChange.rangeOffset,
162
- },
163
- }, {
164
- get isCancellationRequested() {
165
- return model.getVersionId() !== version;
166
- },
167
- onCancellationRequested: language_service_1.Event.None,
168
- });
169
- const codeEditor = editor.getEditors().find((e) => e.getModel() === model);
170
- if (codeEditor && edit && model.getVersionId() === version) {
171
- if (typeof edit === 'string') {
172
- (_a = codeEditor === null || codeEditor === void 0 ? void 0 : codeEditor.getContribution('snippetController2')) === null || _a === void 0 ? void 0 : _a.insert(edit);
173
- }
174
- else {
175
- model.pushEditOperations([], [protocol2monaco.asTextEdit(edit)], () => []);
176
- }
154
+ else {
155
+ model.pushEditOperations([], [protocol2monaco.asTextEdit(edit)], () => []);
177
156
  }
178
- }))();
179
- timeout = undefined;
180
- }, 100);
181
- });
157
+ }
158
+ })();
159
+ timeout = undefined;
160
+ }, 100);
182
161
  }
183
162
  }
184
163
  editor_1.activateAutoInsertion = activateAutoInsertion;
package/out/languages.js CHANGED
@@ -1,46 +1,37 @@
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.languages = void 0;
12
3
  const provider_1 = require("./utils/provider");
13
4
  var languages;
14
5
  (function (languages_1) {
15
- function registerProvides(worker, language, getSyncUris, languages) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const provider = yield (0, provider_1.createLanguageFeaturesProvider)(worker, getSyncUris);
18
- const disposables = [
19
- languages.registerHoverProvider(language, provider),
20
- languages.registerReferenceProvider(language, provider),
21
- languages.registerRenameProvider(language, provider),
22
- languages.registerSignatureHelpProvider(language, provider),
23
- languages.registerDocumentSymbolProvider(language, provider),
24
- languages.registerDocumentHighlightProvider(language, provider),
25
- languages.registerLinkedEditingRangeProvider(language, provider),
26
- languages.registerDefinitionProvider(language, provider),
27
- languages.registerImplementationProvider(language, provider),
28
- languages.registerTypeDefinitionProvider(language, provider),
29
- languages.registerCodeLensProvider(language, provider),
30
- languages.registerCodeActionProvider(language, provider),
31
- languages.registerDocumentFormattingEditProvider(language, provider),
32
- languages.registerDocumentRangeFormattingEditProvider(language, provider),
33
- languages.registerOnTypeFormattingEditProvider(language, provider),
34
- languages.registerLinkProvider(language, provider),
35
- languages.registerCompletionItemProvider(language, provider),
36
- languages.registerColorProvider(language, provider),
37
- languages.registerFoldingRangeProvider(language, provider),
38
- languages.registerDeclarationProvider(language, provider),
39
- languages.registerSelectionRangeProvider(language, provider),
40
- languages.registerInlayHintsProvider(language, provider),
41
- ];
42
- return { dispose: () => disposables.forEach((d) => d.dispose()) };
43
- });
6
+ async function registerProvides(worker, language, getSyncUris, languages) {
7
+ const provider = await (0, provider_1.createLanguageFeaturesProvider)(worker, getSyncUris);
8
+ const disposables = [
9
+ languages.registerHoverProvider(language, provider),
10
+ languages.registerReferenceProvider(language, provider),
11
+ languages.registerRenameProvider(language, provider),
12
+ languages.registerSignatureHelpProvider(language, provider),
13
+ languages.registerDocumentSymbolProvider(language, provider),
14
+ languages.registerDocumentHighlightProvider(language, provider),
15
+ languages.registerLinkedEditingRangeProvider(language, provider),
16
+ languages.registerDefinitionProvider(language, provider),
17
+ languages.registerImplementationProvider(language, provider),
18
+ languages.registerTypeDefinitionProvider(language, provider),
19
+ languages.registerCodeLensProvider(language, provider),
20
+ languages.registerCodeActionProvider(language, provider),
21
+ languages.registerDocumentFormattingEditProvider(language, provider),
22
+ languages.registerDocumentRangeFormattingEditProvider(language, provider),
23
+ languages.registerOnTypeFormattingEditProvider(language, provider),
24
+ languages.registerLinkProvider(language, provider),
25
+ languages.registerCompletionItemProvider(language, provider),
26
+ languages.registerColorProvider(language, provider),
27
+ languages.registerFoldingRangeProvider(language, provider),
28
+ languages.registerDeclarationProvider(language, provider),
29
+ languages.registerSelectionRangeProvider(language, provider),
30
+ languages.registerInlayHintsProvider(language, provider),
31
+ languages.registerDocumentSemanticTokensProvider(language, provider),
32
+ languages.registerDocumentRangeSemanticTokensProvider(language, provider),
33
+ ];
34
+ return { dispose: () => disposables.forEach((d) => d.dispose()) };
44
35
  }
45
36
  languages_1.registerProvides = registerProvides;
46
37
  })(languages = exports.languages || (exports.languages = {}));
@@ -67,7 +67,6 @@ function asCompletionItemKind(kind) {
67
67
  }
68
68
  exports.asCompletionItemKind = asCompletionItemKind;
69
69
  function asCompletionItem(item, range) {
70
- var _a, _b, _c, _d;
71
70
  return {
72
71
  label: item.label,
73
72
  kind: asCompletionItemKind(item.kind),
@@ -77,11 +76,11 @@ function asCompletionItem(item, range) {
77
76
  sortText: item.sortText,
78
77
  filterText: item.filterText,
79
78
  preselect: item.preselect,
80
- insertText: (_c = (_b = (_a = item.textEdit) === null || _a === void 0 ? void 0 : _a.newText) !== null && _b !== void 0 ? _b : item.insertText) !== null && _c !== void 0 ? _c : item.label,
79
+ insertText: item.textEdit?.newText ?? item.insertText ?? item.label,
81
80
  insertTextRules: monaco_editor_core_1.languages.CompletionItemInsertTextRule.InsertAsSnippet,
82
81
  range: item.textEdit ? asCompletionItemRange(item.textEdit) : asRange(range),
83
82
  commitCharacters: item.commitCharacters,
84
- additionalTextEdits: (_d = item.additionalTextEdits) === null || _d === void 0 ? void 0 : _d.map(asTextEdit),
83
+ additionalTextEdits: item.additionalTextEdits?.map(asTextEdit),
85
84
  command: item.command ? asCommand(item.command) : undefined,
86
85
  };
87
86
  }
@@ -160,11 +159,10 @@ function asUri(uri) {
160
159
  }
161
160
  exports.asUri = asUri;
162
161
  function asSignatureHelp(signatureHelp) {
163
- var _a, _b;
164
162
  return {
165
163
  signatures: signatureHelp.signatures.map(asSignatureInformation),
166
- activeSignature: (_a = signatureHelp.activeSignature) !== null && _a !== void 0 ? _a : 0,
167
- activeParameter: (_b = signatureHelp.activeParameter) !== null && _b !== void 0 ? _b : 0,
164
+ activeSignature: signatureHelp.activeSignature ?? 0,
165
+ activeParameter: signatureHelp.activeParameter ?? 0,
168
166
  };
169
167
  }
170
168
  exports.asSignatureHelp = asSignatureHelp;
@@ -187,8 +185,15 @@ function asParameterInformation(parameterInformation) {
187
185
  }
188
186
  exports.asParameterInformation = asParameterInformation;
189
187
  function asMarkerData(diagnostic) {
190
- var _a, _b, _c;
191
- return Object.assign(Object.assign({ code: (_a = diagnostic.code) === null || _a === void 0 ? void 0 : _a.toString(), severity: asMarkerSeverity(diagnostic.severity), message: diagnostic.message, source: diagnostic.source }, asRange(diagnostic.range)), { relatedInformation: (_b = diagnostic.relatedInformation) === null || _b === void 0 ? void 0 : _b.map(asRelatedInformation), tags: (_c = diagnostic.tags) === null || _c === void 0 ? void 0 : _c.map(asMarkerTag) });
188
+ return {
189
+ code: diagnostic.code?.toString(),
190
+ severity: asMarkerSeverity(diagnostic.severity),
191
+ message: diagnostic.message,
192
+ source: diagnostic.source,
193
+ ...asRange(diagnostic.range),
194
+ relatedInformation: diagnostic.relatedInformation?.map(asRelatedInformation),
195
+ tags: diagnostic.tags?.map(asMarkerTag),
196
+ };
192
197
  }
193
198
  exports.asMarkerData = asMarkerData;
194
199
  function asMarkerTag(tag) {
@@ -201,7 +206,11 @@ function asMarkerTag(tag) {
201
206
  }
202
207
  exports.asMarkerTag = asMarkerTag;
203
208
  function asRelatedInformation(relatedInformation) {
204
- return Object.assign({ resource: asUri(relatedInformation.location.uri), message: relatedInformation.message }, asRange(relatedInformation.location.range));
209
+ return {
210
+ resource: asUri(relatedInformation.location.uri),
211
+ message: relatedInformation.message,
212
+ ...asRange(relatedInformation.location.range),
213
+ };
205
214
  }
206
215
  exports.asRelatedInformation = asRelatedInformation;
207
216
  function asMarkerSeverity(severity) {
@@ -220,7 +229,6 @@ function asMarkerSeverity(severity) {
220
229
  }
221
230
  exports.asMarkerSeverity = asMarkerSeverity;
222
231
  function asWorkspaceEdit(workspaceEdit) {
223
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
224
232
  const result = {
225
233
  edits: [],
226
234
  };
@@ -243,7 +251,7 @@ function asWorkspaceEdit(workspaceEdit) {
243
251
  result.edits.push({
244
252
  resource: asUri(documentChange.textDocument.uri),
245
253
  textEdit: asTextEdit(edit),
246
- versionId: (_a = documentChange.textDocument.version) !== null && _a !== void 0 ? _a : undefined,
254
+ versionId: documentChange.textDocument.version ?? undefined,
247
255
  });
248
256
  }
249
257
  }
@@ -251,8 +259,8 @@ function asWorkspaceEdit(workspaceEdit) {
251
259
  result.edits.push({
252
260
  newResource: asUri(documentChange.uri),
253
261
  options: {
254
- overwrite: (_c = (_b = documentChange.options) === null || _b === void 0 ? void 0 : _b.overwrite) !== null && _c !== void 0 ? _c : false,
255
- ignoreIfExists: (_e = (_d = documentChange.options) === null || _d === void 0 ? void 0 : _d.ignoreIfExists) !== null && _e !== void 0 ? _e : false,
262
+ overwrite: documentChange.options?.overwrite ?? false,
263
+ ignoreIfExists: documentChange.options?.ignoreIfExists ?? false,
256
264
  },
257
265
  });
258
266
  }
@@ -261,8 +269,8 @@ function asWorkspaceEdit(workspaceEdit) {
261
269
  oldResource: asUri(documentChange.oldUri),
262
270
  newResource: asUri(documentChange.newUri),
263
271
  options: {
264
- overwrite: (_g = (_f = documentChange.options) === null || _f === void 0 ? void 0 : _f.overwrite) !== null && _g !== void 0 ? _g : false,
265
- ignoreIfExists: (_j = (_h = documentChange.options) === null || _h === void 0 ? void 0 : _h.ignoreIfExists) !== null && _j !== void 0 ? _j : false,
272
+ overwrite: documentChange.options?.overwrite ?? false,
273
+ ignoreIfExists: documentChange.options?.ignoreIfExists ?? false,
266
274
  },
267
275
  });
268
276
  }
@@ -270,8 +278,8 @@ function asWorkspaceEdit(workspaceEdit) {
270
278
  result.edits.push({
271
279
  oldResource: asUri(documentChange.uri),
272
280
  options: {
273
- recursive: (_l = (_k = documentChange.options) === null || _k === void 0 ? void 0 : _k.recursive) !== null && _l !== void 0 ? _l : false,
274
- ignoreIfNotExists: (_o = (_m = documentChange.options) === null || _m === void 0 ? void 0 : _m.ignoreIfNotExists) !== null && _o !== void 0 ? _o : false,
281
+ recursive: documentChange.options?.recursive ?? false,
282
+ ignoreIfNotExists: documentChange.options?.ignoreIfNotExists ?? false,
275
283
  },
276
284
  });
277
285
  }
@@ -281,12 +289,11 @@ function asWorkspaceEdit(workspaceEdit) {
281
289
  }
282
290
  exports.asWorkspaceEdit = asWorkspaceEdit;
283
291
  function asDocumentSymbol(symbol) {
284
- var _a, _b;
285
292
  return {
286
293
  name: symbol.name,
287
294
  detail: '',
288
295
  kind: asSymbolKind(symbol.kind),
289
- tags: (_b = (_a = symbol.tags) === null || _a === void 0 ? void 0 : _a.map(asSymbolTag)) !== null && _b !== void 0 ? _b : [],
296
+ tags: symbol.tags?.map(asSymbolTag) ?? [],
290
297
  range: asRange(symbol.range),
291
298
  selectionRange: asRange(symbol.selectionRange),
292
299
  children: symbol.children
@@ -389,7 +396,6 @@ function asCodeLens(item) {
389
396
  }
390
397
  exports.asCodeLens = asCodeLens;
391
398
  function asCodeAction(item) {
392
- var _a;
393
399
  return {
394
400
  title: item.title,
395
401
  command: item.command ? asCommand(item.command) : undefined,
@@ -399,7 +405,7 @@ function asCodeAction(item) {
399
405
  : undefined,
400
406
  kind: item.kind,
401
407
  isPreferred: item.isPreferred,
402
- disabled: (_a = item.disabled) === null || _a === void 0 ? void 0 : _a.reason,
408
+ disabled: item.disabled?.reason,
403
409
  };
404
410
  }
405
411
  exports.asCodeAction = asCodeAction;
@@ -429,12 +435,11 @@ function asColorPresentation(item) {
429
435
  }
430
436
  exports.asColorPresentation = asColorPresentation;
431
437
  function asFoldingRange(item) {
432
- var _a;
433
438
  return {
434
439
  start: item.startLine + 1,
435
440
  end: item.endLine + 1,
436
441
  kind: {
437
- value: (_a = item.kind) !== null && _a !== void 0 ? _a : '',
442
+ value: item.kind ?? '',
438
443
  },
439
444
  };
440
445
  }
@@ -1,362 +1,293 @@
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.createLanguageFeaturesProvider = void 0;
12
3
  const language_service_1 = require("@volar/language-service");
13
4
  const markers_1 = require("./markers");
14
5
  const monaco2protocol = require("./monaco2protocol");
15
6
  const protocol2monaco = require("./protocol2monaco");
16
- function createLanguageFeaturesProvider(worker, getSyncUris) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const completionItems = new WeakMap();
19
- const codeLens = new WeakMap();
20
- const codeActions = new WeakMap();
21
- const colorInfos = new WeakMap();
22
- const languageService = yield worker.getProxy();
23
- return {
24
- triggerCharacters: yield languageService.triggerCharacters(),
25
- autoFormatTriggerCharacters: yield languageService.triggerCharacters(),
26
- signatureHelpTriggerCharacters: yield languageService.triggerCharacters(),
27
- signatureHelpRetriggerCharacters: yield languageService.triggerCharacters(),
28
- getLegend() {
29
- return language_service_1.standardSemanticTokensLegend;
30
- },
31
- provideDocumentSemanticTokens(model, _lastResultId, token) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const languageService = yield worker.withSyncedResources(getSyncUris());
34
- const codeResult = yield languageService.getSemanticTokens(model.uri.toString(), undefined, language_service_1.standardSemanticTokensLegend, token);
35
- if (codeResult) {
36
- return {
37
- resultId: codeResult.resultId,
38
- data: Uint32Array.from(codeResult.data),
39
- };
40
- }
7
+ async function createLanguageFeaturesProvider(worker, getSyncUris) {
8
+ const completionItems = new WeakMap();
9
+ const codeLens = new WeakMap();
10
+ const codeActions = new WeakMap();
11
+ const colorInfos = new WeakMap();
12
+ const languageService = await worker.getProxy();
13
+ return {
14
+ triggerCharacters: await languageService.triggerCharacters(),
15
+ autoFormatTriggerCharacters: await languageService.triggerCharacters(),
16
+ signatureHelpTriggerCharacters: await languageService.triggerCharacters(),
17
+ signatureHelpRetriggerCharacters: await languageService.triggerCharacters(),
18
+ getLegend() {
19
+ return language_service_1.standardSemanticTokensLegend;
20
+ },
21
+ async provideDocumentSemanticTokens(model, _lastResultId) {
22
+ const languageService = await worker.withSyncedResources(getSyncUris());
23
+ const codeResult = await languageService.getSemanticTokens(model.uri.toString(), undefined, language_service_1.standardSemanticTokensLegend);
24
+ if (codeResult) {
25
+ return {
26
+ resultId: codeResult.resultId,
27
+ data: Uint32Array.from(codeResult.data),
28
+ };
29
+ }
30
+ },
31
+ async provideDocumentRangeSemanticTokens(model, range) {
32
+ const languageService = await worker.withSyncedResources(getSyncUris());
33
+ const codeResult = await languageService.getSemanticTokens(model.uri.toString(), monaco2protocol.asRange(range), language_service_1.standardSemanticTokensLegend);
34
+ if (codeResult) {
35
+ return {
36
+ resultId: codeResult.resultId,
37
+ data: Uint32Array.from(codeResult.data),
38
+ };
39
+ }
40
+ },
41
+ releaseDocumentSemanticTokens() { },
42
+ async provideDocumentSymbols(model) {
43
+ const languageService = await worker.withSyncedResources(getSyncUris());
44
+ const codeResult = await languageService.findDocumentSymbols(model.uri.toString());
45
+ if (codeResult) {
46
+ return codeResult.map(protocol2monaco.asDocumentSymbol);
47
+ }
48
+ },
49
+ async provideDocumentHighlights(model, position) {
50
+ const languageService = await worker.withSyncedResources(getSyncUris());
51
+ const codeResult = await languageService.findDocumentHighlights(model.uri.toString(), monaco2protocol.asPosition(position));
52
+ if (codeResult) {
53
+ return codeResult.map(protocol2monaco.asDocumentHighlight);
54
+ }
55
+ },
56
+ async provideLinkedEditingRanges(model, position) {
57
+ const languageService = await worker.withSyncedResources(getSyncUris());
58
+ const codeResult = await languageService.findLinkedEditingRanges(model.uri.toString(), monaco2protocol.asPosition(position));
59
+ if (codeResult) {
60
+ return {
61
+ ranges: codeResult.ranges.map(protocol2monaco.asRange),
62
+ wordPattern: codeResult.wordPattern
63
+ ? new RegExp(codeResult.wordPattern)
64
+ : undefined,
65
+ };
66
+ }
67
+ },
68
+ async provideDefinition(model, position) {
69
+ const languageService = await worker.withSyncedResources(getSyncUris());
70
+ const codeResult = await languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
71
+ if (codeResult) {
72
+ return codeResult.map(protocol2monaco.asLocation);
73
+ }
74
+ },
75
+ async provideImplementation(model, position) {
76
+ const languageService = await worker.withSyncedResources(getSyncUris());
77
+ const codeResult = await languageService.findImplementations(model.uri.toString(), monaco2protocol.asPosition(position));
78
+ if (codeResult) {
79
+ return codeResult.map(protocol2monaco.asLocation);
80
+ }
81
+ },
82
+ async provideTypeDefinition(model, position) {
83
+ const languageService = await worker.withSyncedResources(getSyncUris());
84
+ const codeResult = await languageService.findTypeDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
85
+ if (codeResult) {
86
+ return codeResult.map(protocol2monaco.asLocation);
87
+ }
88
+ },
89
+ async provideCodeLenses(model) {
90
+ const languageService = await worker.withSyncedResources(getSyncUris());
91
+ const codeResult = await languageService.doCodeLens(model.uri.toString());
92
+ if (codeResult) {
93
+ const monacoResult = codeResult.map(protocol2monaco.asCodeLens);
94
+ for (let i = 0; i < monacoResult.length; i++) {
95
+ codeLens.set(monacoResult[i], codeResult[i]);
96
+ }
97
+ return {
98
+ lenses: monacoResult,
99
+ dispose: () => { },
100
+ };
101
+ }
102
+ },
103
+ async resolveCodeLens(_, monacoResult) {
104
+ let codeResult = codeLens.get(monacoResult);
105
+ if (codeResult) {
106
+ const languageService = await worker.withSyncedResources(getSyncUris());
107
+ codeResult = await languageService.doCodeLensResolve(codeResult);
108
+ if (codeResult) {
109
+ monacoResult = protocol2monaco.asCodeLens(codeResult);
110
+ codeLens.set(monacoResult, codeResult);
111
+ }
112
+ }
113
+ return monacoResult;
114
+ },
115
+ async provideCodeActions(model, range, context) {
116
+ const diagnostics = [];
117
+ for (const marker of context.markers) {
118
+ const diagnostic = markers_1.markers.get(marker);
119
+ if (diagnostic) {
120
+ diagnostics.push(diagnostic);
121
+ }
122
+ }
123
+ const languageService = await worker.withSyncedResources(getSyncUris());
124
+ const codeResult = await languageService.doCodeActions(model.uri.toString(), monaco2protocol.asRange(range), {
125
+ diagnostics: diagnostics,
126
+ only: context.only ? [context.only] : undefined,
127
+ });
128
+ if (codeResult) {
129
+ const monacoResult = codeResult.map(protocol2monaco.asCodeAction);
130
+ for (let i = 0; i < monacoResult.length; i++) {
131
+ codeActions.set(monacoResult[i], codeResult[i]);
132
+ }
133
+ return {
134
+ actions: monacoResult,
135
+ dispose: () => { },
136
+ };
137
+ }
138
+ },
139
+ async resolveCodeAction(monacoResult) {
140
+ let codeResult = codeActions.get(monacoResult);
141
+ if (codeResult) {
142
+ const languageService = await worker.withSyncedResources(getSyncUris());
143
+ codeResult = await languageService.doCodeActionResolve(codeResult);
144
+ if (codeResult) {
145
+ monacoResult = protocol2monaco.asCodeAction(codeResult);
146
+ codeActions.set(monacoResult, codeResult);
147
+ }
148
+ }
149
+ return monacoResult;
150
+ },
151
+ async provideDocumentFormattingEdits(model, options) {
152
+ const languageService = await worker.withSyncedResources(getSyncUris());
153
+ const codeResult = await languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, undefined);
154
+ if (codeResult) {
155
+ return codeResult.map(protocol2monaco.asTextEdit);
156
+ }
157
+ },
158
+ async provideDocumentRangeFormattingEdits(model, range, options) {
159
+ const languageService = await worker.withSyncedResources(getSyncUris());
160
+ const codeResult = await languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), monaco2protocol.asRange(range), undefined);
161
+ if (codeResult) {
162
+ return codeResult.map(protocol2monaco.asTextEdit);
163
+ }
164
+ },
165
+ async provideOnTypeFormattingEdits(model, position, ch, options) {
166
+ const languageService = await worker.withSyncedResources(getSyncUris());
167
+ const codeResult = await languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, {
168
+ ch: ch,
169
+ position: monaco2protocol.asPosition(position),
170
+ });
171
+ if (codeResult) {
172
+ return codeResult.map(protocol2monaco.asTextEdit);
173
+ }
174
+ },
175
+ async provideLinks(model) {
176
+ const languageService = await worker.withSyncedResources(getSyncUris());
177
+ const codeResult = await languageService.findDocumentLinks(model.uri.toString());
178
+ if (codeResult) {
179
+ return {
180
+ links: codeResult.map(protocol2monaco.asLink),
181
+ };
182
+ }
183
+ },
184
+ async provideCompletionItems(model, position, context) {
185
+ const languageService = await worker.withSyncedResources(getSyncUris());
186
+ const codeResult = await languageService.doComplete(model.uri.toString(), monaco2protocol.asPosition(position), monaco2protocol.asCompletionContext(context));
187
+ const fallbackRange = {
188
+ start: monaco2protocol.asPosition(position),
189
+ end: monaco2protocol.asPosition(position),
190
+ };
191
+ const monacoResult = protocol2monaco.asCompletionList(codeResult, fallbackRange);
192
+ for (let i = 0; i < codeResult.items.length; i++) {
193
+ completionItems.set(monacoResult.suggestions[i], codeResult.items[i]);
194
+ }
195
+ return monacoResult;
196
+ },
197
+ async resolveCompletionItem(monacoItem) {
198
+ let codeItem = completionItems.get(monacoItem);
199
+ if (codeItem) {
200
+ const languageService = await worker.withSyncedResources(getSyncUris());
201
+ codeItem = await languageService.doCompletionResolve(codeItem);
202
+ const fallbackRange = 'replace' in monacoItem.range
203
+ ? monaco2protocol.asRange(monacoItem.range.replace)
204
+ : monaco2protocol.asRange(monacoItem.range);
205
+ monacoItem = protocol2monaco.asCompletionItem(codeItem, fallbackRange);
206
+ completionItems.set(monacoItem, codeItem);
207
+ }
208
+ return monacoItem;
209
+ },
210
+ async provideDocumentColors(model) {
211
+ const languageService = await worker.withSyncedResources(getSyncUris());
212
+ const codeResult = await languageService.findDocumentColors(model.uri.toString());
213
+ if (codeResult) {
214
+ return codeResult.map(protocol2monaco.asColorInformation);
215
+ }
216
+ },
217
+ async provideColorPresentations(model, monacoResult) {
218
+ const languageService = await worker.withSyncedResources(getSyncUris());
219
+ const codeResult = colorInfos.get(monacoResult);
220
+ if (codeResult) {
221
+ const codeColors = await languageService.getColorPresentations(model.uri.toString(), codeResult.color, {
222
+ start: monaco2protocol.asPosition(model.getPositionAt(0)),
223
+ end: monaco2protocol.asPosition(model.getPositionAt(model.getValueLength())),
41
224
  });
42
- },
43
- provideDocumentRangeSemanticTokens(model, range, token) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const languageService = yield worker.withSyncedResources(getSyncUris());
46
- const codeResult = yield languageService.getSemanticTokens(model.uri.toString(), monaco2protocol.asRange(range), language_service_1.standardSemanticTokensLegend, token);
47
- if (codeResult) {
48
- return {
49
- resultId: codeResult.resultId,
50
- data: Uint32Array.from(codeResult.data),
51
- };
52
- }
53
- });
54
- },
55
- releaseDocumentSemanticTokens() { },
56
- provideDocumentSymbols(model, token) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const languageService = yield worker.withSyncedResources(getSyncUris());
59
- const codeResult = yield languageService.findDocumentSymbols(model.uri.toString(), token);
60
- if (codeResult) {
61
- return codeResult.map(protocol2monaco.asDocumentSymbol);
62
- }
63
- });
64
- },
65
- provideDocumentHighlights(model, position, token) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const languageService = yield worker.withSyncedResources(getSyncUris());
68
- const codeResult = yield languageService.findDocumentHighlights(model.uri.toString(), monaco2protocol.asPosition(position), token);
69
- if (codeResult) {
70
- return codeResult.map(protocol2monaco.asDocumentHighlight);
71
- }
72
- });
73
- },
74
- provideLinkedEditingRanges(model, position, token) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const languageService = yield worker.withSyncedResources(getSyncUris());
77
- const codeResult = yield languageService.findLinkedEditingRanges(model.uri.toString(), monaco2protocol.asPosition(position), token);
78
- if (codeResult) {
79
- return {
80
- ranges: codeResult.ranges.map(protocol2monaco.asRange),
81
- wordPattern: codeResult.wordPattern
82
- ? new RegExp(codeResult.wordPattern)
83
- : undefined,
84
- };
85
- }
86
- });
87
- },
88
- provideDefinition(model, position, token) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const languageService = yield worker.withSyncedResources(getSyncUris());
91
- const codeResult = yield languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position), token);
92
- // TODO: can't show if only one result from libs
93
- if (codeResult) {
94
- return codeResult.map(protocol2monaco.asLocation);
95
- }
96
- });
97
- },
98
- provideImplementation(model, position, token) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const languageService = yield worker.withSyncedResources(getSyncUris());
101
- const codeResult = yield languageService.findImplementations(model.uri.toString(), monaco2protocol.asPosition(position), token);
102
- if (codeResult) {
103
- return codeResult.map(protocol2monaco.asLocation);
104
- }
105
- });
106
- },
107
- provideTypeDefinition(model, position, token) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- const languageService = yield worker.withSyncedResources(getSyncUris());
110
- const codeResult = yield languageService.findTypeDefinition(model.uri.toString(), monaco2protocol.asPosition(position), token);
111
- if (codeResult) {
112
- return codeResult.map(protocol2monaco.asLocation);
113
- }
114
- });
115
- },
116
- provideCodeLenses(model, token) {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- const languageService = yield worker.withSyncedResources(getSyncUris());
119
- const codeResult = yield languageService.doCodeLens(model.uri.toString(), token);
120
- if (codeResult) {
121
- const monacoResult = codeResult.map(protocol2monaco.asCodeLens);
122
- for (let i = 0; i < monacoResult.length; i++) {
123
- codeLens.set(monacoResult[i], codeResult[i]);
124
- }
125
- return {
126
- lenses: monacoResult,
127
- dispose: () => { },
128
- };
129
- }
130
- });
131
- },
132
- resolveCodeLens(_, monacoResult, token) {
133
- return __awaiter(this, void 0, void 0, function* () {
134
- let codeResult = codeLens.get(monacoResult);
135
- if (codeResult) {
136
- const languageService = yield worker.withSyncedResources(getSyncUris());
137
- codeResult = yield languageService.doCodeLensResolve(codeResult, token);
138
- if (codeResult) {
139
- monacoResult = protocol2monaco.asCodeLens(codeResult);
140
- codeLens.set(monacoResult, codeResult);
141
- }
142
- }
143
- return monacoResult;
144
- });
145
- },
146
- provideCodeActions(model, range, context, token) {
147
- return __awaiter(this, void 0, void 0, function* () {
148
- const diagnostics = [];
149
- for (const marker of context.markers) {
150
- const diagnostic = markers_1.markers.get(marker);
151
- if (diagnostic) {
152
- diagnostics.push(diagnostic);
153
- }
154
- }
155
- const languageService = yield worker.withSyncedResources(getSyncUris());
156
- const codeResult = yield languageService.doCodeActions(model.uri.toString(), monaco2protocol.asRange(range), {
157
- diagnostics: diagnostics,
158
- only: context.only ? [context.only] : undefined,
159
- }, token);
160
- if (codeResult) {
161
- const monacoResult = codeResult.map(protocol2monaco.asCodeAction);
162
- for (let i = 0; i < monacoResult.length; i++) {
163
- codeActions.set(monacoResult[i], codeResult[i]);
164
- }
165
- return {
166
- actions: monacoResult,
167
- dispose: () => { },
168
- };
169
- }
170
- });
171
- },
172
- resolveCodeAction(monacoResult, token) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- let codeResult = codeActions.get(monacoResult);
175
- if (codeResult) {
176
- const languageService = yield worker.withSyncedResources(getSyncUris());
177
- codeResult = yield languageService.doCodeActionResolve(codeResult, token);
178
- if (codeResult) {
179
- monacoResult = protocol2monaco.asCodeAction(codeResult);
180
- codeActions.set(monacoResult, codeResult);
181
- }
182
- }
183
- return monacoResult;
184
- });
185
- },
186
- provideDocumentFormattingEdits(model, options, token) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- const languageService = yield worker.withSyncedResources(getSyncUris());
189
- const codeResult = yield languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, undefined, token);
190
- if (codeResult) {
191
- return codeResult.map(protocol2monaco.asTextEdit);
192
- }
193
- });
194
- },
195
- provideDocumentRangeFormattingEdits(model, range, options, token) {
196
- return __awaiter(this, void 0, void 0, function* () {
197
- const languageService = yield worker.withSyncedResources(getSyncUris());
198
- const codeResult = yield languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), monaco2protocol.asRange(range), undefined, token);
199
- if (codeResult) {
200
- return codeResult.map(protocol2monaco.asTextEdit);
201
- }
202
- });
203
- },
204
- provideOnTypeFormattingEdits(model, position, ch, options, token) {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- const languageService = yield worker.withSyncedResources(getSyncUris());
207
- const codeResult = yield languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, {
208
- ch: ch,
209
- position: monaco2protocol.asPosition(position),
210
- }, token);
211
- if (codeResult) {
212
- return codeResult.map(protocol2monaco.asTextEdit);
213
- }
214
- });
215
- },
216
- provideLinks(model, token) {
217
- return __awaiter(this, void 0, void 0, function* () {
218
- const languageService = yield worker.withSyncedResources(getSyncUris());
219
- const codeResult = yield languageService.findDocumentLinks(model.uri.toString(), token);
220
- if (codeResult) {
221
- return {
222
- links: codeResult.map(protocol2monaco.asLink),
223
- };
224
- }
225
- });
226
- },
227
- provideCompletionItems(model, position, context, token) {
228
- return __awaiter(this, void 0, void 0, function* () {
229
- const languageService = yield worker.withSyncedResources(getSyncUris());
230
- const codeResult = yield languageService.doComplete(model.uri.toString(), monaco2protocol.asPosition(position), monaco2protocol.asCompletionContext(context), token);
231
- const fallbackRange = {
232
- start: monaco2protocol.asPosition(position),
233
- end: monaco2protocol.asPosition(position),
234
- };
235
- const monacoResult = protocol2monaco.asCompletionList(codeResult, fallbackRange);
236
- for (let i = 0; i < codeResult.items.length; i++) {
237
- completionItems.set(monacoResult.suggestions[i], codeResult.items[i]);
238
- }
239
- return monacoResult;
240
- });
241
- },
242
- resolveCompletionItem(monacoItem, token) {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- let codeItem = completionItems.get(monacoItem);
245
- if (codeItem) {
246
- const languageService = yield worker.withSyncedResources(getSyncUris());
247
- codeItem = yield languageService.doCompletionResolve(codeItem, token);
248
- const fallbackRange = 'replace' in monacoItem.range
249
- ? monaco2protocol.asRange(monacoItem.range.replace)
250
- : monaco2protocol.asRange(monacoItem.range);
251
- monacoItem = protocol2monaco.asCompletionItem(codeItem, fallbackRange);
252
- completionItems.set(monacoItem, codeItem);
253
- }
254
- return monacoItem;
255
- });
256
- },
257
- provideDocumentColors(model, token) {
258
- return __awaiter(this, void 0, void 0, function* () {
259
- const languageService = yield worker.withSyncedResources(getSyncUris());
260
- const codeResult = yield languageService.findDocumentColors(model.uri.toString(), token);
261
- if (codeResult) {
262
- return codeResult.map(protocol2monaco.asColorInformation);
263
- }
264
- });
265
- },
266
- provideColorPresentations(model, monacoResult, token) {
267
- return __awaiter(this, void 0, void 0, function* () {
268
- const languageService = yield worker.withSyncedResources(getSyncUris());
269
- const codeResult = colorInfos.get(monacoResult);
270
- if (codeResult) {
271
- const codeColors = yield languageService.getColorPresentations(model.uri.toString(), codeResult.color, {
272
- start: monaco2protocol.asPosition(model.getPositionAt(0)),
273
- end: monaco2protocol.asPosition(model.getPositionAt(model.getValueLength())),
274
- }, token);
275
- if (codeColors) {
276
- return codeColors.map(protocol2monaco.asColorPresentation);
277
- }
278
- }
279
- });
280
- },
281
- provideFoldingRanges(model, _context, token) {
282
- return __awaiter(this, void 0, void 0, function* () {
283
- const languageService = yield worker.withSyncedResources(getSyncUris());
284
- const codeResult = yield languageService.getFoldingRanges(model.uri.toString(), token);
285
- if (codeResult) {
286
- return codeResult.map(protocol2monaco.asFoldingRange);
287
- }
288
- });
289
- },
290
- provideDeclaration(model, position, token) {
291
- return __awaiter(this, void 0, void 0, function* () {
292
- const languageService = yield worker.withSyncedResources(getSyncUris());
293
- const codeResult = yield languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position), token);
294
- if (codeResult) {
295
- return codeResult.map(protocol2monaco.asLocation);
296
- }
297
- });
298
- },
299
- provideSelectionRanges(model, positions, token) {
300
- return __awaiter(this, void 0, void 0, function* () {
301
- const languageService = yield worker.withSyncedResources(getSyncUris());
302
- const codeResults = yield Promise.all(positions.map((position) => languageService.getSelectionRanges(model.uri.toString(), [monaco2protocol.asPosition(position)], token)));
303
- return codeResults.map((codeResult) => { var _a; return (_a = codeResult === null || codeResult === void 0 ? void 0 : codeResult.map(protocol2monaco.asSelectionRange)) !== null && _a !== void 0 ? _a : []; });
304
- });
305
- },
306
- provideSignatureHelp(model, position, token, context) {
307
- return __awaiter(this, void 0, void 0, function* () {
308
- const languageService = yield worker.withSyncedResources(getSyncUris());
309
- const codeResult = yield languageService.getSignatureHelp(model.uri.toString(), monaco2protocol.asPosition(position), monaco2protocol.asSignatureHelpContext(context), token);
310
- if (codeResult) {
311
- return {
312
- value: protocol2monaco.asSignatureHelp(codeResult),
313
- dispose: () => { },
314
- };
315
- }
316
- });
317
- },
318
- provideRenameEdits(model, position, newName, token) {
319
- return __awaiter(this, void 0, void 0, function* () {
320
- const languageService = yield worker.withSyncedResources(getSyncUris());
321
- const codeResult = yield languageService.doRename(model.uri.toString(), monaco2protocol.asPosition(position), newName, token);
322
- if (codeResult) {
323
- return protocol2monaco.asWorkspaceEdit(codeResult);
324
- }
325
- });
326
- },
327
- provideReferences(model, position, _context, token) {
328
- return __awaiter(this, void 0, void 0, function* () {
329
- const languageService = yield worker.withSyncedResources(getSyncUris());
330
- const codeResult = yield languageService.findReferences(model.uri.toString(), monaco2protocol.asPosition(position), token);
331
- // TODO: can't show if only one result from libs
332
- if (codeResult) {
333
- return codeResult.map(protocol2monaco.asLocation);
334
- }
335
- });
336
- },
337
- provideInlayHints(model, range, token) {
338
- return __awaiter(this, void 0, void 0, function* () {
339
- const languageService = yield worker.withSyncedResources(getSyncUris());
340
- const codeResult = yield languageService.getInlayHints(model.uri.toString(), monaco2protocol.asRange(range), token);
341
- if (codeResult) {
342
- return {
343
- hints: codeResult.map(protocol2monaco.asInlayHint),
344
- dispose: () => { },
345
- };
346
- }
347
- });
348
- },
349
- provideHover(model, position, token) {
350
- return __awaiter(this, void 0, void 0, function* () {
351
- const languageService = yield worker.withSyncedResources(getSyncUris());
352
- const codeResult = yield languageService.doHover(model.uri.toString(), monaco2protocol.asPosition(position), token);
353
- if (codeResult) {
354
- return protocol2monaco.asHover(codeResult);
355
- }
356
- });
357
- },
358
- };
359
- });
225
+ if (codeColors) {
226
+ return codeColors.map(protocol2monaco.asColorPresentation);
227
+ }
228
+ }
229
+ },
230
+ async provideFoldingRanges(model, _context) {
231
+ const languageService = await worker.withSyncedResources(getSyncUris());
232
+ const codeResult = await languageService.getFoldingRanges(model.uri.toString());
233
+ if (codeResult) {
234
+ return codeResult.map(protocol2monaco.asFoldingRange);
235
+ }
236
+ },
237
+ async provideDeclaration(model, position) {
238
+ const languageService = await worker.withSyncedResources(getSyncUris());
239
+ const codeResult = await languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
240
+ if (codeResult) {
241
+ return codeResult.map(protocol2monaco.asLocation);
242
+ }
243
+ },
244
+ async provideSelectionRanges(model, positions) {
245
+ const languageService = await worker.withSyncedResources(getSyncUris());
246
+ const codeResults = await Promise.all(positions.map((position) => languageService.getSelectionRanges(model.uri.toString(), [monaco2protocol.asPosition(position)])));
247
+ return codeResults.map((codeResult) => codeResult?.map(protocol2monaco.asSelectionRange) ?? []);
248
+ },
249
+ async provideSignatureHelp(model, position, _token, context) {
250
+ const languageService = await worker.withSyncedResources(getSyncUris());
251
+ const codeResult = await languageService.getSignatureHelp(model.uri.toString(), monaco2protocol.asPosition(position), monaco2protocol.asSignatureHelpContext(context));
252
+ if (codeResult) {
253
+ return {
254
+ value: protocol2monaco.asSignatureHelp(codeResult),
255
+ dispose: () => { },
256
+ };
257
+ }
258
+ },
259
+ async provideRenameEdits(model, position, newName) {
260
+ const languageService = await worker.withSyncedResources(getSyncUris());
261
+ const codeResult = await languageService.doRename(model.uri.toString(), monaco2protocol.asPosition(position), newName);
262
+ if (codeResult) {
263
+ return protocol2monaco.asWorkspaceEdit(codeResult);
264
+ }
265
+ },
266
+ async provideReferences(model, position, _context) {
267
+ const languageService = await worker.withSyncedResources(getSyncUris());
268
+ const codeResult = await languageService.findReferences(model.uri.toString(), monaco2protocol.asPosition(position));
269
+ if (codeResult) {
270
+ return codeResult.map(protocol2monaco.asLocation);
271
+ }
272
+ },
273
+ async provideInlayHints(model, range) {
274
+ const languageService = await worker.withSyncedResources(getSyncUris());
275
+ const codeResult = await languageService.getInlayHints(model.uri.toString(), monaco2protocol.asRange(range));
276
+ if (codeResult) {
277
+ return {
278
+ hints: codeResult.map(protocol2monaco.asInlayHint),
279
+ dispose: () => { },
280
+ };
281
+ }
282
+ },
283
+ async provideHover(model, position) {
284
+ const languageService = await worker.withSyncedResources(getSyncUris());
285
+ const codeResult = await languageService.doHover(model.uri.toString(), monaco2protocol.asPosition(position));
286
+ if (codeResult) {
287
+ return protocol2monaco.asHover(codeResult);
288
+ }
289
+ },
290
+ };
360
291
  }
361
292
  exports.createLanguageFeaturesProvider = createLanguageFeaturesProvider;
362
293
  //# sourceMappingURL=provider.js.map
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.2",
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.2",
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": "034b230da17794a6fcf5a0b07668710f98ff84e3"
25
24
  }