@volar/monaco 1.4.0-alpha.0 → 1.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/editor.js +58 -74
- package/out/languages.js +27 -38
- package/out/utils/protocol2monaco.js +28 -23
- package/out/utils/provider.js +284 -353
- package/out/worker.d.ts +1 -1
- package/out/worker.js +38 -66
- package/package.json +3 -4
package/out/editor.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
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
3
|
const language_service_1 = require("@volar/language-service");
|
|
@@ -34,11 +25,10 @@ var editor;
|
|
|
34
25
|
}
|
|
35
26
|
return { dispose: () => disposables.forEach((d) => d.dispose()) };
|
|
36
27
|
function stopHostingMarkers(model) {
|
|
37
|
-
var _a;
|
|
38
28
|
editor.setModelMarkers(model, markersOwn, []);
|
|
39
29
|
const key = model.uri.toString();
|
|
40
30
|
if (listener.has(key)) {
|
|
41
|
-
|
|
31
|
+
listener.get(key)?.dispose();
|
|
42
32
|
listener.delete(key);
|
|
43
33
|
}
|
|
44
34
|
}
|
|
@@ -68,29 +58,27 @@ var editor;
|
|
|
68
58
|
});
|
|
69
59
|
doValidation(model);
|
|
70
60
|
}
|
|
71
|
-
function doValidation(model) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return marker;
|
|
91
|
-
});
|
|
92
|
-
editor.setModelMarkers(model, markersOwn, result);
|
|
61
|
+
async function doValidation(model) {
|
|
62
|
+
if (model.isDisposed()) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!model.isAttachedToEditor()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const version = model.getVersionId();
|
|
69
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
70
|
+
const diagnostics = await languageService.doValidation(model.uri.toString(), {
|
|
71
|
+
get isCancellationRequested() {
|
|
72
|
+
return model.getVersionId() !== version;
|
|
73
|
+
},
|
|
74
|
+
onCancellationRequested: language_service_1.Event.None,
|
|
75
|
+
}, 'all');
|
|
76
|
+
const result = diagnostics.map(error => {
|
|
77
|
+
const marker = protocol2monaco.asMarkerData(error);
|
|
78
|
+
markers_1.markers.set(marker, error);
|
|
79
|
+
return marker;
|
|
93
80
|
});
|
|
81
|
+
editor.setModelMarkers(model, markersOwn, result);
|
|
94
82
|
}
|
|
95
83
|
}
|
|
96
84
|
editor_1.activateMarkers = activateMarkers;
|
|
@@ -114,9 +102,8 @@ var editor;
|
|
|
114
102
|
}
|
|
115
103
|
return { dispose: () => disposables.forEach((d) => d.dispose()) };
|
|
116
104
|
function stopHostingAutoInsertion(model) {
|
|
117
|
-
var _a;
|
|
118
105
|
if (listener.has(model)) {
|
|
119
|
-
|
|
106
|
+
listener.get(model)?.dispose();
|
|
120
107
|
listener.delete(model);
|
|
121
108
|
}
|
|
122
109
|
}
|
|
@@ -138,47 +125,44 @@ var editor;
|
|
|
138
125
|
doAutoInsert(model, lastChange);
|
|
139
126
|
}));
|
|
140
127
|
}
|
|
141
|
-
function doAutoInsert(model, lastChange) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
(()
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
128
|
+
async function doAutoInsert(model, lastChange) {
|
|
129
|
+
if (timeout) {
|
|
130
|
+
clearTimeout(timeout);
|
|
131
|
+
timeout = undefined;
|
|
132
|
+
}
|
|
133
|
+
const version = model.getVersionId();
|
|
134
|
+
timeout = setTimeout(() => {
|
|
135
|
+
(async () => {
|
|
136
|
+
if (model.getVersionId() !== version) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const position = new monaco_editor_core_1.Position(lastChange.range.startLineNumber, lastChange.range.startColumn + lastChange.text.length);
|
|
140
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
141
|
+
const edit = await languageService.doAutoInsert(model.uri.toString(), monaco2protocol.asPosition(position), {
|
|
142
|
+
lastChange: {
|
|
143
|
+
range: monaco2protocol.asRange(lastChange.range),
|
|
144
|
+
rangeLength: lastChange.rangeLength,
|
|
145
|
+
text: lastChange.text,
|
|
146
|
+
rangeOffset: lastChange.rangeOffset,
|
|
147
|
+
},
|
|
148
|
+
}, {
|
|
149
|
+
get isCancellationRequested() {
|
|
150
|
+
return model.getVersionId() !== version;
|
|
151
|
+
},
|
|
152
|
+
onCancellationRequested: language_service_1.Event.None,
|
|
153
|
+
});
|
|
154
|
+
const codeEditor = editor.getEditors().find((e) => e.getModel() === model);
|
|
155
|
+
if (codeEditor && edit && model.getVersionId() === version) {
|
|
156
|
+
if (typeof edit === 'string') {
|
|
157
|
+
codeEditor?.getContribution('snippetController2')?.insert(edit);
|
|
153
158
|
}
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
}
|
|
159
|
+
else {
|
|
160
|
+
model.pushEditOperations([], [protocol2monaco.asTextEdit(edit)], () => []);
|
|
177
161
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
162
|
+
}
|
|
163
|
+
})();
|
|
164
|
+
timeout = undefined;
|
|
165
|
+
}, 100);
|
|
182
166
|
}
|
|
183
167
|
}
|
|
184
168
|
editor_1.activateAutoInsertion = activateAutoInsertion;
|
package/out/languages.js
CHANGED
|
@@ -1,46 +1,35 @@
|
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
];
|
|
32
|
+
return { dispose: () => disposables.forEach((d) => d.dispose()) };
|
|
44
33
|
}
|
|
45
34
|
languages_1.registerProvides = registerProvides;
|
|
46
35
|
})(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:
|
|
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:
|
|
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:
|
|
167
|
-
activeParameter:
|
|
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
|
-
|
|
191
|
-
|
|
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
|
|
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:
|
|
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:
|
|
255
|
-
ignoreIfExists:
|
|
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:
|
|
265
|
-
ignoreIfExists:
|
|
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:
|
|
274
|
-
ignoreIfNotExists:
|
|
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:
|
|
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:
|
|
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:
|
|
442
|
+
value: item.kind ?? '',
|
|
438
443
|
},
|
|
439
444
|
};
|
|
440
445
|
}
|