@volar/monaco 1.3.0-alpha.2-patch.1 → 1.3.0-alpha.3-patch.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/README.md CHANGED
@@ -89,7 +89,15 @@ languages.onLanguage('my-lang', () => {
89
89
  worker,
90
90
  ['my-lang'],
91
91
  'my-lang-markers-owner',
92
- // root files
92
+ // sync files
93
+ () => [Uri.file('/Foo.my-lang'), Uri.file('/Bar.my-lang')],
94
+ editor
95
+ );
96
+ // auto close tags
97
+ VolarMonaco.editor.activateAutoInsertion(
98
+ worker,
99
+ ['my-lang'],
100
+ // sync files
93
101
  () => [Uri.file('/Foo.my-lang'), Uri.file('/Bar.my-lang')],
94
102
  editor
95
103
  );
package/out/editor.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { LanguageService } from '@volar/language-service';
2
- import type { editor as _editor, IDisposable, Uri } from 'monaco-editor-core';
2
+ import { editor as _editor, IDisposable, Uri } from 'monaco-editor-core';
3
3
  export declare namespace editor {
4
4
  function activateMarkers(worker: _editor.MonacoWebWorker<LanguageService>, languages: string[], markersOwn: string, getSyncUris: () => Uri[], editor: typeof import('monaco-editor-core').editor): IDisposable;
5
+ function activateAutoInsertion(worker: _editor.MonacoWebWorker<LanguageService>, languages: string[], getSyncUris: () => Uri[], editor: typeof import('monaco-editor-core').editor): IDisposable;
5
6
  }
package/out/editor.js CHANGED
@@ -9,8 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.editor = void 0;
12
+ const monaco_editor_core_1 = require("monaco-editor-core");
12
13
  const markers_1 = require("./utils/markers");
13
14
  const protocol2monaco = require("./utils/protocol2monaco");
15
+ const monaco2protocol = require("./utils/monaco2protocol");
14
16
  var editor;
15
17
  (function (editor_1) {
16
18
  function activateMarkers(worker, languages, markersOwn, getSyncUris, editor) {
@@ -85,5 +87,88 @@ var editor;
85
87
  }
86
88
  }
87
89
  editor_1.activateMarkers = activateMarkers;
90
+ function activateAutoInsertion(worker, languages, getSyncUris, editor) {
91
+ const disposables = [];
92
+ const listener = new Map();
93
+ let timeout;
94
+ disposables.push(editor.onDidCreateModel((model) => hostingAutoInsertion(model)), editor.onWillDisposeModel(stopHostingAutoInsertion), editor.onDidChangeModelLanguage((event) => {
95
+ stopHostingAutoInsertion(event.model);
96
+ hostingAutoInsertion(event.model);
97
+ }), {
98
+ dispose: () => {
99
+ for (const disposable of listener.values()) {
100
+ disposable.dispose();
101
+ }
102
+ listener.clear();
103
+ }
104
+ });
105
+ for (const model of editor.getModels()) {
106
+ hostingAutoInsertion(model);
107
+ }
108
+ return { dispose: () => disposables.forEach((d) => d.dispose()) };
109
+ function stopHostingAutoInsertion(model) {
110
+ var _a;
111
+ if (listener.has(model)) {
112
+ (_a = listener.get(model)) === null || _a === void 0 ? void 0 : _a.dispose();
113
+ listener.delete(model);
114
+ }
115
+ }
116
+ function hostingAutoInsertion(model) {
117
+ if (!languages.includes(model.getLanguageId())) {
118
+ return;
119
+ }
120
+ listener.set(model, model.onDidChangeContent((e) => {
121
+ if (model.isDisposed()) {
122
+ return;
123
+ }
124
+ if (!model.isAttachedToEditor()) {
125
+ return;
126
+ }
127
+ if (e.changes.length === 0 || e.isUndoing || e.isRedoing) {
128
+ return;
129
+ }
130
+ const lastChange = e.changes[e.changes.length - 1];
131
+ doAutoInsert(model, lastChange);
132
+ }));
133
+ }
134
+ function doAutoInsert(model, lastChange) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ if (timeout) {
137
+ clearTimeout(timeout);
138
+ timeout = undefined;
139
+ }
140
+ const version = model.getVersionId();
141
+ timeout = setTimeout(() => {
142
+ (() => __awaiter(this, void 0, void 0, function* () {
143
+ var _a;
144
+ if (model.getVersionId() !== version) {
145
+ return;
146
+ }
147
+ const position = new monaco_editor_core_1.Position(lastChange.range.startLineNumber, lastChange.range.startColumn + lastChange.text.length);
148
+ const languageService = yield worker.withSyncedResources(getSyncUris());
149
+ const edit = yield languageService.doAutoInsert(model.uri.toString(), monaco2protocol.asPosition(position), {
150
+ lastChange: {
151
+ range: monaco2protocol.asRange(lastChange.range),
152
+ rangeLength: lastChange.rangeLength,
153
+ text: lastChange.text,
154
+ rangeOffset: lastChange.rangeOffset,
155
+ },
156
+ });
157
+ const codeEditor = editor.getEditors().find((e) => e.getModel() === model);
158
+ if (codeEditor && edit && model.getVersionId() === version) {
159
+ if (typeof edit === 'string') {
160
+ (_a = codeEditor === null || codeEditor === void 0 ? void 0 : codeEditor.getContribution('snippetController2')) === null || _a === void 0 ? void 0 : _a.insert(edit);
161
+ }
162
+ else {
163
+ model.pushEditOperations([], [protocol2monaco.asTextEdit(edit)], () => []);
164
+ }
165
+ }
166
+ }))();
167
+ timeout = undefined;
168
+ }, 100);
169
+ });
170
+ }
171
+ }
172
+ editor_1.activateAutoInsertion = activateAutoInsertion;
88
173
  })(editor = exports.editor || (exports.editor = {}));
