@volar/language-server 1.4.0-alpha.0 → 1.4.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/browser/fileSystems.js +82 -102
- package/out/browser/index.js +10 -23
- package/out/browser/typescript/core.js +1 -1
- package/out/browser/typescript/corePublic.js +2 -2
- package/out/common/cancellationPipe.js +1 -1
- package/out/common/configurationHost.js +12 -28
- package/out/common/documents.js +2 -3
- package/out/common/features/customFeatures.js +34 -47
- package/out/common/features/languageFeatures.js +127 -152
- package/out/common/project.d.ts +62 -62
- package/out/common/project.js +211 -227
- package/out/common/server.js +51 -65
- package/out/common/utils/inferredCompilerOptions.js +57 -61
- package/out/common/utils/registerFeatures.js +8 -8
- package/out/common/utils/serverConfig.js +2 -2
- package/out/common/utils/uriMap.js +1 -1
- package/out/common/workspace.d.ts +558 -558
- package/out/common/workspace.js +164 -193
- package/out/common/workspaces.d.ts +682 -682
- package/out/common/workspaces.js +81 -107
- package/out/node/fileSystem.js +4 -14
- package/out/node/index.js +7 -18
- package/package.json +4 -4
|
@@ -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.sleep = exports.register = void 0;
|
|
12
3
|
const embedded = require("@volar/language-service");
|
|
@@ -19,73 +10,71 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
19
10
|
let lastCodeLensLs;
|
|
20
11
|
let lastCodeActionLs;
|
|
21
12
|
let lastCallHierarchyLs;
|
|
22
|
-
connection.onDocumentFormatting((params, token) =>
|
|
13
|
+
connection.onDocumentFormatting(async (params, token) => {
|
|
23
14
|
return worker(params.textDocument.uri, token, service => {
|
|
24
15
|
return service.format(params.textDocument.uri, params.options, undefined, undefined, token);
|
|
25
16
|
});
|
|
26
|
-
})
|
|
27
|
-
connection.onDocumentRangeFormatting((params, token) =>
|
|
17
|
+
});
|
|
18
|
+
connection.onDocumentRangeFormatting(async (params, token) => {
|
|
28
19
|
return worker(params.textDocument.uri, token, service => {
|
|
29
20
|
return service.format(params.textDocument.uri, params.options, params.range, undefined, token);
|
|
30
21
|
});
|
|
31
|
-
})
|
|
32
|
-
connection.onDocumentOnTypeFormatting((params, token) =>
|
|
22
|
+
});
|
|
23
|
+
connection.onDocumentOnTypeFormatting(async (params, token) => {
|
|
33
24
|
return worker(params.textDocument.uri, token, service => {
|
|
34
25
|
return service.format(params.textDocument.uri, params.options, undefined, params, token);
|
|
35
26
|
});
|
|
36
|
-
})
|
|
37
|
-
connection.onSelectionRanges((params, token) =>
|
|
27
|
+
});
|
|
28
|
+
connection.onSelectionRanges(async (params, token) => {
|
|
38
29
|
return worker(params.textDocument.uri, token, service => {
|
|
39
30
|
return service.getSelectionRanges(params.textDocument.uri, params.positions, token);
|
|
40
31
|
});
|
|
41
|
-
})
|
|
42
|
-
connection.onFoldingRanges((params, token) =>
|
|
32
|
+
});
|
|
33
|
+
connection.onFoldingRanges(async (params, token) => {
|
|
43
34
|
return worker(params.textDocument.uri, token, service => {
|
|
44
35
|
return service.getFoldingRanges(params.textDocument.uri, token);
|
|
45
36
|
});
|
|
46
|
-
})
|
|
47
|
-
connection.languages.onLinkedEditingRange((params, token) =>
|
|
37
|
+
});
|
|
38
|
+
connection.languages.onLinkedEditingRange(async (params, token) => {
|
|
48
39
|
return worker(params.textDocument.uri, token, service => {
|
|
49
40
|
return service.findLinkedEditingRanges(params.textDocument.uri, params.position, token);
|
|
50
41
|
});
|
|
51
|
-
})
|
|
52
|
-
connection.onDocumentSymbol((params, token) =>
|
|
42
|
+
});
|
|
43
|
+
connection.onDocumentSymbol(async (params, token) => {
|
|
53
44
|
return worker(params.textDocument.uri, token, service => {
|
|
54
45
|
return service.findDocumentSymbols(params.textDocument.uri, token);
|
|
55
46
|
});
|
|
56
|
-
})
|
|
57
|
-
connection.onDocumentColor((params, token) =>
|
|
47
|
+
});
|
|
48
|
+
connection.onDocumentColor(async (params, token) => {
|
|
58
49
|
return worker(params.textDocument.uri, token, service => {
|
|
59
50
|
return service.findDocumentColors(params.textDocument.uri, token);
|
|
60
51
|
});
|
|
61
|
-
})
|
|
62
|
-
connection.onColorPresentation((params, token) =>
|
|
52
|
+
});
|
|
53
|
+
connection.onColorPresentation(async (params, token) => {
|
|
63
54
|
return worker(params.textDocument.uri, token, service => {
|
|
64
55
|
return service.getColorPresentations(params.textDocument.uri, params.color, params.range, token);
|
|
65
56
|
});
|
|
66
|
-
})
|
|
67
|
-
connection.onCompletion((params, token) =>
|
|
68
|
-
return worker(params.textDocument.uri, token, (service) =>
|
|
69
|
-
var _a;
|
|
57
|
+
});
|
|
58
|
+
connection.onCompletion(async (params, token) => {
|
|
59
|
+
return worker(params.textDocument.uri, token, async (service) => {
|
|
70
60
|
lastCompleteUri = params.textDocument.uri;
|
|
71
61
|
lastCompleteLs = service;
|
|
72
|
-
const document =
|
|
73
|
-
const list =
|
|
62
|
+
const document = documents.data.uriGet(params.textDocument.uri)?.getDocument();
|
|
63
|
+
const list = await service.doComplete(params.textDocument.uri, params.position, params.context, token);
|
|
74
64
|
for (const item of list.items) {
|
|
75
65
|
fixTextEdit(item);
|
|
76
66
|
}
|
|
77
67
|
if (!initOptions.fullCompletionList && document) {
|
|
78
68
|
list.items = list.items.filter(item => {
|
|
79
|
-
var _a, _b;
|
|
80
69
|
const range = item.textEdit ? (vscode.InsertReplaceEdit.is(item.textEdit)
|
|
81
70
|
? item.textEdit.replace
|
|
82
|
-
: item.textEdit.range) :
|
|
71
|
+
: item.textEdit.range) : list.itemDefaults?.editRange ? (vscode.Range.is(list.itemDefaults.editRange)
|
|
83
72
|
? list.itemDefaults.editRange
|
|
84
73
|
: list.itemDefaults.editRange.replace) : undefined;
|
|
85
74
|
if (range) {
|
|
86
75
|
const sourceText = document.getText(range).toLowerCase();
|
|
87
76
|
if (sourceText.trim()) {
|
|
88
|
-
let filterText = (
|
|
77
|
+
let filterText = (item.filterText ?? item.label).toLowerCase();
|
|
89
78
|
for (const char of sourceText) {
|
|
90
79
|
const index = filterText.indexOf(char);
|
|
91
80
|
if (index === -1) {
|
|
@@ -99,50 +88,49 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
99
88
|
});
|
|
100
89
|
}
|
|
101
90
|
return list;
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
connection.onCompletionResolve((item, token) =>
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
connection.onCompletionResolve(async (item, token) => {
|
|
105
94
|
if (lastCompleteUri && lastCompleteLs) {
|
|
106
|
-
item =
|
|
95
|
+
item = await lastCompleteLs.doCompletionResolve(item, token);
|
|
107
96
|
fixTextEdit(item);
|
|
108
97
|
}
|
|
109
98
|
return item;
|
|
110
|
-
})
|
|
111
|
-
connection.onHover((params, token) =>
|
|
99
|
+
});
|
|
100
|
+
connection.onHover(async (params, token) => {
|
|
112
101
|
return worker(params.textDocument.uri, token, service => {
|
|
113
102
|
return service.doHover(params.textDocument.uri, params.position, token);
|
|
114
103
|
});
|
|
115
|
-
})
|
|
116
|
-
connection.onSignatureHelp((params, token) =>
|
|
104
|
+
});
|
|
105
|
+
connection.onSignatureHelp(async (params, token) => {
|
|
117
106
|
return worker(params.textDocument.uri, token, service => {
|
|
118
107
|
return service.getSignatureHelp(params.textDocument.uri, params.position, params.context, token);
|
|
119
108
|
});
|
|
120
|
-
})
|
|
121
|
-
connection.onPrepareRename((params, token) =>
|
|
109
|
+
});
|
|
110
|
+
connection.onPrepareRename(async (params, token) => {
|
|
122
111
|
return worker(params.textDocument.uri, token, service => {
|
|
123
112
|
return service.prepareRename(params.textDocument.uri, params.position, token);
|
|
124
113
|
});
|
|
125
|
-
})
|
|
126
|
-
connection.onRenameRequest((params, token) =>
|
|
114
|
+
});
|
|
115
|
+
connection.onRenameRequest(async (params, token) => {
|
|
127
116
|
return worker(params.textDocument.uri, token, service => {
|
|
128
117
|
return service.doRename(params.textDocument.uri, params.position, params.newName, token);
|
|
129
118
|
});
|
|
130
|
-
})
|
|
131
|
-
connection.onCodeLens((params, token) =>
|
|
132
|
-
return worker(params.textDocument.uri, token, (service) =>
|
|
119
|
+
});
|
|
120
|
+
connection.onCodeLens(async (params, token) => {
|
|
121
|
+
return worker(params.textDocument.uri, token, async (service) => {
|
|
133
122
|
lastCodeLensLs = service;
|
|
134
123
|
return service.doCodeLens(params.textDocument.uri, token);
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
connection.onCodeLensResolve((codeLens, token) =>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
connection.onExecuteCommand((params) => __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
connection.onCodeLensResolve(async (codeLens, token) => {
|
|
127
|
+
return await lastCodeLensLs?.doCodeLensResolve(codeLens, token) ?? codeLens;
|
|
128
|
+
});
|
|
129
|
+
connection.onExecuteCommand(async (params) => {
|
|
142
130
|
if (params.command === embedded.showReferencesCommand
|
|
143
131
|
&& params.arguments) {
|
|
144
132
|
const args = params.arguments;
|
|
145
|
-
|
|
133
|
+
await connection.sendNotification(protocol_1.ShowReferencesNotification.type, {
|
|
146
134
|
textDocument: {
|
|
147
135
|
uri: args[0],
|
|
148
136
|
},
|
|
@@ -150,12 +138,11 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
150
138
|
references: args[2],
|
|
151
139
|
});
|
|
152
140
|
}
|
|
153
|
-
})
|
|
154
|
-
connection.onCodeAction((params, token) =>
|
|
155
|
-
return worker(params.textDocument.uri, token, (service) =>
|
|
156
|
-
var _c, _d, _e;
|
|
141
|
+
});
|
|
142
|
+
connection.onCodeAction(async (params, token) => {
|
|
143
|
+
return worker(params.textDocument.uri, token, async (service) => {
|
|
157
144
|
lastCodeActionLs = service;
|
|
158
|
-
let codeActions =
|
|
145
|
+
let codeActions = await service.doCodeActions(params.textDocument.uri, params.range, params.context, token) ?? [];
|
|
159
146
|
for (const codeAction of codeActions) {
|
|
160
147
|
if (codeAction.data && typeof codeAction.data === 'object') {
|
|
161
148
|
codeAction.data.uri = params.textDocument.uri;
|
|
@@ -164,104 +151,98 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
164
151
|
codeAction.data = { uri: params.textDocument.uri };
|
|
165
152
|
}
|
|
166
153
|
}
|
|
167
|
-
if (!
|
|
154
|
+
if (!initParams.capabilities.textDocument?.codeAction?.disabledSupport) {
|
|
168
155
|
codeActions = codeActions.filter(codeAction => !codeAction.disabled);
|
|
169
156
|
}
|
|
170
157
|
return codeActions;
|
|
171
|
-
})
|
|
172
|
-
})
|
|
173
|
-
connection.onCodeActionResolve((codeAction, token) =>
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
connection.onReferences((params, token) => __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
connection.onCodeActionResolve(async (codeAction, token) => {
|
|
161
|
+
return await lastCodeActionLs.doCodeActionResolve(codeAction, token) ?? codeAction;
|
|
162
|
+
});
|
|
163
|
+
connection.onReferences(async (params, token) => {
|
|
178
164
|
return worker(params.textDocument.uri, token, service => {
|
|
179
165
|
return service.findReferences(params.textDocument.uri, params.position, token);
|
|
180
166
|
});
|
|
181
|
-
})
|
|
182
|
-
connection.onRequest(protocol_1.FindFileReferenceRequest.type, (params, token) =>
|
|
167
|
+
});
|
|
168
|
+
connection.onRequest(protocol_1.FindFileReferenceRequest.type, async (params, token) => {
|
|
183
169
|
return worker(params.textDocument.uri, token, service => {
|
|
184
170
|
return service.findFileReferences(params.textDocument.uri, token);
|
|
185
171
|
});
|
|
186
|
-
})
|
|
187
|
-
connection.onImplementation((params, token) =>
|
|
172
|
+
});
|
|
173
|
+
connection.onImplementation(async (params, token) => {
|
|
188
174
|
return worker(params.textDocument.uri, token, service => {
|
|
189
175
|
return service.findImplementations(params.textDocument.uri, params.position, token);
|
|
190
176
|
});
|
|
191
|
-
})
|
|
192
|
-
connection.onDefinition((params, token) =>
|
|
177
|
+
});
|
|
178
|
+
connection.onDefinition(async (params, token) => {
|
|
193
179
|
return worker(params.textDocument.uri, token, service => {
|
|
194
180
|
return service.findDefinition(params.textDocument.uri, params.position, token);
|
|
195
181
|
});
|
|
196
|
-
})
|
|
197
|
-
connection.onTypeDefinition((params, token) =>
|
|
182
|
+
});
|
|
183
|
+
connection.onTypeDefinition(async (params, token) => {
|
|
198
184
|
return worker(params.textDocument.uri, token, service => {
|
|
199
185
|
return service.findTypeDefinition(params.textDocument.uri, params.position, token);
|
|
200
186
|
});
|
|
201
|
-
})
|
|
202
|
-
connection.onDocumentHighlight((params, token) =>
|
|
187
|
+
});
|
|
188
|
+
connection.onDocumentHighlight(async (params, token) => {
|
|
203
189
|
return worker(params.textDocument.uri, token, service => {
|
|
204
190
|
return service.findDocumentHighlights(params.textDocument.uri, params.position, token);
|
|
205
191
|
});
|
|
206
|
-
})
|
|
207
|
-
connection.onDocumentLinks((params, token) =>
|
|
208
|
-
return
|
|
192
|
+
});
|
|
193
|
+
connection.onDocumentLinks(async (params, token) => {
|
|
194
|
+
return await worker(params.textDocument.uri, token, service => {
|
|
209
195
|
return service.findDocumentLinks(params.textDocument.uri, token);
|
|
210
196
|
});
|
|
211
|
-
})
|
|
212
|
-
connection.onWorkspaceSymbol((params, token) =>
|
|
197
|
+
});
|
|
198
|
+
connection.onWorkspaceSymbol(async (params, token) => {
|
|
213
199
|
let results = [];
|
|
214
200
|
for (const _workspace of projects.workspaces.values()) {
|
|
215
|
-
const workspace =
|
|
201
|
+
const workspace = await _workspace;
|
|
216
202
|
let projects = [...workspace.projects.values()];
|
|
217
203
|
projects = projects.length ? projects : [workspace.getInferredProject()];
|
|
218
204
|
for (const project of projects) {
|
|
219
205
|
if (token.isCancellationRequested)
|
|
220
206
|
return;
|
|
221
|
-
const service = (
|
|
222
|
-
results = results.concat(
|
|
207
|
+
const service = (await project).getLanguageService();
|
|
208
|
+
results = results.concat(await service.findWorkspaceSymbols(params.query, token));
|
|
223
209
|
}
|
|
224
210
|
}
|
|
225
211
|
return results;
|
|
226
|
-
})
|
|
227
|
-
connection.languages.callHierarchy.onPrepare((params, token) =>
|
|
228
|
-
|
|
229
|
-
return (_g = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
});
|
|
213
|
+
connection.languages.callHierarchy.onPrepare(async (params, token) => {
|
|
214
|
+
return await worker(params.textDocument.uri, token, async (service) => {
|
|
230
215
|
lastCallHierarchyLs = service;
|
|
231
216
|
return service.callHierarchy.doPrepare(params.textDocument.uri, params.position, token);
|
|
232
|
-
})
|
|
233
|
-
})
|
|
234
|
-
connection.languages.callHierarchy.onIncomingCalls((params, token) =>
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}))) !== null && _l !== void 0 ? _l : { data: [] };
|
|
255
|
-
}));
|
|
256
|
-
connection.languages.diagnostics.on((params, token, _workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
|
|
257
|
-
const result = yield worker(params.textDocument.uri, token, service => {
|
|
217
|
+
}) ?? [];
|
|
218
|
+
});
|
|
219
|
+
connection.languages.callHierarchy.onIncomingCalls(async (params, token) => {
|
|
220
|
+
return await lastCallHierarchyLs?.callHierarchy.getIncomingCalls(params.item, token) ?? [];
|
|
221
|
+
});
|
|
222
|
+
connection.languages.callHierarchy.onOutgoingCalls(async (params, token) => {
|
|
223
|
+
return await lastCallHierarchyLs?.callHierarchy.getOutgoingCalls(params.item, token) ?? [];
|
|
224
|
+
});
|
|
225
|
+
connection.languages.semanticTokens.on(async (params, token, _, resultProgress) => {
|
|
226
|
+
await sleep(200);
|
|
227
|
+
return await worker(params.textDocument.uri, token, async (service) => {
|
|
228
|
+
return await service?.getSemanticTokens(params.textDocument.uri, undefined, semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
|
|
229
|
+
}) ?? { data: [] };
|
|
230
|
+
});
|
|
231
|
+
connection.languages.semanticTokens.onRange(async (params, token, _, resultProgress) => {
|
|
232
|
+
await sleep(200);
|
|
233
|
+
return await worker(params.textDocument.uri, token, async (service) => {
|
|
234
|
+
return await service?.getSemanticTokens(params.textDocument.uri, params.range, semanticTokensLegend, token, tokens => resultProgress?.report(tokens));
|
|
235
|
+
}) ?? { data: [] };
|
|
236
|
+
});
|
|
237
|
+
connection.languages.diagnostics.on(async (params, token, _workDoneProgressReporter, resultProgressReporter) => {
|
|
238
|
+
const result = await worker(params.textDocument.uri, token, service => {
|
|
258
239
|
const tsToken = cancelHost.createCancellationToken(token);
|
|
259
240
|
const mode = initOptions.serverMode === types_1.ServerMode.PartialSemantic ? 'semantic'
|
|
260
241
|
: initOptions.serverMode === types_1.ServerMode.Syntactic ? 'syntactic'
|
|
261
242
|
: 'all';
|
|
262
|
-
return service.doValidation(params.textDocument.uri,
|
|
243
|
+
return service.doValidation(params.textDocument.uri, mode, tsToken, errors => {
|
|
263
244
|
// resultProgressReporter is undefined in vscode
|
|
264
|
-
resultProgressReporter
|
|
245
|
+
resultProgressReporter?.report({
|
|
265
246
|
relatedDocuments: {
|
|
266
247
|
[params.textDocument.uri]: {
|
|
267
248
|
kind: vscode.DocumentDiagnosticReportKind.Full,
|
|
@@ -273,57 +254,55 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
273
254
|
});
|
|
274
255
|
return {
|
|
275
256
|
kind: vscode.DocumentDiagnosticReportKind.Full,
|
|
276
|
-
items: result
|
|
257
|
+
items: result ?? [],
|
|
277
258
|
};
|
|
278
|
-
})
|
|
279
|
-
connection.languages.inlayHint.on((params, token) =>
|
|
280
|
-
return worker(params.textDocument.uri, token, (service) =>
|
|
259
|
+
});
|
|
260
|
+
connection.languages.inlayHint.on(async (params, token) => {
|
|
261
|
+
return worker(params.textDocument.uri, token, async (service) => {
|
|
281
262
|
return service.getInlayHints(params.textDocument.uri, params.range, token);
|
|
282
|
-
})
|
|
283
|
-
})
|
|
263
|
+
});
|
|
264
|
+
});
|
|
284
265
|
// TODO: connection.languages.inlayHint.resolve
|
|
285
|
-
connection.workspace.onWillRenameFiles((params, token) =>
|
|
286
|
-
const config =
|
|
266
|
+
connection.workspace.onWillRenameFiles(async (params, token) => {
|
|
267
|
+
const config = await connection.workspace.getConfiguration('volar.updateImportsOnFileMove.enabled');
|
|
287
268
|
if (!config) {
|
|
288
269
|
return null;
|
|
289
270
|
}
|
|
290
|
-
const _edits =
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
})) !== null && _m !== void 0 ? _m : null;
|
|
296
|
-
})));
|
|
271
|
+
const _edits = await Promise.all(params.files.map(async (file) => {
|
|
272
|
+
return await worker(file.oldUri, token, service => {
|
|
273
|
+
return service.getEditsForFileRename(file.oldUri, file.newUri, token) ?? null;
|
|
274
|
+
}) ?? null;
|
|
275
|
+
}));
|
|
297
276
|
const edits = _edits.filter((edit) => !!edit);
|
|
298
277
|
if (edits.length) {
|
|
299
278
|
embedded.mergeWorkspaceEdits(edits[0], ...edits.slice(1));
|
|
300
279
|
return edits[0];
|
|
301
280
|
}
|
|
302
281
|
return null;
|
|
303
|
-
})
|
|
304
|
-
connection.onRequest(protocol_1.AutoInsertRequest.type, (params, token) =>
|
|
282
|
+
});
|
|
283
|
+
connection.onRequest(protocol_1.AutoInsertRequest.type, async (params, token) => {
|
|
305
284
|
return worker(params.textDocument.uri, token, service => {
|
|
306
285
|
return service.doAutoInsert(params.textDocument.uri, params.position, params.options, token);
|
|
307
286
|
});
|
|
308
|
-
})
|
|
287
|
+
});
|
|
309
288
|
function worker(uri, token, cb) {
|
|
310
289
|
return new Promise(resolve => {
|
|
311
|
-
runtime.timer.setImmediate(() =>
|
|
290
|
+
runtime.timer.setImmediate(async () => {
|
|
312
291
|
if (token.isCancellationRequested) {
|
|
313
292
|
resolve(undefined);
|
|
314
293
|
return;
|
|
315
294
|
}
|
|
316
|
-
const service =
|
|
295
|
+
const service = await getLanguageService(uri);
|
|
317
296
|
if (service) {
|
|
318
297
|
try { // handle TS cancel throw
|
|
319
|
-
const result =
|
|
298
|
+
const result = await cb(service);
|
|
320
299
|
if (token.isCancellationRequested) {
|
|
321
300
|
resolve(undefined);
|
|
322
301
|
return;
|
|
323
302
|
}
|
|
324
303
|
resolve(result);
|
|
325
304
|
}
|
|
326
|
-
catch
|
|
305
|
+
catch {
|
|
327
306
|
resolve(undefined);
|
|
328
307
|
return;
|
|
329
308
|
}
|
|
@@ -331,19 +310,15 @@ function register(connection, projects, initParams, initOptions, cancelHost, sem
|
|
|
331
310
|
else {
|
|
332
311
|
resolve(undefined);
|
|
333
312
|
}
|
|
334
|
-
})
|
|
313
|
+
});
|
|
335
314
|
});
|
|
336
315
|
}
|
|
337
|
-
function getLanguageService(uri) {
|
|
338
|
-
|
|
339
|
-
return
|
|
340
|
-
const project = (_a = (yield projects.getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
|
|
341
|
-
return project === null || project === void 0 ? void 0 : project.getLanguageService();
|
|
342
|
-
});
|
|
316
|
+
async function getLanguageService(uri) {
|
|
317
|
+
const project = (await projects.getProject(uri))?.project;
|
|
318
|
+
return project?.getLanguageService();
|
|
343
319
|
}
|
|
344
320
|
function fixTextEdit(item) {
|
|
345
|
-
|
|
346
|
-
const insertReplaceSupport = (_d = (_c = (_b = (_a = initParams.capabilities.textDocument) === null || _a === void 0 ? void 0 : _a.completion) === null || _b === void 0 ? void 0 : _b.completionItem) === null || _c === void 0 ? void 0 : _c.insertReplaceSupport) !== null && _d !== void 0 ? _d : false;
|
|
321
|
+
const insertReplaceSupport = initParams.capabilities.textDocument?.completion?.completionItem?.insertReplaceSupport ?? false;
|
|
347
322
|
if (!insertReplaceSupport) {
|
|
348
323
|
if (item.textEdit && vscode.InsertReplaceEdit.is(item.textEdit)) {
|
|
349
324
|
item.textEdit = vscode.TextEdit.replace(item.textEdit.insert, item.textEdit.newText);
|