@volar/monaco 1.4.0-alpha.0 → 1.4.0-alpha.10
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 +55 -75
- package/out/index.js +1 -0
- package/out/languages.js +30 -38
- package/out/utils/markers.js +1 -0
- package/out/utils/monaco2protocol.js +1 -0
- package/out/utils/protocol2monaco.js +29 -23
- package/out/utils/provider.js +311 -352
- package/out/worker.d.ts +1 -1
- package/out/worker.js +42 -68
- package/package.json +3 -4
package/out/utils/provider.js
CHANGED
|
@@ -1,362 +1,321 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
"use strict";
|
|
10
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
3
|
exports.createLanguageFeaturesProvider = void 0;
|
|
12
4
|
const language_service_1 = require("@volar/language-service");
|
|
13
5
|
const markers_1 = require("./markers");
|
|
14
6
|
const monaco2protocol = require("./monaco2protocol");
|
|
15
7
|
const protocol2monaco = require("./protocol2monaco");
|
|
16
|
-
function createLanguageFeaturesProvider(worker, getSyncUris) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
8
|
+
async function createLanguageFeaturesProvider(worker, getSyncUris) {
|
|
9
|
+
const completionItems = new WeakMap();
|
|
10
|
+
const codeLens = new WeakMap();
|
|
11
|
+
const codeActions = new WeakMap();
|
|
12
|
+
const colorInfos = new WeakMap();
|
|
13
|
+
const documentLinks = new WeakMap();
|
|
14
|
+
const inlayHints = new WeakMap();
|
|
15
|
+
const languageService = await worker.getProxy();
|
|
16
|
+
return {
|
|
17
|
+
triggerCharacters: await languageService.triggerCharacters(),
|
|
18
|
+
autoFormatTriggerCharacters: await languageService.triggerCharacters(),
|
|
19
|
+
signatureHelpTriggerCharacters: await languageService.triggerCharacters(),
|
|
20
|
+
signatureHelpRetriggerCharacters: await languageService.triggerCharacters(),
|
|
21
|
+
getLegend() {
|
|
22
|
+
return language_service_1.standardSemanticTokensLegend;
|
|
23
|
+
},
|
|
24
|
+
async provideDocumentSemanticTokens(model, _lastResultId) {
|
|
25
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
26
|
+
const codeResult = await languageService.getSemanticTokens(model.uri.toString(), undefined, language_service_1.standardSemanticTokensLegend);
|
|
27
|
+
if (codeResult) {
|
|
28
|
+
return {
|
|
29
|
+
resultId: codeResult.resultId,
|
|
30
|
+
data: Uint32Array.from(codeResult.data),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
async provideDocumentRangeSemanticTokens(model, range) {
|
|
35
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
36
|
+
const codeResult = await languageService.getSemanticTokens(model.uri.toString(), monaco2protocol.asRange(range), language_service_1.standardSemanticTokensLegend);
|
|
37
|
+
if (codeResult) {
|
|
38
|
+
return {
|
|
39
|
+
resultId: codeResult.resultId,
|
|
40
|
+
data: Uint32Array.from(codeResult.data),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
releaseDocumentSemanticTokens() { },
|
|
45
|
+
async provideDocumentSymbols(model) {
|
|
46
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
47
|
+
const codeResult = await languageService.findDocumentSymbols(model.uri.toString());
|
|
48
|
+
if (codeResult) {
|
|
49
|
+
return codeResult.map(protocol2monaco.asDocumentSymbol);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
async provideDocumentHighlights(model, position) {
|
|
53
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
54
|
+
const codeResult = await languageService.findDocumentHighlights(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
55
|
+
if (codeResult) {
|
|
56
|
+
return codeResult.map(protocol2monaco.asDocumentHighlight);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
async provideLinkedEditingRanges(model, position) {
|
|
60
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
61
|
+
const codeResult = await languageService.findLinkedEditingRanges(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
62
|
+
if (codeResult) {
|
|
63
|
+
return {
|
|
64
|
+
ranges: codeResult.ranges.map(protocol2monaco.asRange),
|
|
65
|
+
wordPattern: codeResult.wordPattern
|
|
66
|
+
? new RegExp(codeResult.wordPattern)
|
|
67
|
+
: undefined,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
async provideDefinition(model, position) {
|
|
72
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
73
|
+
const codeResult = await languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
74
|
+
if (codeResult) {
|
|
75
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
async provideImplementation(model, position) {
|
|
79
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
80
|
+
const codeResult = await languageService.findImplementations(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
81
|
+
if (codeResult) {
|
|
82
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
async provideTypeDefinition(model, position) {
|
|
86
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
87
|
+
const codeResult = await languageService.findTypeDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
88
|
+
if (codeResult) {
|
|
89
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
async provideCodeLenses(model) {
|
|
93
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
94
|
+
const codeResult = await languageService.doCodeLens(model.uri.toString());
|
|
95
|
+
if (codeResult) {
|
|
96
|
+
const monacoResult = codeResult.map(protocol2monaco.asCodeLens);
|
|
97
|
+
for (let i = 0; i < monacoResult.length; i++) {
|
|
98
|
+
codeLens.set(monacoResult[i], codeResult[i]);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
lenses: monacoResult,
|
|
102
|
+
dispose: () => { },
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
async resolveCodeLens(_, monacoResult) {
|
|
107
|
+
let codeResult = codeLens.get(monacoResult);
|
|
108
|
+
if (codeResult) {
|
|
109
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
110
|
+
codeResult = await languageService.doCodeLensResolve(codeResult);
|
|
111
|
+
if (codeResult) {
|
|
112
|
+
monacoResult = protocol2monaco.asCodeLens(codeResult);
|
|
113
|
+
codeLens.set(monacoResult, codeResult);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return monacoResult;
|
|
117
|
+
},
|
|
118
|
+
async provideCodeActions(model, range, context) {
|
|
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 languageService = await worker.withSyncedResources(getSyncUris());
|
|
127
|
+
const codeResult = await languageService.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
|
+
async resolveCodeAction(monacoResult) {
|
|
143
|
+
let codeResult = codeActions.get(monacoResult);
|
|
144
|
+
if (codeResult) {
|
|
145
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
146
|
+
codeResult = await languageService.doCodeActionResolve(codeResult);
|
|
147
|
+
if (codeResult) {
|
|
148
|
+
monacoResult = protocol2monaco.asCodeAction(codeResult);
|
|
149
|
+
codeActions.set(monacoResult, codeResult);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return monacoResult;
|
|
153
|
+
},
|
|
154
|
+
async provideDocumentFormattingEdits(model, options) {
|
|
155
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
156
|
+
const codeResult = await languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, undefined);
|
|
157
|
+
if (codeResult) {
|
|
158
|
+
return codeResult.map(protocol2monaco.asTextEdit);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
async provideDocumentRangeFormattingEdits(model, range, options) {
|
|
162
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
163
|
+
const codeResult = await languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), monaco2protocol.asRange(range), undefined);
|
|
164
|
+
if (codeResult) {
|
|
165
|
+
return codeResult.map(protocol2monaco.asTextEdit);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
async provideOnTypeFormattingEdits(model, position, ch, options) {
|
|
169
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
170
|
+
const codeResult = await languageService.format(model.uri.toString(), monaco2protocol.asFormattingOptions(options), undefined, {
|
|
171
|
+
ch: ch,
|
|
172
|
+
position: monaco2protocol.asPosition(position),
|
|
173
|
+
});
|
|
174
|
+
if (codeResult) {
|
|
175
|
+
return codeResult.map(protocol2monaco.asTextEdit);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
async provideLinks(model) {
|
|
179
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
180
|
+
const codeResult = await languageService.findDocumentLinks(model.uri.toString());
|
|
181
|
+
if (codeResult) {
|
|
182
|
+
return {
|
|
183
|
+
links: codeResult.map(link => {
|
|
184
|
+
const monacoLink = protocol2monaco.asLink(link);
|
|
185
|
+
documentLinks.set(monacoLink, link);
|
|
186
|
+
return monacoLink;
|
|
187
|
+
}),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
async resolveLink(link) {
|
|
192
|
+
let codeResult = documentLinks.get(link);
|
|
193
|
+
if (codeResult) {
|
|
194
|
+
codeResult = await languageService.doDocumentLinkResolve(codeResult);
|
|
195
|
+
return protocol2monaco.asLink(codeResult);
|
|
196
|
+
}
|
|
197
|
+
return link;
|
|
198
|
+
},
|
|
199
|
+
async provideCompletionItems(model, position, context) {
|
|
200
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
201
|
+
const codeResult = await languageService.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
|
+
async resolveCompletionItem(monacoItem) {
|
|
213
|
+
let codeItem = completionItems.get(monacoItem);
|
|
214
|
+
if (codeItem) {
|
|
215
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
216
|
+
codeItem = await languageService.doCompletionResolve(codeItem);
|
|
217
|
+
const fallbackRange = 'replace' in monacoItem.range
|
|
218
|
+
? monaco2protocol.asRange(monacoItem.range.replace)
|
|
219
|
+
: monaco2protocol.asRange(monacoItem.range);
|
|
220
|
+
monacoItem = protocol2monaco.asCompletionItem(codeItem, fallbackRange);
|
|
221
|
+
completionItems.set(monacoItem, codeItem);
|
|
222
|
+
}
|
|
223
|
+
return monacoItem;
|
|
224
|
+
},
|
|
225
|
+
async provideDocumentColors(model) {
|
|
226
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
227
|
+
const codeResult = await languageService.findDocumentColors(model.uri.toString());
|
|
228
|
+
if (codeResult) {
|
|
229
|
+
return codeResult.map(protocol2monaco.asColorInformation);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
async provideColorPresentations(model, monacoResult) {
|
|
233
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
234
|
+
const codeResult = colorInfos.get(monacoResult);
|
|
235
|
+
if (codeResult) {
|
|
236
|
+
const codeColors = await languageService.getColorPresentations(model.uri.toString(), codeResult.color, {
|
|
237
|
+
start: monaco2protocol.asPosition(model.getPositionAt(0)),
|
|
238
|
+
end: monaco2protocol.asPosition(model.getPositionAt(model.getValueLength())),
|
|
41
239
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
});
|
|
240
|
+
if (codeColors) {
|
|
241
|
+
return codeColors.map(protocol2monaco.asColorPresentation);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
async provideFoldingRanges(model, _context) {
|
|
246
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
247
|
+
const codeResult = await languageService.getFoldingRanges(model.uri.toString());
|
|
248
|
+
if (codeResult) {
|
|
249
|
+
return codeResult.map(protocol2monaco.asFoldingRange);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
async provideDeclaration(model, position) {
|
|
253
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
254
|
+
const codeResult = await languageService.findDefinition(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
255
|
+
if (codeResult) {
|
|
256
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
async provideSelectionRanges(model, positions) {
|
|
260
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
261
|
+
const codeResults = await Promise.all(positions.map((position) => languageService.getSelectionRanges(model.uri.toString(), [monaco2protocol.asPosition(position)])));
|
|
262
|
+
return codeResults.map((codeResult) => codeResult?.map(protocol2monaco.asSelectionRange) ?? []);
|
|
263
|
+
},
|
|
264
|
+
async provideSignatureHelp(model, position, _token, context) {
|
|
265
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
266
|
+
const codeResult = await languageService.getSignatureHelp(model.uri.toString(), monaco2protocol.asPosition(position), monaco2protocol.asSignatureHelpContext(context));
|
|
267
|
+
if (codeResult) {
|
|
268
|
+
return {
|
|
269
|
+
value: protocol2monaco.asSignatureHelp(codeResult),
|
|
270
|
+
dispose: () => { },
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
async provideRenameEdits(model, position, newName) {
|
|
275
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
276
|
+
const codeResult = await languageService.doRename(model.uri.toString(), monaco2protocol.asPosition(position), newName);
|
|
277
|
+
if (codeResult) {
|
|
278
|
+
return protocol2monaco.asWorkspaceEdit(codeResult);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
async provideReferences(model, position, _context) {
|
|
282
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
283
|
+
const codeResult = await languageService.findReferences(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
284
|
+
if (codeResult) {
|
|
285
|
+
return codeResult.map(protocol2monaco.asLocation);
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
async provideInlayHints(model, range) {
|
|
289
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
290
|
+
const codeResult = await languageService.getInlayHints(model.uri.toString(), monaco2protocol.asRange(range));
|
|
291
|
+
if (codeResult) {
|
|
292
|
+
return {
|
|
293
|
+
hints: codeResult.map(hint => {
|
|
294
|
+
const monacoHint = protocol2monaco.asInlayHint(hint);
|
|
295
|
+
inlayHints.set(monacoHint, hint);
|
|
296
|
+
return monacoHint;
|
|
297
|
+
}),
|
|
298
|
+
dispose: () => { },
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
async resolveInlayHint(hint) {
|
|
303
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
304
|
+
const codeHint = inlayHints.get(hint);
|
|
305
|
+
if (codeHint) {
|
|
306
|
+
const resolvedCodeHint = await languageService.doInlayHintResolve(codeHint);
|
|
307
|
+
return protocol2monaco.asInlayHint(resolvedCodeHint);
|
|
308
|
+
}
|
|
309
|
+
return hint;
|
|
310
|
+
},
|
|
311
|
+
async provideHover(model, position) {
|
|
312
|
+
const languageService = await worker.withSyncedResources(getSyncUris());
|
|
313
|
+
const codeResult = await languageService.doHover(model.uri.toString(), monaco2protocol.asPosition(position));
|
|
314
|
+
if (codeResult) {
|
|
315
|
+
return protocol2monaco.asHover(codeResult);
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
};
|
|
360
319
|
}
|
|
361
320
|
exports.createLanguageFeaturesProvider = createLanguageFeaturesProvider;
|
|
362
321
|
//# sourceMappingURL=provider.js.map
|