89
174
  //# sourceMappingURL=editor.js.map
@@ -26,8 +26,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
26
26
  signatureHelpTriggerCharacters: ['(', ','],
27
27
  provideDocumentSymbols(model, _token) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
- const worker = yield getLanguageService(model.uri);
30
- const codeResult = yield worker.findDocumentSymbols(model.uri.toString());
29
+ const languageService = yield worker.withSyncedResources(getSyncUris());
30
+ const codeResult = yield languageService.findDocumentSymbols(model.uri.toString());
31
31
  if (codeResult) {
32
32
  return codeResult.map(protocol2monaco.asDocumentSymbol);
33
33
  }
@@ -35,8 +35,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
35
35
  },
36
36
  provideDocumentHighlights(model, position, _token) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
- const worker = yield getLanguageService(model.uri);
39
- const codeResult = yield worker.findDocumentHighlights(model.uri.toString(), monaco2protocol.asPosition(position));
38
+ const languageService = yield worker.withSyncedResources(getSyncUris());
39
+ const codeResult = yield languageService.findDocumentHighlights(model.uri.toString(), monaco2protocol.asPosition(position));
40
40
  if (codeResult) {
41
41
  return codeResult.map(protocol2monaco.asDocumentHighlight);
42
42
  }
@@ -44,8 +44,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
44
44
  },
