@volar/monaco 1.3.0-alpha.0
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/LICENSE +21 -0
- package/README.md +97 -0
- package/out/editor.d.ts +5 -0
- package/out/editor.js +95 -0
- package/out/index.d.ts +2 -0
- package/out/index.js +18 -0
- package/out/languages.d.ts +5 -0
- package/out/languages.js +47 -0
- package/out/utils/autoFetchTypes.d.ts +6 -0
- package/out/utils/autoFetchTypes.js +82 -0
- package/out/utils/markers.d.ts +3 -0
- package/out/utils/markers.js +4 -0
- package/out/utils/monaco2protocol.d.ts +7 -0
- package/out/utils/monaco2protocol.js +38 -0
- package/out/utils/protocol2monaco.d.ts +38 -0
- package/out/utils/protocol2monaco.js +490 -0
- package/out/utils/provider.d.ts +3 -0
- package/out/utils/provider.js +341 -0
- package/out/worker.d.ts +15 -0
- package/out/worker.js +179 -0
- package/package.json +25 -0
- package/worker.d.ts +1 -0
- package/worker.js +1 -0
|
@@ -0,0 +1,341 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createLanguageFeaturesProvider = void 0;
|
|
12
|
+
const markers_1 = require("./markers");
|
|
13
|
+
const monaco2protocol = require("./monaco2protocol");
|
|
14
|
+
const protocol2monaco = require("./protocol2monaco");
|
|
15
|
+
function createLanguageFeaturesProvider(worker) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const completionItems = new WeakMap();
|
|
18
|
+
const codeLens = new WeakMap();
|
|
19
|
+
const codeActions = new WeakMap();
|
|
20
|
+
const colorInfos = new WeakMap();
|
|
21
|
+
const languageService = yield worker.getProxy();
|
|
22
|
+
return {
|
|
23
|
+
triggerCharacters: yield languageService.triggerCharacters(),
|
|
24
|
+
// TODO
|
|
25
|
+
autoFormatTriggerCharacters: ['}', ';', '\n'],
|
|
26
|
+
signatureHelpTriggerCharacters: ['(', ','],
|
|
27
|
+
provideDocumentSymbols(model, _token) {
|
|
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());
|
|
31
|
+
if (codeResult) {
|
|
32
|
+
return codeResult.map(protocol2monaco.asDocumentSymbol);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
provideDocumentHighlights(model, position, _token) {
|
|
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));
|
|
40
|
+
if (codeResult) {
|
|
41
|
+
return codeResult.map(protocol2monaco.asDocumentHighlight);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
provideLinkedEditingRanges(model, position, _token) {
|
|
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));
|
|
49
|
+
if (codeResult) {
|
|
50
|
+
return {
|
|
51
|
+
ranges: codeResult.ranges.map(protocol2monaco.asRange),
|
|
52
|
+
wordPattern: codeResult.wordPattern
|
|
53
|
+
? new RegExp(codeResult.wordPattern)
|
|
54
|
+
: undefined,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
provideDefinition(model, position, _token) {
|
|
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));
|
|
63
|
+
// TODO: can't show if only one result from libs
|
|
64
|
+
if (codeResult) {
|
|
65
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
provideImplementation(model, position, _token) {
|
|
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));
|
|
73
|
+
if (codeResult) {
|
|
74
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
provideTypeDefinition(model, position, _token) {
|
|
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));
|
|
82
|
+
if (codeResult) {
|
|
83
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
provideCodeLenses(model, _token) {
|
|
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());
|
|
91
|
+
if (codeResult) {
|
|
92
|
+
const monacoResult = codeResult.map(protocol2monaco.asCodeLens);
|
|
93
|
+
for (let i = 0; i < monacoResult.length; i++) {
|
|
94
|
+
codeLens.set(monacoResult[i], codeResult[i]);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
lenses: monacoResult,
|
|
98
|
+
dispose: () => { },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
resolveCodeLens(model, monacoResult) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
let codeResult = codeLens.get(monacoResult);
|
|
106
|
+
if (codeResult) {
|
|
107
|
+
const worker = yield getLanguageService(model.uri);
|
|
108
|
+
codeResult = yield worker.doCodeLensResolve(codeResult);
|
|
109
|
+
if (codeResult) {
|
|
110
|
+
monacoResult = protocol2monaco.asCodeLens(codeResult);
|
|
111
|
+
codeLens.set(monacoResult, codeResult);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return monacoResult;
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
provideCodeActions(model, range, context, _token) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const diagnostics = [];
|
|
120
|
+
for (const marker of context.markers) {
|
|
121
|
+
const diagnostic = markers_1.markers.get(marker);
|
|
122
|
+
if (diagnostic) {
|
|
123
|
+
diagnostics.push(diagnostic);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const worker = yield getLanguageService(model.uri);
|
|
127
|
+
const codeResult = yield worker.doCodeActions(model.uri.toString(), monaco2protocol.asRange(range), {
|
|
128
|
+
diagnostics: diagnostics,
|
|
129
|
+
only: context.only ? [context.only] : undefined,
|
|
130
|
+
});
|
|
131
|
+
if (codeResult) {
|
|
132
|
+
const monacoResult = codeResult.map(protocol2monaco.asCodeAction);
|
|
133
|
+
for (let i = 0; i < monacoResult.length; i++) {
|
|
134
|
+
codeActions.set(monacoResult[i], codeResult[i]);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
actions: monacoResult,
|
|
138
|
+
dispose: () => { },
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
resolveCodeAction(monacoResult) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
let codeResult = codeActions.get(monacoResult);
|
|
146
|
+
if (codeResult) {
|
|
147
|
+
const worker = yield getLanguageService();
|
|
148
|
+
codeResult = yield worker.doCodeActionResolve(codeResult);
|
|
149
|
+
if (codeResult) {
|
|
150
|
+
monacoResult = protocol2monaco.asCodeAction(codeResult);
|
|
151
|
+
codeActions.set(monacoResult, codeResult);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return monacoResult;
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
provideDocumentFormattingEdits(model, options, _token) {
|
|
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));
|
|
161
|
+
if (codeResult) {
|
|
162
|
+
return codeResult.map(protocol2monaco.asTextEdit);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
provideDocumentRangeFormattingEdits(model, range, options, _token) {
|
|
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));
|
|
170
|
+
if (codeResult) {
|
|
171
|
+
return codeResult.map(protocol2monaco.asTextEdit);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
provideOnTypeFormattingEdits(model, position, ch, options, _token) {
|
|
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, {
|
|
179
|
+
ch: ch,
|
|
180
|
+
position: monaco2protocol.asPosition(position),
|
|
181
|
+
});
|
|
182
|
+
if (codeResult) {
|
|
183
|
+
return codeResult.map(protocol2monaco.asTextEdit);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
provideLinks(model, _token) {
|
|
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());
|
|
191
|
+
if (codeResult) {
|
|
192
|
+
return {
|
|
193
|
+
links: codeResult.map(protocol2monaco.asLink),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
provideCompletionItems(model, position, context, _token) {
|
|
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));
|
|
202
|
+
const fallbackRange = {
|
|
203
|
+
start: monaco2protocol.asPosition(position),
|
|
204
|
+
end: monaco2protocol.asPosition(position),
|
|
205
|
+
};
|
|
206
|
+
const monacoResult = protocol2monaco.asCompletionList(codeResult, fallbackRange);
|
|
207
|
+
for (let i = 0; i < codeResult.items.length; i++) {
|
|
208
|
+
completionItems.set(monacoResult.suggestions[i], codeResult.items[i]);
|
|
209
|
+
}
|
|
210
|
+
return monacoResult;
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
resolveCompletionItem(monacoItem, _token) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
let codeItem = completionItems.get(monacoItem);
|
|
216
|
+
if (codeItem) {
|
|
217
|
+
const worker = yield getLanguageService();
|
|
218
|
+
codeItem = yield worker.doCompletionResolve(codeItem);
|
|
219
|
+
const fallbackRange = 'replace' in monacoItem.range
|
|
220
|
+
? monaco2protocol.asRange(monacoItem.range.replace)
|
|
221
|
+
: monaco2protocol.asRange(monacoItem.range);
|
|
222
|
+
monacoItem = protocol2monaco.asCompletionItem(codeItem, fallbackRange);
|
|
223
|
+
completionItems.set(monacoItem, codeItem);
|
|
224
|
+
}
|
|
225
|
+
return monacoItem;
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
provideDocumentColors(model, _token) {
|
|
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());
|
|
232
|
+
if (codeResult) {
|
|
233
|
+
return codeResult.map(protocol2monaco.asColorInformation);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
provideColorPresentations(model, monacoResult) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const worker = yield getLanguageService(model.uri);
|
|
240
|
+
const codeResult = colorInfos.get(monacoResult);
|
|
241
|
+
if (codeResult) {
|
|
242
|
+
const codeColors = yield worker.getColorPresentations(model.uri.toString(), codeResult.color, {
|
|
243
|
+
start: monaco2protocol.asPosition(model.getPositionAt(0)),
|
|
244
|
+
end: monaco2protocol.asPosition(model.getPositionAt(model.getValueLength())),
|
|
245
|
+
});
|
|
246
|
+
if (codeColors) {
|
|
247
|
+
return codeColors.map(protocol2monaco.asColorPresentation);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
provideFoldingRanges(model, _context, _token) {
|
|
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());
|
|
256
|
+
if (codeResult) {
|
|
257
|
+
return codeResult.map(protocol2monaco.asFoldingRange);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
},
|
|
261
|
+
provideDeclaration(model, position, _token) {
|
|
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));
|
|
265
|
+
if (codeResult) {
|
|
266
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
provideSelectionRanges(model, positions, _token) {
|
|
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(), [
|
|
274
|
+
monaco2protocol.asPosition(position),
|
|
275
|
+
])));
|
|
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 : []; });
|
|
277
|
+
});
|
|
278
|
+
},
|
|
279
|
+
provideSignatureHelp(model, position, _token, _context) {
|
|
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));
|
|
283
|
+
if (codeResult) {
|
|
284
|
+
return {
|
|
285
|
+
value: protocol2monaco.asSignatureHelp(codeResult),
|
|
286
|
+
dispose: () => { },
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
provideRenameEdits(model, position, newName, _token) {
|
|
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);
|
|
295
|
+
if (codeResult) {
|
|
296
|
+
return protocol2monaco.asWorkspaceEdit(codeResult);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
provideReferences(model, position, _context, _token) {
|
|
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));
|
|
304
|
+
// TODO: can't show if only one result from libs
|
|
305
|
+
if (codeResult) {
|
|
306
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
provideInlayHints(model, range, _token) {
|
|
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));
|
|
314
|
+
if (codeResult) {
|
|
315
|
+
return {
|
|
316
|
+
hints: codeResult.map(protocol2monaco.asInlayHint),
|
|
317
|
+
dispose: () => { },
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
},
|
|
322
|
+
provideHover(model, position, _token) {
|
|
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));
|
|
326
|
+
if (codeResult) {
|
|
327
|
+
return protocol2monaco.asHover(codeResult);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
function getLanguageService(...uris) {
|
|
333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
yield worker.withSyncedResources(uris);
|
|
335
|
+
return worker.getProxy();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
exports.createLanguageFeaturesProvider = createLanguageFeaturesProvider;
|
|
341
|
+
//# sourceMappingURL=provider.js.map
|
package/out/worker.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Config } from '@volar/language-service';
|
|
2
|
+
import type * as monaco from 'monaco-editor-core';
|
|
3
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
export declare function createLanguageService(options: {
|
|
5
|
+
workerContext: monaco.worker.IWorkerContext<any>;
|
|
6
|
+
config: Config;
|
|
7
|
+
typescript?: {
|
|
8
|
+
module: typeof import('typescript/lib/tsserverlibrary');
|
|
9
|
+
compilerOptions: ts.CompilerOptions;
|
|
10
|
+
autoFetchTypes?: boolean | {
|
|
11
|
+
onFetchTypesFiles?(files: Record<string, string>): void;
|
|
12
|
+
cdn?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}): {};
|
package/out/worker.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createLanguageService = void 0;
|
|
12
|
+
const language_service_1 = require("@volar/language-service");
|
|
13
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
14
|
+
const autoFetchTypes_1 = require("./utils/autoFetchTypes");
|
|
15
|
+
function createLanguageService(options) {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
const ts = options.typescript ? options.typescript.module : undefined;
|
|
18
|
+
const config = (_a = options.config) !== null && _a !== void 0 ? _a : {};
|
|
19
|
+
const compilerOptions = (_c = (_b = options.typescript) === null || _b === void 0 ? void 0 : _b.compilerOptions) !== null && _c !== void 0 ? _c : {};
|
|
20
|
+
let autoFetchTypesCdn = 'https://unpkg.com/';
|
|
21
|
+
if (typeof ((_d = options.typescript) === null || _d === void 0 ? void 0 : _d.autoFetchTypes) === 'object' && options.typescript.autoFetchTypes.cdn) {
|
|
22
|
+
autoFetchTypesCdn = options.typescript.autoFetchTypes.cdn;
|
|
23
|
+
}
|
|
24
|
+
const autoTypeFetchHost = ((_e = options.typescript) === null || _e === void 0 ? void 0 : _e.autoFetchTypes) ? (0, autoFetchTypes_1.createAutoTypesFetchingHost)(autoFetchTypesCdn) : undefined;
|
|
25
|
+
let host = createLanguageServiceHost();
|
|
26
|
+
let languageService = (0, language_service_1.createLanguageService)(host, config, { rootUri: vscode_uri_1.URI.file('/') });
|
|
27
|
+
let webFilesNumOfLanguageService = (_f = autoTypeFetchHost === null || autoTypeFetchHost === void 0 ? void 0 : autoTypeFetchHost.files.size) !== null && _f !== void 0 ? _f : 0;
|
|
28
|
+
const syncedFiles = new Set();
|
|
29
|
+
class InnocentRabbit {
|
|
30
|
+
}
|
|
31
|
+
;
|
|
32
|
+
for (const api in languageService) {
|
|
33
|
+
const isFunction = typeof languageService[api] === 'function';
|
|
34
|
+
;
|
|
35
|
+
if (!isFunction) {
|
|
36
|
+
InnocentRabbit.prototype[api] = () => languageService[api];
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
InnocentRabbit.prototype[api] = (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _g;
|
|
41
|
+
if (!autoTypeFetchHost) {
|
|
42
|
+
return languageService[api](...args);
|
|
43
|
+
}
|
|
44
|
+
let shouldSync = false;
|
|
45
|
+
let webFilesNumOfThisCall = autoTypeFetchHost.files.size;
|
|
46
|
+
let result = yield languageService[api](...args);
|
|
47
|
+
yield autoTypeFetchHost.wait();
|
|
48
|
+
while (autoTypeFetchHost.files.size > webFilesNumOfThisCall) {
|
|
49
|
+
shouldSync = true;
|
|
50
|
+
webFilesNumOfThisCall = autoTypeFetchHost.files.size;
|
|
51
|
+
if (autoTypeFetchHost.files.size > webFilesNumOfLanguageService) {
|
|
52
|
+
webFilesNumOfLanguageService = autoTypeFetchHost.files.size;
|
|
53
|
+
languageService.dispose();
|
|
54
|
+
languageService = (0, language_service_1.createLanguageService)(host, config, { rootUri: vscode_uri_1.URI.file('/') });
|
|
55
|
+
}
|
|
56
|
+
result = yield languageService[api](...args);
|
|
57
|
+
yield autoTypeFetchHost.wait();
|
|
58
|
+
}
|
|
59
|
+
if (shouldSync && typeof ((_g = options.typescript) === null || _g === void 0 ? void 0 : _g.autoFetchTypes) === 'object' && options.typescript.autoFetchTypes.onFetchTypesFiles) {
|
|
60
|
+
const files = autoTypeFetchHost.files;
|
|
61
|
+
const syncFiles = {};
|
|
62
|
+
for (const [fileName, text] of files) {
|
|
63
|
+
if (!syncedFiles.has(fileName) && text !== undefined) {
|
|
64
|
+
syncFiles[fileName] = text;
|
|
65
|
+
syncedFiles.add(fileName);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
options.typescript.autoFetchTypes.onFetchTypesFiles(syncFiles);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return new InnocentRabbit();
|
|
74
|
+
function createLanguageServiceHost() {
|
|
75
|
+
let projectVersion = 0;
|
|
76
|
+
const modelSnapshot = new WeakMap();
|
|
77
|
+
const webFileSnapshot = new Map();
|
|
78
|
+
const modelVersions = new Map();
|
|
79
|
+
const host = {
|
|
80
|
+
getProjectVersion() {
|
|
81
|
+
const models = options.workerContext.getMirrorModels();
|
|
82
|
+
if (modelVersions.size === options.workerContext.getMirrorModels().length) {
|
|
83
|
+
if (models.every(model => modelVersions.get(model) === model.version)) {
|
|
84
|
+
return projectVersion.toString();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
modelVersions.clear();
|
|
88
|
+
for (const model of options.workerContext.getMirrorModels()) {
|
|
89
|
+
modelVersions.set(model, model.version);
|
|
90
|
+
}
|
|
91
|
+
projectVersion++;
|
|
92
|
+
return projectVersion.toString();
|
|
93
|
+
},
|
|
94
|
+
getScriptFileNames() {
|
|
95
|
+
const models = options.workerContext.getMirrorModels();
|
|
96
|
+
return models.map(model => model.uri.fsPath);
|
|
97
|
+
},
|
|
98
|
+
getScriptVersion(fileName) {
|
|
99
|
+
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
100
|
+
if (model) {
|
|
101
|
+
return model.version.toString();
|
|
102
|
+
}
|
|
103
|
+
if (autoTypeFetchHost) {
|
|
104
|
+
const dts = autoTypeFetchHost.readFile(fileName);
|
|
105
|
+
if (dts) {
|
|
106
|
+
return dts.length.toString();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return '';
|
|
110
|
+
},
|
|
111
|
+
getScriptSnapshot(fileName) {
|
|
112
|
+
var _a;
|
|
113
|
+
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
114
|
+
if (model) {
|
|
115
|
+
const cache = modelSnapshot.get(model);
|
|
116
|
+
if (cache && cache[0] === model.version) {
|
|
117
|
+
return cache[1];
|
|
118
|
+
}
|
|
119
|
+
const text = model.getValue();
|
|
120
|
+
modelSnapshot.set(model, [model.version, {
|
|
121
|
+
getText: (start, end) => text.substring(start, end),
|
|
122
|
+
getLength: () => text.length,
|
|
123
|
+
getChangeRange: () => undefined,
|
|
124
|
+
}]);
|
|
125
|
+
return (_a = modelSnapshot.get(model)) === null || _a === void 0 ? void 0 : _a[1];
|
|
126
|
+
}
|
|
127
|
+
if (webFileSnapshot.has(fileName)) {
|
|
128
|
+
return webFileSnapshot.get(fileName);
|
|
129
|
+
}
|
|
130
|
+
if (autoTypeFetchHost) {
|
|
131
|
+
const webFileText = autoTypeFetchHost.readFile(fileName);
|
|
132
|
+
if (webFileText !== undefined) {
|
|
133
|
+
webFileSnapshot.set(fileName, {
|
|
134
|
+
getText: (start, end) => webFileText.substring(start, end),
|
|
135
|
+
getLength: () => webFileText.length,
|
|
136
|
+
getChangeRange: () => undefined,
|
|
137
|
+
});
|
|
138
|
+
return webFileSnapshot.get(fileName);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
getCompilationSettings() {
|
|
143
|
+
return compilerOptions;
|
|
144
|
+
},
|
|
145
|
+
getCurrentDirectory() {
|
|
146
|
+
return '/';
|
|
147
|
+
},
|
|
148
|
+
getDefaultLibFileName(options) {
|
|
149
|
+
if (ts) {
|
|
150
|
+
return '/node_modules/typescript/lib/' + ts.getDefaultLibFileName(options);
|
|
151
|
+
}
|
|
152
|
+
return '';
|
|
153
|
+
},
|
|
154
|
+
readFile(fileName) {
|
|
155
|
+
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
156
|
+
if (model) {
|
|
157
|
+
return model.getValue();
|
|
158
|
+
}
|
|
159
|
+
if (autoTypeFetchHost) {
|
|
160
|
+
return autoTypeFetchHost.readFile(fileName);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
fileExists(fileName) {
|
|
164
|
+
const model = options.workerContext.getMirrorModels().find(model => model.uri.fsPath === fileName);
|
|
165
|
+
if (model) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
if (autoTypeFetchHost) {
|
|
169
|
+
return autoTypeFetchHost.fileExists(fileName);
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
},
|
|
173
|
+
getTypeScriptModule: ts ? (() => ts) : undefined,
|
|
174
|
+
};
|
|
175
|
+
return host;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.createLanguageService = createLanguageService;
|
|
179
|
+
//# sourceMappingURL=worker.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volar/monaco",
|
|
3
|
+
"version": "1.3.0-alpha.0",
|
|
4
|
+
"main": "out/index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"*.js",
|
|
8
|
+
"*.d.ts",
|
|
9
|
+
"out/**/*.js",
|
|
10
|
+
"out/**/*.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/volarjs/volar.js.git",
|
|
15
|
+
"directory": "packages/monaco"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@volar/language-service": "1.3.0-alpha.0",
|
|
19
|
+
"axios": "^1.3.4",
|
|
20
|
+
"monaco-editor-core": "^0.36.0",
|
|
21
|
+
"vscode-languageserver-protocol": "^3.17.3",
|
|
22
|
+
"vscode-uri": "^3.0.7"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "7582403cc521d33f642183a32da44fb1f64e65ef"
|
|
25
|
+
}
|
package/worker.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './out/worker';
|
package/worker.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./out/worker');
|