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.language.typescript) {
10
- currentDirectory = ctx.language.typescript.languageServiceHost.getCurrentDirectory();
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;
@@ -96,10 +96,11 @@ function create(ts, { isValidationEnabled = async (document, context) => {
96
96
  },
97
97
  },
98
98
  create(context) {
99
- if (!context.language.typescript) {
99
+ if (!context.project.typescript) {
100
+ console.warn(`[volar] typescript-semantic requires typescript project.`);
100
101
  return {};
101
102
  }
102
- const { sys, languageServiceHost, asFileName, asScriptId, getExtraServiceScript } = context.language.typescript;
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 = asScriptId(fileName);
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
- return await worker(token, async () => {
227
- const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
228
- const fileName = ctx.uriToFileName(uri);
229
- const offset = document.offsetAt(position);
230
- const info = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionsAtPosition(fileName, offset, {
231
- ...preferences,
232
- triggerCharacter: completeContext.triggerCharacter,
233
- triggerKind: completeContext.triggerKind,
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
- if (info) {
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
- return await worker(token, async () => {
252
- const data = item.data;
253
- if (!data) {
254
- return item;
255
- }
256
- const { fileName, offset } = data;
257
- const uri = vscode_uri_1.URI.parse(data.uri);
258
- const document = ctx.getTextDocument(uri);
259
- const [formatOptions, preferences] = await Promise.all([
260
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
261
- (0, getUserPreferences_1.getUserPreferences)(ctx, document),
262
- ]);
263
- const details = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionEntryDetails(fileName, offset, data.originalItem.name, formatOptions, data.originalItem.source, preferences, data.originalItem.data));
264
- if (!details) {
265
- return item;
266
- }
267
- if (data.originalItem.labelDetails) {
268
- item.labelDetails ??= {};
269
- Object.assign(item.labelDetails, data.originalItem.labelDetails);
270
- }
271
- (0, lspConverters_1.applyCompletionEntryDetails)(ts, item, details, document, ctx.fileNameToUri, ctx.getTextDocument);
272
- const useCodeSnippetsOnMethodSuggest = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.completeFunctionCalls') ?? false;
273
- const useCodeSnippet = useCodeSnippetsOnMethodSuggest
274
- && (item.kind === 3
275
- || item.kind === 2);
276
- if (useCodeSnippet) {
277
- const shouldCompleteFunction = isValidFunctionCompletionContext(ctx.languageService, fileName, offset, document);
278
- if (shouldCompleteFunction) {
279
- const { snippet, parameterCount } = (0, snippetForFunctionCall_1.snippetForFunctionCall)({
280
- 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
281
- label: item.label,
282
- }, details.displayParts);
283
- if (item.textEdit) {
284
- item.textEdit.newText = snippet;
285
- }
286
- if (item.insertText) {
287
- item.insertText = snippet;
288
- }
289
- item.insertTextFormat = 2;
290
- if (parameterCount > 0) {
291
- //Fix for https://github.com/microsoft/vscode/issues/104059
292
- //Don't show parameter hints if "editor.parameterHints.enabled": false
293
- // if (await getConfiguration('editor.parameterHints.enabled', document.uri)) {
294
- // item.command = {
295
- // title: 'triggerParameterHints',
296
- // command: 'editor.action.triggerParameterHints',
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
- return item;
303
- function isValidFunctionCompletionContext(client, filepath, offset, document) {
304
- // Workaround for https://github.com/microsoft/TypeScript/issues/12677
305
- // Don't complete function calls inside of destructive assignments or imports
306
- try {
307
- const response = client.getQuickInfoAtPosition(filepath, offset);
308
- if (response) {
309
- switch (response.kind) {
310
- case 'var':
311
- case 'let':
312
- case 'const':
313
- case 'alias':
314
- return false;
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
- }) ?? item;
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
- return worker(token, () => {
335
- const fileName = ctx.uriToFileName(uri);
336
- const offset = document.offsetAt(position);
337
- const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, renameInfoOptions));
338
- if (!renameInfo) {
339
- return;
340
- }
341
- if (!renameInfo.canRename) {
342
- return { message: renameInfo.localizedErrorMessage };
343
- }
344
- return (0, lspConverters_1.convertTextSpan)(renameInfo.triggerSpan, document);
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
- return worker(token, async () => {
353
- const fileName = ctx.uriToFileName(uri);
354
- const offset = document.offsetAt(position);
355
- const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, renameInfoOptions));
356
- if (!renameInfo?.canRename) {
357
- return;
358
- }
359
- if (renameInfo.fileToRename) {
360
- const [formatOptions, preferences] = await Promise.all([
361
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
362
- (0, getUserPreferences_1.getUserPreferences)(ctx, document),
363
- ]);
364
- return renameFile(renameInfo.fileToRename, newName, formatOptions, preferences);
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 { providePrefixAndSuffixTextForRename } = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
367
- const entries = ctx.languageService.findRenameLocations(fileName, offset, false, false, providePrefixAndSuffixTextForRename);
368
- if (!entries) {
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
- return (0, lspConverters_1.convertRenameLocations)(newName, entries, ctx.fileNameToUri, ctx.getTextDocument);
372
- function renameFile(fileToRename, newName, formatOptions, preferences) {
373
- // Make sure we preserve file extension if none provided
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
- return worker(token, () => {
402
- return getCodeActions(uri, document, range, context, formattingOptions);
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
- return await worker(token, () => {
407
- return doCodeActionResolve(codeAction, formattingOptions);
408
- }) ?? codeAction;
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
- return worker(token, async () => {
416
- const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
417
- const fileName = ctx.uriToFileName(uri);
418
- const start = document.offsetAt(range.start);
419
- const end = document.offsetAt(range.end);
420
- const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.languageService
421
- ? ctx.languageService.provideInlayHints(fileName, { start, length: end - start }, preferences)
422
- : []);
423
- if (!inlayHints) {
424
- return [];
425
- }
426
- return inlayHints.map(hint => (0, lspConverters_1.convertInlayHint)(hint, document));
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
- return worker(token, () => {
435
- const fileName = ctx.uriToFileName(uri);
436
- const offset = document.offsetAt(position);
437
- const calls = (0, shared_1.safeCall)(() => ctx.languageService.prepareCallHierarchy(fileName, offset));
438
- if (!calls) {
439
- return [];
440
- }
441
- const items = Array.isArray(calls) ? calls : [calls];
442
- return items.map(item => (0, lspConverters_1.convertCallHierarchyItem)(item, ctx));
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
- return await worker(token, () => {
447
- const uri = vscode_uri_1.URI.parse(item.uri);
448
- const document = ctx.getTextDocument(uri);
449
- const fileName = ctx.uriToFileName(uri);
450
- const offset = document.offsetAt(item.selectionRange.start);
451
- const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyIncomingCalls(fileName, offset));
452
- if (!calls) {
453
- return [];
454
- }
455
- const items = Array.isArray(calls) ? calls : [calls];
456
- return items.map(item => (0, lspConverters_1.convertCallHierarchyIncomingCall)(item, ctx));
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
- return await worker(token, () => {
461
- const uri = vscode_uri_1.URI.parse(item.uri);
462
- const document = ctx.getTextDocument(uri);
463
- const fileName = ctx.uriToFileName(uri);
464
- const offset = document.offsetAt(item.selectionRange.start);
465
- const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyOutgoingCalls(fileName, offset));
466
- if (!calls) {
467
- return [];
468
- }
469
- const items = Array.isArray(calls) ? calls : [calls];
470
- return items.map(item => (0, lspConverters_1.convertCallHierarchyOutgoingCall)(item, document, ctx));
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
- return worker(token, () => {
479
- const fileName = ctx.uriToFileName(uri);
480
- const offset = document.offsetAt(position);
481
- const info = (0, shared_1.safeCall)(() => ctx.languageService.getDefinitionAndBoundSpan(fileName, offset));
482
- if (!info) {
483
- return [];
484
- }
485
- return (0, lspConverters_1.convertDefinitionInfoAndBoundSpan)(info, document, ctx);
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
- return worker(token, () => {
494
- const fileName = ctx.uriToFileName(uri);
495
- const offset = document.offsetAt(position);
496
- const entries = (0, shared_1.safeCall)(() => ctx.languageService.getTypeDefinitionAtPosition(fileName, offset));
497
- if (!entries) {
498
- return [];
499
- }
500
- return entries.map(entry => (0, lspConverters_1.convertDocumentSpantoLocationLink)(entry, ctx));
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
- return worker(token, () => {
515
- const fileName = ctx.uriToFileName(uri);
516
- const offset = document.offsetAt(position);
517
- const info = (0, shared_1.safeCall)(() => ctx.languageService.getQuickInfoAtPosition(fileName, offset));
518
- if (!info) {
519
- return;
520
- }
521
- return (0, lspConverters_1.convertQuickInfo)(ts, info, document, ctx.fileNameToUri, ctx.getTextDocument);
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
- return worker(token, () => {
530
- const fileName = ctx.uriToFileName(uri);
531
- const offset = document.offsetAt(position);
532
- const entries = (0, shared_1.safeCall)(() => ctx.languageService.getImplementationAtPosition(fileName, offset));
533
- if (!entries) {
534
- return [];
535
- }
536
- return entries.map(entry => (0, lspConverters_1.convertDocumentSpantoLocationLink)(entry, ctx));
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
- return worker(token, () => {
545
- const fileName = ctx.uriToFileName(uri);
546
- const offset = document.offsetAt(position);
547
- const references = (0, shared_1.safeCall)(() => ctx.languageService.findReferences(fileName, offset));
548
- if (!references) {
549
- return [];
550
- }
551
- const result = [];
552
- for (const reference of references) {
553
- if (referenceContext.includeDeclaration) {
554
- const definition = (0, lspConverters_1.convertDocumentSpanToLocation)(reference.definition, ctx);
555
- if (definition) {
556
- result.push(definition);
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
- for (const referenceEntry of reference.references) {
560
- const reference = (0, lspConverters_1.convertDocumentSpanToLocation)(referenceEntry, ctx);
561
- if (reference) {
562
- result.push(reference);
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
- return result;
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
- return worker(token, () => {
575
- const fileName = ctx.uriToFileName(uri);
576
- const entries = (0, shared_1.safeCall)(() => ctx.languageService.getFileReferences(fileName));
577
- if (!entries) {
578
- return [];
579
- }
580
- return entries.map(entry => (0, lspConverters_1.convertDocumentSpanToLocation)(entry, ctx));
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
- return worker(token, () => {
589
- const fileName = ctx.uriToFileName(uri);
590
- const offset = document.offsetAt(position);
591
- const highlights = (0, shared_1.safeCall)(() => ctx.languageService.getDocumentHighlights(fileName, offset, [fileName]));
592
- if (!highlights) {
593
- return [];
594
- }
595
- const results = [];
596
- for (const highlight of highlights) {
597
- for (const span of highlight.highlightSpans) {
598
- results.push((0, lspConverters_1.convertHighlightSpan)(span, document));
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
- return results;
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
- return worker(token, () => {
610
- return getDocumentSemanticTokens(uri, document, range, legend);
611
- });
627
+ if (await isCancellationRequestedWhileSync(token)) {
628
+ return;
629
+ }
630
+ return getDocumentSemanticTokens(uri, document, range, legend);
612
631
  },
613
- provideWorkspaceSymbols(query, token) {
614
- return worker(token, () => {
615
- const items = (0, shared_1.safeCall)(() => ctx.languageService.getNavigateToItems(query));
616
- if (!items) {
617
- return [];
618
- }
619
- return items
620
- .filter(item => item.containerName || item.kind !== 'alias')
621
- .map(item => (0, lspConverters_1.convertNavigateToItem)(item, ctx.getTextDocument(ctx.fileNameToUri(item.fileName))))
622
- .filter(item => !!item);
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
- return worker(token, async () => {
627
- const document = ctx.getTextDocument(oldUri);
628
- const [formatOptions, preferences] = await Promise.all([
629
- (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, formattingOptions),
630
- (0, getUserPreferences_1.getUserPreferences)(ctx, document),
631
- ]);
632
- const fileToRename = ctx.uriToFileName(oldUri);
633
- const newFilePath = ctx.uriToFileName(newUri);
634
- const response = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences));
635
- if (!response?.length) {
636
- return;
637
- }
638
- return (0, lspConverters_1.convertFileTextChanges)(response, ctx.fileNameToUri, ctx.getTextDocument);
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
- return worker(token, () => {
647
- const options = {};
648
- if (context?.triggerKind === 1) {
649
- options.triggerReason = {
650
- kind: 'invoked'
651
- };
652
- }
653
- else if (context?.triggerKind === 2) {
654
- options.triggerReason = {
655
- kind: 'characterTyped',
656
- triggerCharacter: context.triggerCharacter,
657
- };
658
- }
659
- else if (context?.triggerKind === 3) {
660
- options.triggerReason = {
661
- kind: 'retrigger',
662
- triggerCharacter: context.triggerCharacter,
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
- const fileName = ctx.uriToFileName(uri);
666
- const offset = document.offsetAt(position);
667
- const helpItems = (0, shared_1.safeCall)(() => ctx.languageService.getSignatureHelpItems(fileName, offset, options));
668
- if (!helpItems) {
669
- return;
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 += ts.displayPartsToString(item.prefixDisplayParts);
681
- item.parameters.forEach((p, i, a) => {
682
- const label = ts.displayPartsToString(p.displayParts);
683
- const parameter = {
684
- label,
685
- documentation: ts.displayPartsToString(p.documentation)
686
- };
687
- signature.label += label;
688
- signature.parameters.push(parameter);
689
- if (i < a.length - 1) {
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
- return await worker(token, () => {
709
- const fileName = ctx.uriToFileName(uri);
710
- const program = ctx.languageService.getProgram();
711
- const sourceFile = program?.getSourceFile(fileName);
712
- if (!program || !sourceFile) {
713
- return [];
714
- }
715
- const token = {
716
- isCancellationRequested() {
717
- return ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested() ?? false;
718
- },
719
- throwIfCancellationRequested() { },
720
- };
721
- if (mode === 'syntactic') {
722
- const syntacticDiagnostics = (0, shared_1.safeCall)(() => program.getSyntacticDiagnostics(sourceFile, token)) ?? [];
723
- const suggestionDiagnostics = (0, shared_1.safeCall)(() => ctx.languageService.getSuggestionDiagnostics(fileName)) ?? [];
724
- return [...syntacticDiagnostics, ...suggestionDiagnostics]
725
- .map(diagnostic => (0, lspConverters_1.convertDiagnostic)(diagnostic, document, ctx.fileNameToUri, ctx.getTextDocument))
726
- .filter(diagnostic => !!diagnostic);
727
- }
728
- else if (mode === 'semantic') {
729
- const semanticDiagnostics = (0, shared_1.safeCall)(() => program.getSemanticDiagnostics(sourceFile, token)) ?? [];
730
- const declarationDiagnostics = getEmitDeclarations(program.getCompilerOptions())
731
- ? (0, shared_1.safeCall)(() => program.getDeclarationDiagnostics(sourceFile, token)) ?? []
732
- : [];
733
- return [...semanticDiagnostics, ...declarationDiagnostics]
734
- .map(diagnostic => (0, lspConverters_1.convertDiagnostic)(diagnostic, document, ctx.fileNameToUri, ctx.getTextDocument))
735
- .filter(diagnostic => !!diagnostic);
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 worker(token, fn) {
753
- let result;
754
- let oldSysVersion;
755
- let newSysVersion = await sys.sync?.();
756
- do {
757
- oldSysVersion = newSysVersion;
758
- try {
759
- result = await fn();
760
- }
761
- catch (err) {
762
- console.warn(err);
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.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()) {
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 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 15 | 22 | 26;
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.55",
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.0"
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.0"
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": "2ab1ef6c5ad543e762522f80048cd73c3aa04bb6"
47
+ "gitHead": "8ec3487544e6b06d76f66202d222170446c91264"
48
48
  }