45
45
  provideLinkedEditingRanges(model, position, _token) {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
- const worker = yield getLanguageService(model.uri);
48
- const codeResult = yield worker.findLinkedEditingRanges(model.uri.toString(), monaco2protocol.asPosition(position));
47
+ const languageService = yield worker.withSyncedResources(getSyncUris());
48
+ const codeResult = yield languageService.findLinkedEditingRanges(model.uri.toString(), monaco2protocol.asPosition(position));
49
49
  if (codeResult) {
50
50
  return {
51
51
  ranges: codeResult.ranges.map(protocol2monaco.asRange),
@@ -58,8 +58,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
58
58
  },
59
59
  provideDefinition(model, position, _token) {
60
60
  return __awaiter(this, void 0, void 0, function* () {
61
- const worker = yield getLanguageService(model.uri);
62
- const codeResult = yield worker.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
61
+ const languageService = yield worker.withSyncedResources(getSyncUris());
62
+ const codeResult = yield languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
63
63
  // TODO: can't show if only one result from libs
64
64
  if (codeResult) {
65
65
  return codeResult.map(protocol2monaco.asLocation);
@@ -68,8 +68,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
68
68
  },
69
69
  provideImplementation(model, position, _token) {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
- const worker = yield getLanguageService(model.uri);
72
- const codeResult = yield worker.findImplementations(model.uri.toString(), monaco2protocol.asPosition(position));
71
+ const languageService = yield worker.withSyncedResources(getSyncUris());
72
+ const codeResult = yield languageService.findImplementations(model.uri.toString(), monaco2protocol.asPosition(position));
73
73
  if (codeResult) {
74
74
  return codeResult.map(protocol2monaco.asLocation);
75
75
  }
@@ -77,8 +77,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
77
77
  },
78
78
  provideTypeDefinition(model, position, _token) {
79
79
  return __awaiter(this, void 0, void 0, function* () {
80
- const worker = yield getLanguageService(model.uri);
81
- const codeResult = yield worker.findTypeDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
80
+ const languageService = yield worker.withSyncedResources(getSyncUris());
81
+ const codeResult = yield languageService.findTypeDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
82
82
  if (codeResult) {
83
83
  return codeResult.map(protocol2monaco.asLocation);
84
84
  }
@@ -86,8 +86,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
86
86
  },
87
87
  provideCodeLenses(model, _token) {
88
88
  return __awaiter(this, void 0, void 0, function* () {
89
- const worker = yield getLanguageService(model.uri);
90
- const codeResult = yield worker.doCodeLens(model.uri.toString());
89
+ const languageService = yield worker.withSyncedResources(getSyncUris());
90
+ const codeResult = yield languageService.doCodeLens(model.uri.toString());
91
91
  if (codeResult) {
92
92
  const monacoResult = codeResult.map(protocol2monaco.asCodeLens);
93
93
  for (let i = 0; i < monacoResult.length; i++) {
@@ -100,12 +100,12 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
100
100
  }
101
101
  });
102
102
  },
103
- resolveCodeLens(model, monacoResult) {
103
+ resolveCodeLens(_, monacoResult) {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  let codeResult = codeLens.get(monacoResult);
106
106
  if (codeResult) {
107
- const worker = yield getLanguageService(model.uri);
108
- codeResult = yield worker.doCodeLensResolve(codeResult);
107
+ const languageService = yield worker.withSyncedResources(getSyncUris());
108
+ codeResult = yield languageService.doCodeLensResolve(codeResult);
109
109
  if (codeResult) {
110
110
  monacoResult = protocol2monaco.asCodeLens(codeResult);
111
111
  codeLens.set(monacoResult, codeResult);
@@ -123,8 +123,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
123
123
  diagnostics.push(diagnostic);
124
124
  }
125
125
  }
126
- const worker = yield getLanguageService(model.uri);
127
- const codeResult = yield worker.doCodeActions(model.uri.toString(), monaco2protocol.asRange(range), {
126
+ const languageService = yield worker.withSyncedResources(getSyncUris());
127
+ const codeResult = yield languageService.doCodeActions(model.uri.toString(), monaco2protocol.asRange(range), {
128
128
  diagnostics: diagnostics,
129
129
  only: context.only ? [context.only] : undefined,
130
130
  });
@@ -144,8 +144,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
144
144
  return __awaiter(this, void 0, void 0, function* () {
145
145
  let codeResult = codeActions.get(monacoResult);
146
146
  if (codeResult) {
147
- const worker = yield getLanguageService();
148
- codeResult = yield worker.doCodeActionResolve(codeResult);
147
+ const languageService = yield worker.withSyncedResources(getSyncUris());
148
+ codeResult = yield languageService.doCodeActionResolve(codeResult);
149
149
  if (codeResult) {
150
150
  monacoResult = protocol2monaco.asCodeAction(codeResult);
151
151
  codeActions.set(monacoResult, codeResult);
@@ -156,8 +156,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
156
156
  },
157
157
  provideDocumentFormattingEdits(model, options, _token) {
158
158
  return __awaiter(this, void 0, void 0, function* () {
159
- const worker = yield getLanguageService(model.uri);
160
- const codeResult = yield worker.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options));
159
+ const languageService = yield worker.withSyncedResources(getSyncUris());
160
+ const codeResult = yield languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options));
161
161
  if (codeResult) {
162
162
  return codeResult.map(protocol2monaco.asTextEdit);
163
163
  }
@@ -165,8 +165,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
165
165
  },
166
166
  provideDocumentRangeFormattingEdits(model, range, options, _token) {
167
167
  return __awaiter(this, void 0, void 0, function* () {
168
- const worker = yield getLanguageService(model.uri);
169
- const codeResult = yield worker.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), monaco2protocol.asRange(range));
168
+ const languageService = yield worker.withSyncedResources(getSyncUris());
169
+ const codeResult = yield languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), monaco2protocol.asRange(range));
170
170
  if (codeResult) {
171
171
  return codeResult.map(protocol2monaco.asTextEdit);
172
172
  }
@@ -174,8 +174,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
174
174
  },
175
175
  provideOnTypeFormattingEdits(model, position, ch, options, _token) {
176
176
  return __awaiter(this, void 0, void 0, function* () {
177
- const worker = yield getLanguageService(model.uri);
178
- const codeResult = yield worker.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, {
177
+ const languageService = yield worker.withSyncedResources(getSyncUris());
178
+ const codeResult = yield languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, {
179
179
  ch: ch,
180
180
  position: monaco2protocol.asPosition(position),
181
181
  });
@@ -186,8 +186,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
186
186
  },
187
187
  provideLinks(model, _token) {
188
188
  return __awaiter(this, void 0, void 0, function* () {
189
- const worker = yield getLanguageService(model.uri);
190
- const codeResult = yield worker.findDocumentLinks(model.uri.toString());
189
+ const languageService = yield worker.withSyncedResources(getSyncUris());
190
+ const codeResult = yield languageService.findDocumentLinks(model.uri.toString());
191
191
  if (codeResult) {
192
192
  return {
193
193
  links: codeResult.map(protocol2monaco.asLink),
@@ -197,8 +197,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
197
197
  },
198
198
  provideCompletionItems(model, position, context, _token) {
199
199
  return __awaiter(this, void 0, void 0, function* () {
200
- const worker = yield getLanguageService(model.uri);
201
- const codeResult = yield worker.doComplete(model.uri.toString(), monaco2protocol.asPosition(position), monaco2protocol.asCompletionContext(context));
200
+ const languageService = yield worker.withSyncedResources(getSyncUris());
201
+ const codeResult = yield languageService.doComplete(model.uri.toString(), monaco2protocol.asPosition(position), monaco2protocol.asCompletionContext(context));
202
202
  const fallbackRange = {
203
203
  start: monaco2protocol.asPosition(position),
204
204
  end: monaco2protocol.asPosition(position),
@@ -214,8 +214,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
214
214
  return __awaiter(this, void 0, void 0, function* () {
215
215
  let codeItem = completionItems.get(monacoItem);
216
216
  if (codeItem) {
217
- const worker = yield getLanguageService();
218
- codeItem = yield worker.doCompletionResolve(codeItem);
217
+ const languageService = yield worker.withSyncedResources(getSyncUris());
218
+ codeItem = yield languageService.doCompletionResolve(codeItem);
219
219
  const fallbackRange = 'replace' in monacoItem.range
220
220
  ? monaco2protocol.asRange(monacoItem.range.replace)
221
221
  : monaco2protocol.asRange(monacoItem.range);
@@ -227,8 +227,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
227
227
  },
228
228
  provideDocumentColors(model, _token) {
229
229
  return __awaiter(this, void 0, void 0, function* () {
230
- const worker = yield getLanguageService(model.uri);
231
- const codeResult = yield worker.findDocumentColors(model.uri.toString());
230
+ const languageService = yield worker.withSyncedResources(getSyncUris());
231
+ const codeResult = yield languageService.findDocumentColors(model.uri.toString());
232
232
  if (codeResult) {
233
233
  return codeResult.map(protocol2monaco.asColorInformation);
234
234
  }
@@ -236,10 +236,10 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
236
236
  },
237
237
  provideColorPresentations(model, monacoResult) {
238
238
  return __awaiter(this, void 0, void 0, function* () {
239
- const worker = yield getLanguageService(model.uri);
239
+ const languageService = yield worker.withSyncedResources(getSyncUris());
240
240
  const codeResult = colorInfos.get(monacoResult);
241
241
  if (codeResult) {
242
- const codeColors = yield worker.getColorPresentations(model.uri.toString(), codeResult.color, {
242
+ const codeColors = yield languageService.getColorPresentations(model.uri.toString(), codeResult.color, {
243
243
  start: monaco2protocol.asPosition(model.getPositionAt(0)),
244
244
  end: monaco2protocol.asPosition(model.getPositionAt(model.getValueLength())),
245
245
  });
@@ -251,8 +251,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
251
251
  },
252
252
  provideFoldingRanges(model, _context, _token) {
253
253
  return __awaiter(this, void 0, void 0, function* () {
254
- const worker = yield getLanguageService(model.uri);
255
- const codeResult = yield worker.getFoldingRanges(model.uri.toString());
254
+ const languageService = yield worker.withSyncedResources(getSyncUris());
255
+ const codeResult = yield languageService.getFoldingRanges(model.uri.toString());
256
256
  if (codeResult) {
257
257
  return codeResult.map(protocol2monaco.asFoldingRange);
258
258
  }
@@ -260,8 +260,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
260
260
  },
261
261
  provideDeclaration(model, position, _token) {
262
262
  return __awaiter(this, void 0, void 0, function* () {
263
- const worker = yield getLanguageService(model.uri);
264
- const codeResult = yield worker.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
263
+ const languageService = yield worker.withSyncedResources(getSyncUris());
264
+ const codeResult = yield languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
265
265
  if (codeResult) {
266
266
  return codeResult.map(protocol2monaco.asLocation);
267
267
  }
@@ -269,8 +269,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
269
269
  },
270
270
  provideSelectionRanges(model, positions, _token) {
271
271
  return __awaiter(this, void 0, void 0, function* () {
272
- const worker = yield getLanguageService(model.uri);
273
- const codeResults = yield Promise.all(positions.map((position) => worker.getSelectionRanges(model.uri.toString(), [
272
+ const languageService = yield worker.withSyncedResources(getSyncUris());
273
+ const codeResults = yield Promise.all(positions.map((position) => languageService.getSelectionRanges(model.uri.toString(), [
274
274
  monaco2protocol.asPosition(position),
275
275
  ])));
276
276
  return codeResults.map((codeResult) => { var _a; return (_a = codeResult === null || codeResult === void 0 ? void 0 : codeResult.map(protocol2monaco.asSelectionRange)) !== null && _a !== void 0 ? _a : []; });
@@ -278,8 +278,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
278
278
  },
279
279
  provideSignatureHelp(model, position, _token, _context) {
280
280
  return __awaiter(this, void 0, void 0, function* () {
281
- const worker = yield getLanguageService(model.uri);
282
- const codeResult = yield worker.getSignatureHelp(model.uri.toString(), monaco2protocol.asPosition(position));
281
+ const languageService = yield worker.withSyncedResources(getSyncUris());
282
+ const codeResult = yield languageService.getSignatureHelp(model.uri.toString(), monaco2protocol.asPosition(position));
283
283
  if (codeResult) {
284
284
  return {
285
285
  value: protocol2monaco.asSignatureHelp(codeResult),
@@ -290,8 +290,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
290
290
  },
291
291
  provideRenameEdits(model, position, newName, _token) {
292
292
  return __awaiter(this, void 0, void 0, function* () {
293
- const worker = yield getLanguageService(model.uri);
294
- const codeResult = yield worker.doRename(model.uri.toString(), monaco2protocol.asPosition(position), newName);
293
+ const languageService = yield worker.withSyncedResources(getSyncUris());
294
+ const codeResult = yield languageService.doRename(model.uri.toString(), monaco2protocol.asPosition(position), newName);
295
295
  if (codeResult) {
296
296
  return protocol2monaco.asWorkspaceEdit(codeResult);
297
297
  }
@@ -299,8 +299,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
299
299
  },
300
300
  provideReferences(model, position, _context, _token) {
301
301
  return __awaiter(this, void 0, void 0, function* () {
302
- const worker = yield getLanguageService(model.uri);
303
- const codeResult = yield worker.findReferences(model.uri.toString(), monaco2protocol.asPosition(position));
302
+ const languageService = yield worker.withSyncedResources(getSyncUris());
303
+ const codeResult = yield languageService.findReferences(model.uri.toString(), monaco2protocol.asPosition(position));
304
304
  // TODO: can't show if only one result from libs
305
305
  if (codeResult) {
306
306
  return codeResult.map(protocol2monaco.asLocation);
@@ -309,8 +309,8 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
309
309
  },
310
310
  provideInlayHints(model, range, _token) {
311
311
  return __awaiter(this, void 0, void 0, function* () {
312
- const worker = yield getLanguageService(model.uri);
313
- const codeResult = yield worker.getInlayHints(model.uri.toString(), monaco2protocol.asRange(range));
312
+ const languageService = yield worker.withSyncedResources(getSyncUris());
313
+ const codeResult = yield languageService.getInlayHints(model.uri.toString(), monaco2protocol.asRange(range));
314
314
  if (codeResult) {
315
315
  return {
316
316
  hints: codeResult.map(protocol2monaco.asInlayHint),
@@ -321,20 +321,14 @@ function createLanguageFeaturesProvider(worker, getSyncUris) {
321
321
  },
322
322
  provideHover(model, position, _token) {
323
323
  return __awaiter(this, void 0, void 0, function* () {
324
- const worker = yield getLanguageService(model.uri);
325
- const codeResult = yield worker.doHover(model.uri.toString(), monaco2protocol.asPosition(position));
324
+ const languageService = yield worker.withSyncedResources(getSyncUris());
325
+ const codeResult = yield languageService.doHover(model.uri.toString(), monaco2protocol.asPosition(position));
326
326
  if (codeResult) {
327
327
  return protocol2monaco.asHover(codeResult);
328
328
  }
329
329
  });
330
330
  },
331
331
  };
332
- function getLanguageService(..._uris) {
333
- return __awaiter(this, void 0, void 0, function* () {
334
- yield worker.withSyncedResources(getSyncUris());
335
- return worker.getProxy();
336
- });
337
- }
338
332
  });
339
333
  }
340
334
  exports.createLanguageFeaturesProvider = createLanguageFeaturesProvider;
package/out/worker.d.ts CHANGED
@@ -20,5 +20,10 @@ declare class CdnDtsHost {
20
20
  getVersion(): Promise<number>;
21
21
  readFile(fileName: string): string | Promise<string | undefined>;
22
22
  fetch(fileName: string, url: string): Promise<string | undefined>;
23
+ /**
24
+ * save / load with json
25
+ */
26
+ toJson(): Promise<Record<string, string | null>>;
27
+ fromJson(json: Record<string, string | null>): void;
23
28
  }
24
29
  export {};
package/out/worker.js CHANGED
@@ -219,6 +219,24 @@ class CdnDtsHost {
219
219
  }
220
220
  });
221
221
  }
222
+ /**
223
+ * save / load with json
224
+ */
225
+ toJson() {
226
+ var _a;
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ const json = {};
229
+ for (const [fileName, file] of this.files) {
230
+ json[fileName] = (_a = (yield file)) !== null && _a !== void 0 ? _a : null;
231
+ }
232
+ return json;
233
+ });
234
+ }
235
+ fromJson(json) {
236
+ for (const [fileName, file] of Object.entries(json)) {
237
+ this.files.set(fileName, file !== null && file !== void 0 ? file : undefined);
238
+ }
239
+ }
222
240
  }
223
241
  function createDtsClient(server) {
224
242
  const fetchTasks = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/monaco",
3
- "version": "1.3.0-alpha.2-patch.1",
3
+ "version": "1.3.0-alpha.3-patch.1",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  "directory": "packages/monaco"
16
16
  },
17
17
  "dependencies": {
18
- "@volar/language-service": "1.3.0-alpha.2",
18
+ "@volar/language-service": "1.3.0-alpha.3",
19
19
  "axios": "^1.3.4",
20
20
  "monaco-editor-core": "^0.36.0",
21
21
  "vscode-languageserver-protocol": "^3.17.3",
package/out/dts.d.ts DELETED
File without changes
package/out/dts.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=dts.js.map