volar-service-typescript 0.0.55 → 0.0.57
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.
|
@@ -6,8 +6,8 @@ const shared_1 = require("../shared");
|
|
|
6
6
|
const vscode_uri_1 = require("vscode-uri");
|
|
7
7
|
async function getUserPreferences(ctx, document) {
|
|
8
8
|
let currentDirectory = '';
|
|
9
|
-
if (ctx.
|
|
10
|
-
currentDirectory = ctx.
|
|
9
|
+
if (ctx.project.typescript) {
|
|
10
|
+
currentDirectory = ctx.project.typescript.languageServiceHost.getCurrentDirectory();
|
|
11
11
|
}
|
|
12
12
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
13
13
|
const documentUri = ctx.decodeEmbeddedDocumentUri(uri)?.[0] ?? uri;
|
package/lib/plugins/semantic.js
CHANGED
|
@@ -96,10 +96,11 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
96
96
|
},
|
|
97
97
|
},
|
|
98
98
|
create(context) {
|
|
99
|
-
if (!context.
|
|
99
|
+
if (!context.project.typescript) {
|
|
100
|
+
console.warn(`[volar] typescript-semantic requires typescript project.`);
|
|
100
101
|
return {};
|
|
101
102
|
}
|
|
102
|
-
const { sys, languageServiceHost,
|
|
103
|
+
const { sys, languageServiceHost, uriConverter, getExtraServiceScript } = context.project.typescript;
|
|
103
104
|
const created = tsWithImportCache.createLanguageService(ts, sys, languageServiceHost, proxiedHost => ts.createLanguageService(proxiedHost, getDocumentRegistry(ts, sys.useCaseSensitiveFileNames, languageServiceHost.getCurrentDirectory())));
|
|
104
105
|
const { languageService } = created;
|
|
105
106
|
const ctx = {
|
|
@@ -111,7 +112,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
111
112
|
if (virtualScript) {
|
|
112
113
|
return virtualScript.fileName;
|
|
113
114
|
}
|
|
114
|
-
return asFileName(uri);
|
|
115
|
+
return uriConverter.asFileName(uri);
|
|
115
116
|
},
|
|
116
117
|
fileNameToUri(fileName) {
|
|
117
118
|
const extraServiceScript = getExtraServiceScript(fileName);
|
|
@@ -119,7 +120,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
119
120
|
const sourceScript = context.language.scripts.fromVirtualCode(extraServiceScript.code);
|
|
120
121
|
return context.encodeEmbeddedDocumentUri(sourceScript.id, extraServiceScript.code.id);
|
|
121
122
|
}
|
|
122
|
-
const uri =
|
|
123
|
+
const uri = uriConverter.asUri(fileName);
|
|
123
124
|
const sourceScript = context.language.scripts.get(uri);
|
|
124
125
|
const serviceScript = sourceScript?.generated?.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
125
126
|
if (sourceScript && serviceScript) {
|
|
@@ -172,7 +173,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
172
173
|
updateSourceScriptFileNames();
|
|
173
174
|
}
|
|
174
175
|
for (const change of params.changes) {
|
|
175
|
-
const fileName = asFileName(vscode_uri_1.URI.parse(change.uri));
|
|
176
|
+
const fileName = uriConverter.asFileName(vscode_uri_1.URI.parse(change.uri));
|
|
176
177
|
if (sourceScriptNames.has(normalizeFileName(fileName))) {
|
|
177
178
|
created.projectUpdated?.(languageServiceHost.getCurrentDirectory());
|
|
178
179
|
}
|
|
@@ -223,282 +224,294 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
223
224
|
if (!await isSuggestionsEnabled(document, context)) {
|
|
224
225
|
return;
|
|
225
226
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
227
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
231
|
+
const fileName = ctx.uriToFileName(uri);
|
|
232
|
+
const offset = document.offsetAt(position);
|
|
233
|
+
const info = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionsAtPosition(fileName, offset, {
|
|
234
|
+
...preferences,
|
|
235
|
+
triggerCharacter: completeContext.triggerCharacter,
|
|
236
|
+
triggerKind: completeContext.triggerKind,
|
|
237
|
+
}));
|
|
238
|
+
if (info) {
|
|
239
|
+
return (0, lspConverters_1.convertCompletionInfo)(ts, info, document, position, tsEntry => ({
|
|
240
|
+
uri: document.uri,
|
|
241
|
+
fileName,
|
|
242
|
+
offset,
|
|
243
|
+
originalItem: {
|
|
244
|
+
name: tsEntry.name,
|
|
245
|
+
source: tsEntry.source,
|
|
246
|
+
data: tsEntry.data,
|
|
247
|
+
labelDetails: tsEntry.labelDetails,
|
|
248
|
+
},
|
|
234
249
|
}));
|
|
235
|
-
|
|
236
|
-
return (0, lspConverters_1.convertCompletionInfo)(ts, info, document, position, tsEntry => ({
|
|
237
|
-
uri: document.uri,
|
|
238
|
-
fileName,
|
|
239
|
-
offset,
|
|
240
|
-
originalItem: {
|
|
241
|
-
name: tsEntry.name,
|
|
242
|
-
source: tsEntry.source,
|
|
243
|
-
data: tsEntry.data,
|
|
244
|
-
labelDetails: tsEntry.labelDetails,
|
|
245
|
-
},
|
|
246
|
-
}));
|
|
247
|
-
}
|
|
248
|
-
});
|
|
250
|
+
}
|
|
249
251
|
},
|
|
250
252
|
async resolveCompletionItem(item, token) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
item.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
253
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
254
|
+
return item;
|
|
255
|
+
}
|
|
256
|
+
const data = item.data;
|
|
257
|
+
if (!data) {
|
|
258
|
+
return item;
|
|
259
|
+
}
|
|
260
|
+
const { fileName, offset } = data;
|
|
261
|
+
const uri = vscode_uri_1.URI.parse(data.uri);
|
|
262
|
+
const document = ctx.getTextDocument(uri);
|
|
263
|
+
const [formatOptions, preferences] = await Promise.all([
|
|
264
|
+
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
|
|
265
|
+
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
266
|
+
]);
|
|
267
|
+
const details = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionEntryDetails(fileName, offset, data.originalItem.name, formatOptions, data.originalItem.source, preferences, data.originalItem.data));
|
|
268
|
+
if (!details) {
|
|
269
|
+
return item;
|
|
270
|
+
}
|
|
271
|
+
if (data.originalItem.labelDetails) {
|
|
272
|
+
item.labelDetails ??= {};
|
|
273
|
+
Object.assign(item.labelDetails, data.originalItem.labelDetails);
|
|
274
|
+
}
|
|
275
|
+
(0, lspConverters_1.applyCompletionEntryDetails)(ts, item, details, document, ctx.fileNameToUri, ctx.getTextDocument);
|
|
276
|
+
const useCodeSnippetsOnMethodSuggest = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.completeFunctionCalls') ?? false;
|
|
277
|
+
const useCodeSnippet = useCodeSnippetsOnMethodSuggest
|
|
278
|
+
&& (item.kind === 3
|
|
279
|
+
|| item.kind === 2);
|
|
280
|
+
if (useCodeSnippet) {
|
|
281
|
+
const shouldCompleteFunction = isValidFunctionCompletionContext(ctx.languageService, fileName, offset, document);
|
|
282
|
+
if (shouldCompleteFunction) {
|
|
283
|
+
const { snippet, parameterCount } = (0, snippetForFunctionCall_1.snippetForFunctionCall)({
|
|
284
|
+
insertText: item.insertText ?? item.textEdit?.newText, // insertText is dropped by LSP in some case: https://github.com/microsoft/vscode-languageserver-node/blob/9b742021fb04ad081aa3676a9eecf4fa612084b4/client/src/common/codeConverter.ts#L659-L664
|
|
285
|
+
label: item.label,
|
|
286
|
+
}, details.displayParts);
|
|
287
|
+
if (item.textEdit) {
|
|
288
|
+
item.textEdit.newText = snippet;
|
|
289
|
+
}
|
|
290
|
+
if (item.insertText) {
|
|
291
|
+
item.insertText = snippet;
|
|
292
|
+
}
|
|
293
|
+
item.insertTextFormat = 2;
|
|
294
|
+
if (parameterCount > 0) {
|
|
295
|
+
//Fix for https://github.com/microsoft/vscode/issues/104059
|
|
296
|
+
//Don't show parameter hints if "editor.parameterHints.enabled": false
|
|
297
|
+
// if (await getConfiguration('editor.parameterHints.enabled', document.uri)) {
|
|
298
|
+
// item.command = {
|
|
299
|
+
// title: 'triggerParameterHints',
|
|
300
|
+
// command: 'editor.action.triggerParameterHints',
|
|
301
|
+
// };
|
|
302
|
+
// }
|
|
300
303
|
}
|
|
301
304
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
305
|
+
}
|
|
306
|
+
return item;
|
|
307
|
+
function isValidFunctionCompletionContext(client, filepath, offset, document) {
|
|
308
|
+
// Workaround for https://github.com/microsoft/TypeScript/issues/12677
|
|
309
|
+
// Don't complete function calls inside of destructive assignments or imports
|
|
310
|
+
try {
|
|
311
|
+
const response = client.getQuickInfoAtPosition(filepath, offset);
|
|
312
|
+
if (response) {
|
|
313
|
+
switch (response.kind) {
|
|
314
|
+
case 'var':
|
|
315
|
+
case 'let':
|
|
316
|
+
case 'const':
|
|
317
|
+
case 'alias':
|
|
318
|
+
return false;
|
|
316
319
|
}
|
|
317
320
|
}
|
|
318
|
-
catch {
|
|
319
|
-
// Noop
|
|
320
|
-
}
|
|
321
|
-
// Don't complete function call if there is already something that looks like a function call
|
|
322
|
-
// https://github.com/microsoft/vscode/issues/18131
|
|
323
|
-
const position = document.positionAt(offset);
|
|
324
|
-
const after = (0, lspConverters_1.getLineText)(document, position.line).slice(position.character);
|
|
325
|
-
return after.match(/^[a-z_$0-9]*\s*\(/gi) === null;
|
|
326
321
|
}
|
|
327
|
-
|
|
322
|
+
catch {
|
|
323
|
+
// Noop
|
|
324
|
+
}
|
|
325
|
+
// Don't complete function call if there is already something that looks like a function call
|
|
326
|
+
// https://github.com/microsoft/vscode/issues/18131
|
|
327
|
+
const position = document.positionAt(offset);
|
|
328
|
+
const after = (0, lspConverters_1.getLineText)(document, position.line).slice(position.character);
|
|
329
|
+
return after.match(/^[a-z_$0-9]*\s*\(/gi) === null;
|
|
330
|
+
}
|
|
328
331
|
},
|
|
329
|
-
provideRenameRange(document, position, token) {
|
|
332
|
+
async provideRenameRange(document, position, token) {
|
|
330
333
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
331
334
|
if (!isSemanticDocument(uri, document)) {
|
|
332
335
|
return;
|
|
333
336
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return
|
|
345
|
-
}
|
|
337
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const fileName = ctx.uriToFileName(uri);
|
|
341
|
+
const offset = document.offsetAt(position);
|
|
342
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, renameInfoOptions));
|
|
343
|
+
if (!renameInfo) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (!renameInfo.canRename) {
|
|
347
|
+
return { message: renameInfo.localizedErrorMessage };
|
|
348
|
+
}
|
|
349
|
+
return (0, lspConverters_1.convertTextSpan)(renameInfo.triggerSpan, document);
|
|
346
350
|
},
|
|
347
|
-
provideRenameEdits(document, position, newName, token) {
|
|
351
|
+
async provideRenameEdits(document, position, newName, token) {
|
|
348
352
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
349
353
|
if (!isSemanticDocument(uri, document, true)) {
|
|
350
354
|
return;
|
|
351
355
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
356
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const fileName = ctx.uriToFileName(uri);
|
|
360
|
+
const offset = document.offsetAt(position);
|
|
361
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, renameInfoOptions));
|
|
362
|
+
if (!renameInfo?.canRename) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (renameInfo.fileToRename) {
|
|
366
|
+
const [formatOptions, preferences] = await Promise.all([
|
|
367
|
+
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
|
|
368
|
+
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
369
|
+
]);
|
|
370
|
+
return renameFile(renameInfo.fileToRename, newName, formatOptions, preferences);
|
|
371
|
+
}
|
|
372
|
+
const { providePrefixAndSuffixTextForRename } = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
373
|
+
const entries = ctx.languageService.findRenameLocations(fileName, offset, false, false, providePrefixAndSuffixTextForRename);
|
|
374
|
+
if (!entries) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
return (0, lspConverters_1.convertRenameLocations)(newName, entries, ctx.fileNameToUri, ctx.getTextDocument);
|
|
378
|
+
function renameFile(fileToRename, newName, formatOptions, preferences) {
|
|
379
|
+
// Make sure we preserve file extension if none provided
|
|
380
|
+
if (!path.extname(newName)) {
|
|
381
|
+
newName += path.extname(fileToRename);
|
|
365
382
|
}
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
|
|
383
|
+
const dirname = path.dirname(fileToRename);
|
|
384
|
+
const newFilePath = path.join(dirname, newName);
|
|
385
|
+
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences));
|
|
386
|
+
if (!response) {
|
|
369
387
|
return;
|
|
370
388
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
if (!path.extname(newName)) {
|
|
375
|
-
newName += path.extname(fileToRename);
|
|
376
|
-
}
|
|
377
|
-
const dirname = path.dirname(fileToRename);
|
|
378
|
-
const newFilePath = path.join(dirname, newName);
|
|
379
|
-
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences));
|
|
380
|
-
if (!response) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
const edits = (0, lspConverters_1.convertFileTextChanges)(response, ctx.fileNameToUri, ctx.getTextDocument);
|
|
384
|
-
if (!edits.documentChanges) {
|
|
385
|
-
edits.documentChanges = [];
|
|
386
|
-
}
|
|
387
|
-
edits.documentChanges.push({
|
|
388
|
-
kind: 'rename',
|
|
389
|
-
oldUri: ctx.fileNameToUri(fileToRename).toString(),
|
|
390
|
-
newUri: ctx.fileNameToUri(newFilePath).toString(),
|
|
391
|
-
});
|
|
392
|
-
return edits;
|
|
389
|
+
const edits = (0, lspConverters_1.convertFileTextChanges)(response, ctx.fileNameToUri, ctx.getTextDocument);
|
|
390
|
+
if (!edits.documentChanges) {
|
|
391
|
+
edits.documentChanges = [];
|
|
393
392
|
}
|
|
394
|
-
|
|
393
|
+
edits.documentChanges.push({
|
|
394
|
+
kind: 'rename',
|
|
395
|
+
oldUri: ctx.fileNameToUri(fileToRename).toString(),
|
|
396
|
+
newUri: ctx.fileNameToUri(newFilePath).toString(),
|
|
397
|
+
});
|
|
398
|
+
return edits;
|
|
399
|
+
}
|
|
395
400
|
},
|
|
396
|
-
provideCodeActions(document, range, context, token) {
|
|
401
|
+
async provideCodeActions(document, range, context, token) {
|
|
397
402
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
398
403
|
if (!isSemanticDocument(uri, document)) {
|
|
399
404
|
return;
|
|
400
405
|
}
|
|
401
|
-
|
|
402
|
-
return
|
|
403
|
-
}
|
|
406
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
return getCodeActions(uri, document, range, context, formattingOptions);
|
|
404
410
|
},
|
|
405
411
|
async resolveCodeAction(codeAction, token) {
|
|
406
|
-
|
|
407
|
-
return
|
|
408
|
-
}
|
|
412
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
413
|
+
return codeAction;
|
|
414
|
+
}
|
|
415
|
+
return doCodeActionResolve(codeAction, formattingOptions);
|
|
409
416
|
},
|
|
410
|
-
provideInlayHints(document, range, token) {
|
|
417
|
+
async provideInlayHints(document, range, token) {
|
|
411
418
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
412
419
|
if (!isSemanticDocument(uri, document)) {
|
|
413
420
|
return;
|
|
414
421
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return
|
|
427
|
-
}
|
|
422
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
426
|
+
const fileName = ctx.uriToFileName(uri);
|
|
427
|
+
const start = document.offsetAt(range.start);
|
|
428
|
+
const end = document.offsetAt(range.end);
|
|
429
|
+
const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.languageService
|
|
430
|
+
? ctx.languageService.provideInlayHints(fileName, { start, length: end - start }, preferences)
|
|
431
|
+
: []);
|
|
432
|
+
if (!inlayHints) {
|
|
433
|
+
return [];
|
|
434
|
+
}
|
|
435
|
+
return inlayHints.map(hint => (0, lspConverters_1.convertInlayHint)(hint, document));
|
|
428
436
|
},
|
|
429
|
-
provideCallHierarchyItems(document, position, token) {
|
|
437
|
+
async provideCallHierarchyItems(document, position, token) {
|
|
430
438
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
431
439
|
if (!isSemanticDocument(uri, document)) {
|
|
432
440
|
return;
|
|
433
441
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
442
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const fileName = ctx.uriToFileName(uri);
|
|
446
|
+
const offset = document.offsetAt(position);
|
|
447
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.prepareCallHierarchy(fileName, offset));
|
|
448
|
+
if (!calls) {
|
|
449
|
+
return [];
|
|
450
|
+
}
|
|
451
|
+
const items = Array.isArray(calls) ? calls : [calls];
|
|
452
|
+
return items.map(item => (0, lspConverters_1.convertCallHierarchyItem)(item, ctx));
|
|
444
453
|
},
|
|
445
454
|
async provideCallHierarchyIncomingCalls(item, token) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
455
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
456
|
+
return [];
|
|
457
|
+
}
|
|
458
|
+
const uri = vscode_uri_1.URI.parse(item.uri);
|
|
459
|
+
const document = ctx.getTextDocument(uri);
|
|
460
|
+
const fileName = ctx.uriToFileName(uri);
|
|
461
|
+
const offset = document.offsetAt(item.selectionRange.start);
|
|
462
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyIncomingCalls(fileName, offset));
|
|
463
|
+
if (!calls) {
|
|
464
|
+
return [];
|
|
465
|
+
}
|
|
466
|
+
const items = Array.isArray(calls) ? calls : [calls];
|
|
467
|
+
return items.map(item => (0, lspConverters_1.convertCallHierarchyIncomingCall)(item, ctx));
|
|
458
468
|
},
|
|
459
469
|
async provideCallHierarchyOutgoingCalls(item, token) {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
470
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
473
|
+
const uri = vscode_uri_1.URI.parse(item.uri);
|
|
474
|
+
const document = ctx.getTextDocument(uri);
|
|
475
|
+
const fileName = ctx.uriToFileName(uri);
|
|
476
|
+
const offset = document.offsetAt(item.selectionRange.start);
|
|
477
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyOutgoingCalls(fileName, offset));
|
|
478
|
+
if (!calls) {
|
|
479
|
+
return [];
|
|
480
|
+
}
|
|
481
|
+
const items = Array.isArray(calls) ? calls : [calls];
|
|
482
|
+
return items.map(item => (0, lspConverters_1.convertCallHierarchyOutgoingCall)(item, document, ctx));
|
|
472
483
|
},
|
|
473
|
-
provideDefinition(document, position, token) {
|
|
484
|
+
async provideDefinition(document, position, token) {
|
|
474
485
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
475
486
|
if (!isSemanticDocument(uri, document)) {
|
|
476
487
|
return;
|
|
477
488
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
return
|
|
486
|
-
}
|
|
489
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const fileName = ctx.uriToFileName(uri);
|
|
493
|
+
const offset = document.offsetAt(position);
|
|
494
|
+
const info = (0, shared_1.safeCall)(() => ctx.languageService.getDefinitionAndBoundSpan(fileName, offset));
|
|
495
|
+
if (!info) {
|
|
496
|
+
return [];
|
|
497
|
+
}
|
|
498
|
+
return (0, lspConverters_1.convertDefinitionInfoAndBoundSpan)(info, document, ctx);
|
|
487
499
|
},
|
|
488
|
-
provideTypeDefinition(document, position, token) {
|
|
500
|
+
async provideTypeDefinition(document, position, token) {
|
|
489
501
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
490
502
|
if (!isSemanticDocument(uri, document)) {
|
|
491
503
|
return;
|
|
492
504
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
return
|
|
501
|
-
}
|
|
505
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const fileName = ctx.uriToFileName(uri);
|
|
509
|
+
const offset = document.offsetAt(position);
|
|
510
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getTypeDefinitionAtPosition(fileName, offset));
|
|
511
|
+
if (!entries) {
|
|
512
|
+
return [];
|
|
513
|
+
}
|
|
514
|
+
return entries.map(entry => (0, lspConverters_1.convertDocumentSpantoLocationLink)(entry, ctx));
|
|
502
515
|
},
|
|
503
516
|
provideDiagnostics(document, token) {
|
|
504
517
|
return provideDiagnosticsWorker(document, token, 'syntactic');
|
|
@@ -506,195 +519,204 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
506
519
|
provideSemanticDiagnostics(document, token) {
|
|
507
520
|
return provideDiagnosticsWorker(document, token, 'semantic');
|
|
508
521
|
},
|
|
509
|
-
provideHover(document, position, token) {
|
|
522
|
+
async provideHover(document, position, token) {
|
|
510
523
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
511
524
|
if (!isSemanticDocument(uri, document)) {
|
|
512
525
|
return;
|
|
513
526
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
return
|
|
522
|
-
}
|
|
527
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const fileName = ctx.uriToFileName(uri);
|
|
531
|
+
const offset = document.offsetAt(position);
|
|
532
|
+
const info = (0, shared_1.safeCall)(() => ctx.languageService.getQuickInfoAtPosition(fileName, offset));
|
|
533
|
+
if (!info) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
return (0, lspConverters_1.convertQuickInfo)(ts, info, document, ctx.fileNameToUri, ctx.getTextDocument);
|
|
523
537
|
},
|
|
524
|
-
provideImplementation(document, position, token) {
|
|
538
|
+
async provideImplementation(document, position, token) {
|
|
525
539
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
526
540
|
if (!isSemanticDocument(uri, document)) {
|
|
527
541
|
return;
|
|
528
542
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
return
|
|
537
|
-
}
|
|
543
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const fileName = ctx.uriToFileName(uri);
|
|
547
|
+
const offset = document.offsetAt(position);
|
|
548
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getImplementationAtPosition(fileName, offset));
|
|
549
|
+
if (!entries) {
|
|
550
|
+
return [];
|
|
551
|
+
}
|
|
552
|
+
return entries.map(entry => (0, lspConverters_1.convertDocumentSpantoLocationLink)(entry, ctx));
|
|
538
553
|
},
|
|
539
|
-
provideReferences(document, position, referenceContext, token) {
|
|
554
|
+
async provideReferences(document, position, referenceContext, token) {
|
|
540
555
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
541
556
|
if (!isSemanticDocument(uri, document, true)) {
|
|
542
557
|
return;
|
|
543
558
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
559
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const fileName = ctx.uriToFileName(uri);
|
|
563
|
+
const offset = document.offsetAt(position);
|
|
564
|
+
const references = (0, shared_1.safeCall)(() => ctx.languageService.findReferences(fileName, offset));
|
|
565
|
+
if (!references) {
|
|
566
|
+
return [];
|
|
567
|
+
}
|
|
568
|
+
const result = [];
|
|
569
|
+
for (const reference of references) {
|
|
570
|
+
if (referenceContext.includeDeclaration) {
|
|
571
|
+
const definition = (0, lspConverters_1.convertDocumentSpanToLocation)(reference.definition, ctx);
|
|
572
|
+
if (definition) {
|
|
573
|
+
result.push(definition);
|
|
558
574
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
575
|
+
}
|
|
576
|
+
for (const referenceEntry of reference.references) {
|
|
577
|
+
const reference = (0, lspConverters_1.convertDocumentSpanToLocation)(referenceEntry, ctx);
|
|
578
|
+
if (reference) {
|
|
579
|
+
result.push(reference);
|
|
564
580
|
}
|
|
565
581
|
}
|
|
566
|
-
|
|
567
|
-
|
|
582
|
+
}
|
|
583
|
+
return result;
|
|
568
584
|
},
|
|
569
|
-
provideFileReferences(document, token) {
|
|
585
|
+
async provideFileReferences(document, token) {
|
|
570
586
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
571
587
|
if (!isSemanticDocument(uri, document, true)) {
|
|
572
588
|
return;
|
|
573
589
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
return
|
|
581
|
-
}
|
|
590
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const fileName = ctx.uriToFileName(uri);
|
|
594
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getFileReferences(fileName));
|
|
595
|
+
if (!entries) {
|
|
596
|
+
return [];
|
|
597
|
+
}
|
|
598
|
+
return entries.map(entry => (0, lspConverters_1.convertDocumentSpanToLocation)(entry, ctx));
|
|
582
599
|
},
|
|
583
|
-
provideDocumentHighlights(document, position, token) {
|
|
600
|
+
async provideDocumentHighlights(document, position, token) {
|
|
584
601
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
585
602
|
if (!isSemanticDocument(uri, document)) {
|
|
586
603
|
return;
|
|
587
604
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
605
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const fileName = ctx.uriToFileName(uri);
|
|
609
|
+
const offset = document.offsetAt(position);
|
|
610
|
+
const highlights = (0, shared_1.safeCall)(() => ctx.languageService.getDocumentHighlights(fileName, offset, [fileName]));
|
|
611
|
+
if (!highlights) {
|
|
612
|
+
return [];
|
|
613
|
+
}
|
|
614
|
+
const results = [];
|
|
615
|
+
for (const highlight of highlights) {
|
|
616
|
+
for (const span of highlight.highlightSpans) {
|
|
617
|
+
results.push((0, lspConverters_1.convertHighlightSpan)(span, document));
|
|
600
618
|
}
|
|
601
|
-
|
|
602
|
-
|
|
619
|
+
}
|
|
620
|
+
return results;
|
|
603
621
|
},
|
|
604
|
-
provideDocumentSemanticTokens(document, range, legend, token) {
|
|
622
|
+
async provideDocumentSemanticTokens(document, range, legend, token) {
|
|
605
623
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
606
624
|
if (!isSemanticDocument(uri, document)) {
|
|
607
625
|
return;
|
|
608
626
|
}
|
|
609
|
-
|
|
610
|
-
return
|
|
611
|
-
}
|
|
627
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
return getDocumentSemanticTokens(uri, document, range, legend);
|
|
612
631
|
},
|
|
613
|
-
provideWorkspaceSymbols(query, token) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
return
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
632
|
+
async provideWorkspaceSymbols(query, token) {
|
|
633
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const items = (0, shared_1.safeCall)(() => ctx.languageService.getNavigateToItems(query));
|
|
637
|
+
if (!items) {
|
|
638
|
+
return [];
|
|
639
|
+
}
|
|
640
|
+
return items
|
|
641
|
+
.filter(item => item.containerName || item.kind !== 'alias')
|
|
642
|
+
.map(item => (0, lspConverters_1.convertNavigateToItem)(item, ctx.getTextDocument(ctx.fileNameToUri(item.fileName))))
|
|
643
|
+
.filter(item => !!item);
|
|
624
644
|
},
|
|
625
|
-
provideFileRenameEdits(oldUri, newUri, token) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return
|
|
639
|
-
}
|
|
645
|
+
async provideFileRenameEdits(oldUri, newUri, token) {
|
|
646
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const document = ctx.getTextDocument(oldUri);
|
|
650
|
+
const [formatOptions, preferences] = await Promise.all([
|
|
651
|
+
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
|
|
652
|
+
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
653
|
+
]);
|
|
654
|
+
const fileToRename = ctx.uriToFileName(oldUri);
|
|
655
|
+
const newFilePath = ctx.uriToFileName(newUri);
|
|
656
|
+
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences));
|
|
657
|
+
if (!response?.length) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
return (0, lspConverters_1.convertFileTextChanges)(response, ctx.fileNameToUri, ctx.getTextDocument);
|
|
640
661
|
},
|
|
641
|
-
provideSignatureHelp(document, position, context, token) {
|
|
662
|
+
async provideSignatureHelp(document, position, context, token) {
|
|
642
663
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
643
664
|
if (!isSemanticDocument(uri, document)) {
|
|
644
665
|
return;
|
|
645
666
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
667
|
+
if (await isCancellationRequestedWhileSync(token)) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const options = {};
|
|
671
|
+
if (context?.triggerKind === 1) {
|
|
672
|
+
options.triggerReason = {
|
|
673
|
+
kind: 'invoked'
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
else if (context?.triggerKind === 2) {
|
|
677
|
+
options.triggerReason = {
|
|
678
|
+
kind: 'characterTyped',
|
|
679
|
+
triggerCharacter: context.triggerCharacter,
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
else if (context?.triggerKind === 3) {
|
|
683
|
+
options.triggerReason = {
|
|
684
|
+
kind: 'retrigger',
|
|
685
|
+
triggerCharacter: context.triggerCharacter,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
const fileName = ctx.uriToFileName(uri);
|
|
689
|
+
const offset = document.offsetAt(position);
|
|
690
|
+
const helpItems = (0, shared_1.safeCall)(() => ctx.languageService.getSignatureHelpItems(fileName, offset, options));
|
|
691
|
+
if (!helpItems) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
return {
|
|
695
|
+
activeSignature: helpItems.selectedItemIndex,
|
|
696
|
+
activeParameter: helpItems.argumentIndex,
|
|
697
|
+
signatures: helpItems.items.map(item => {
|
|
698
|
+
const signature = {
|
|
699
|
+
label: '',
|
|
700
|
+
documentation: undefined,
|
|
701
|
+
parameters: []
|
|
663
702
|
};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}
|
|
671
|
-
return {
|
|
672
|
-
activeSignature: helpItems.selectedItemIndex,
|
|
673
|
-
activeParameter: helpItems.argumentIndex,
|
|
674
|
-
signatures: helpItems.items.map(item => {
|
|
675
|
-
const signature = {
|
|
676
|
-
label: '',
|
|
677
|
-
documentation: undefined,
|
|
678
|
-
parameters: []
|
|
703
|
+
signature.label += ts.displayPartsToString(item.prefixDisplayParts);
|
|
704
|
+
item.parameters.forEach((p, i, a) => {
|
|
705
|
+
const label = ts.displayPartsToString(p.displayParts);
|
|
706
|
+
const parameter = {
|
|
707
|
+
label,
|
|
708
|
+
documentation: ts.displayPartsToString(p.documentation)
|
|
679
709
|
};
|
|
680
|
-
signature.label +=
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
signature.label += ts.displayPartsToString(item.separatorDisplayParts);
|
|
691
|
-
}
|
|
692
|
-
});
|
|
693
|
-
signature.label += ts.displayPartsToString(item.suffixDisplayParts);
|
|
694
|
-
return signature;
|
|
695
|
-
}),
|
|
696
|
-
};
|
|
697
|
-
});
|
|
710
|
+
signature.label += label;
|
|
711
|
+
signature.parameters.push(parameter);
|
|
712
|
+
if (i < a.length - 1) {
|
|
713
|
+
signature.label += ts.displayPartsToString(item.separatorDisplayParts);
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
signature.label += ts.displayPartsToString(item.suffixDisplayParts);
|
|
717
|
+
return signature;
|
|
718
|
+
}),
|
|
719
|
+
};
|
|
698
720
|
},
|
|
699
721
|
};
|
|
700
722
|
async function provideDiagnosticsWorker(document, token, mode) {
|
|
@@ -705,36 +727,37 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
705
727
|
if (!await isValidationEnabled(document, context)) {
|
|
706
728
|
return;
|
|
707
729
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
730
|
+
if (mode === 'semantic' && await isCancellationRequestedWhileSync(token)) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
const fileName = ctx.uriToFileName(uri);
|
|
734
|
+
const program = ctx.languageService.getProgram();
|
|
735
|
+
const sourceFile = program?.getSourceFile(fileName);
|
|
736
|
+
if (!program || !sourceFile) {
|
|
737
|
+
return [];
|
|
738
|
+
}
|
|
739
|
+
const tsToken = {
|
|
740
|
+
isCancellationRequested() {
|
|
741
|
+
return ctx.project.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested() ?? false;
|
|
742
|
+
},
|
|
743
|
+
throwIfCancellationRequested() { },
|
|
744
|
+
};
|
|
745
|
+
if (mode === 'syntactic') {
|
|
746
|
+
const syntacticDiagnostics = (0, shared_1.safeCall)(() => program.getSyntacticDiagnostics(sourceFile, tsToken)) ?? [];
|
|
747
|
+
const suggestionDiagnostics = (0, shared_1.safeCall)(() => ctx.languageService.getSuggestionDiagnostics(fileName)) ?? [];
|
|
748
|
+
return [...syntacticDiagnostics, ...suggestionDiagnostics]
|
|
749
|
+
.map(diagnostic => (0, lspConverters_1.convertDiagnostic)(diagnostic, document, ctx.fileNameToUri, ctx.getTextDocument))
|
|
750
|
+
.filter(diagnostic => !!diagnostic);
|
|
751
|
+
}
|
|
752
|
+
else if (mode === 'semantic') {
|
|
753
|
+
const semanticDiagnostics = (0, shared_1.safeCall)(() => program.getSemanticDiagnostics(sourceFile, tsToken)) ?? [];
|
|
754
|
+
const declarationDiagnostics = getEmitDeclarations(program.getCompilerOptions())
|
|
755
|
+
? (0, shared_1.safeCall)(() => program.getDeclarationDiagnostics(sourceFile, tsToken)) ?? []
|
|
756
|
+
: [];
|
|
757
|
+
return [...semanticDiagnostics, ...declarationDiagnostics]
|
|
758
|
+
.map(diagnostic => (0, lspConverters_1.convertDiagnostic)(diagnostic, document, ctx.fileNameToUri, ctx.getTextDocument))
|
|
759
|
+
.filter(diagnostic => !!diagnostic);
|
|
760
|
+
}
|
|
738
761
|
}
|
|
739
762
|
function getEmitDeclarations(compilerOptions) {
|
|
740
763
|
return !!(compilerOptions.declaration || compilerOptions.composite);
|
|
@@ -749,22 +772,17 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
749
772
|
}
|
|
750
773
|
return (0, shared_1.isTsDocument)(document);
|
|
751
774
|
}
|
|
752
|
-
async function
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
break;
|
|
764
|
-
}
|
|
765
|
-
newSysVersion = await sys.sync?.();
|
|
766
|
-
} while (newSysVersion !== oldSysVersion && !token.isCancellationRequested);
|
|
767
|
-
return result;
|
|
775
|
+
async function isCancellationRequestedWhileSync(token) {
|
|
776
|
+
if (sys.sync) {
|
|
777
|
+
let oldSysVersion;
|
|
778
|
+
let newSysVersion = await sys.sync();
|
|
779
|
+
do {
|
|
780
|
+
oldSysVersion = newSysVersion;
|
|
781
|
+
languageService.getProgram(); // trigger sync
|
|
782
|
+
newSysVersion = await sys.sync();
|
|
783
|
+
} while (newSysVersion !== oldSysVersion && !token.isCancellationRequested);
|
|
784
|
+
}
|
|
785
|
+
return token.isCancellationRequested;
|
|
768
786
|
}
|
|
769
787
|
function getVirtualScriptByUri(uri) {
|
|
770
788
|
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
@@ -772,7 +790,7 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
772
790
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
773
791
|
if (virtualCode && sourceScript?.generated?.languagePlugin.typescript) {
|
|
774
792
|
const { getServiceScript, getExtraServiceScripts } = sourceScript.generated?.languagePlugin.typescript;
|
|
775
|
-
const sourceFileName = asFileName(sourceScript.id);
|
|
793
|
+
const sourceFileName = uriConverter.asFileName(sourceScript.id);
|
|
776
794
|
if (getServiceScript(sourceScript.generated.root)?.code === virtualCode) {
|
|
777
795
|
return {
|
|
778
796
|
fileName: sourceFileName,
|
|
@@ -7,7 +7,7 @@ function register(ts, ctx) {
|
|
|
7
7
|
const fileName = ctx.uriToFileName(uri);
|
|
8
8
|
const start = range ? document.offsetAt(range.start) : 0;
|
|
9
9
|
const length = range ? (document.offsetAt(range.end) - start) : document.getText().length;
|
|
10
|
-
if (ctx.
|
|
10
|
+
if (ctx.project.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEncodedSemanticClassifications(fileName, { start, length }, ts.SemanticClassificationFormat.TwentyTwenty));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
export declare namespace SymbolKind {
|
|
3
|
-
function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 |
|
|
3
|
+
function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 | 10 | 22 | 11 | 6 | 7 | 13 | 12 | 9 | 26 | 15;
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=typeConverters.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
4
4
|
"description": "Integrate TypeScript into Volar",
|
|
5
5
|
"homepage": "https://github.com/volarjs/services/tree/master/packages/typescript",
|
|
6
6
|
"bugs": "https://github.com/volarjs/services/issues",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/path-browserify": "latest",
|
|
28
28
|
"@types/semver": "latest",
|
|
29
|
-
"@volar/typescript": "~2.4.0-alpha.
|
|
29
|
+
"@volar/typescript": "~2.4.0-alpha.11"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"path-browserify": "^1.0.1",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"vscode-uri": "^3.0.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@volar/language-service": "~2.4.0-alpha.
|
|
40
|
+
"@volar/language-service": "~2.4.0-alpha.11"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"@volar/language-service": {
|
|
44
44
|
"optional": true
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "8ec3487544e6b06d76f66202d222170446c91264"
|
|
48
48
|
}
|