volar-service-typescript 0.0.27 → 0.0.29

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.
Files changed (2) hide show
  1. package/index.js +65 -33
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -178,8 +178,8 @@ function create(ts) {
178
178
  }
179
179
  },
180
180
  };
181
- let syntacticHostCtx = {
182
- projectVersion: 0,
181
+ const syntacticHostCtx = {
182
+ projectVersion: -1,
183
183
  document: undefined,
184
184
  fileName: '',
185
185
  fileVersion: 0,
@@ -241,24 +241,28 @@ function create(ts) {
241
241
  languageServiceHost,
242
242
  languageService,
243
243
  ts,
244
- uriToFileName: uri => {
245
- const [_virtualCode, file] = context.documents.getVirtualCodeByUri(uri);
246
- if (file) {
247
- return context.env.typescript.uriToFileName(file.id);
248
- }
249
- else {
250
- return context.env.typescript.uriToFileName(uri);
244
+ uriToFileName(uri) {
245
+ const virtualScript = getVirtualScriptByUri(uri);
246
+ if (virtualScript) {
247
+ return virtualScript.fileName;
251
248
  }
249
+ return context.env.typescript.uriToFileName(uri);
252
250
  },
253
- fileNameToUri: fileName => {
251
+ fileNameToUri(fileName) {
254
252
  const uri = context.env.typescript.fileNameToUri(fileName);
255
- const file = context.language.files.get(uri);
256
- if (file?.generated) {
257
- const script = file.generated.languagePlugin.typescript?.getScript(file.generated.code);
258
- if (script) {
259
- return context.documents.getVirtualCodeUri(uri, script.code.id);
253
+ const sourceFile = context.language.files.get(uri);
254
+ const extraScript = context.language.typescript.getExtraScript(fileName);
255
+ let virtualCode = extraScript?.code;
256
+ if (!virtualCode && sourceFile?.generated?.languagePlugin.typescript) {
257
+ const mainScript = sourceFile.generated.languagePlugin.typescript.getScript(sourceFile.generated.code);
258
+ if (mainScript) {
259
+ virtualCode = mainScript.code;
260
260
  }
261
261
  }
262
+ if (virtualCode) {
263
+ const sourceFile = context.language.files.getByVirtualCode(virtualCode);
264
+ return context.documents.getVirtualCodeUri(sourceFile.id, virtualCode.id);
265
+ }
262
266
  return uri;
263
267
  },
264
268
  getTextDocument(uri) {
@@ -306,7 +310,7 @@ function create(ts) {
306
310
  languageService.dispose();
307
311
  },
308
312
  async provideCompletionItems(document, position, completeContext, token) {
309
- if (!(0, shared_1.isTsDocument)(document))
313
+ if (!isSemanticDocument(document))
310
314
  return;
311
315
  const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.enabled') ?? true;
312
316
  if (!enable) {
@@ -348,21 +352,21 @@ function create(ts) {
348
352
  });
349
353
  },
350
354
  provideRenameRange(document, position, token) {
351
- if (!(0, shared_1.isTsDocument)(document))
355
+ if (!isSemanticDocument(document))
352
356
  return;
353
357
  return worker(token, () => {
354
358
  return doPrepareRename(document.uri, position);
355
359
  });
356
360
  },
357
361
  provideRenameEdits(document, position, newName, token) {
358
- if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
362
+ if (!isSemanticDocument(document, true))
359
363
  return;
360
364
  return worker(token, () => {
361
365
  return doRename(document.uri, position, newName);
362
366
  });
363
367
  },
364
368
  provideCodeActions(document, range, context, token) {
365
- if (!(0, shared_1.isTsDocument)(document))
369
+ if (!isSemanticDocument(document))
366
370
  return;
367
371
  return worker(token, () => {
368
372
  return getCodeActions(document.uri, range, context);
@@ -374,14 +378,14 @@ function create(ts) {
374
378
  });
375
379
  },
376
380
  provideInlayHints(document, range, token) {
377
- if (!(0, shared_1.isTsDocument)(document))
381
+ if (!isSemanticDocument(document))
378
382
  return;
379
383
  return worker(token, () => {
380
384
  return getInlayHints(document.uri, range);
381
385
  });
382
386
  },
383
387
  provideCallHierarchyItems(document, position, token) {
384
- if (!(0, shared_1.isTsDocument)(document))
388
+ if (!isSemanticDocument(document))
385
389
  return;
386
390
  return worker(token, () => {
387
391
  return callHierarchy.doPrepare(document.uri, position);
@@ -398,21 +402,21 @@ function create(ts) {
398
402
  });
399
403
  },
400
404
  provideDefinition(document, position, token) {
401
- if (!(0, shared_1.isTsDocument)(document))
405
+ if (!isSemanticDocument(document))
402
406
  return;
403
407
  return worker(token, () => {
404
408
  return findDefinition(document.uri, position);
405
409
  });
406
410
  },
407
411
  provideTypeDefinition(document, position, token) {
408
- if (!(0, shared_1.isTsDocument)(document))
412
+ if (!isSemanticDocument(document))
409
413
  return;
410
414
  return worker(token, () => {
411
415
  return findTypeDefinition(document.uri, position);
412
416
  });
413
417
  },
414
418
  async provideDiagnostics(document, token) {
415
- if (!(0, shared_1.isTsDocument)(document))
419
+ if (!isSemanticDocument(document))
416
420
  return;
417
421
  const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.validate.enable') ?? true;
418
422
  if (!enable) {
@@ -423,49 +427,49 @@ function create(ts) {
423
427
  });
424
428
  },
425
429
  provideSemanticDiagnostics(document, token) {
426
- if (!(0, shared_1.isTsDocument)(document))
430
+ if (!isSemanticDocument(document))
427
431
  return;
428
432
  return worker(token, () => {
429
433
  return doValidation(document.uri, { semantic: true, declaration: true });
430
434
  });
431
435
  },
432
436
  provideHover(document, position, token) {
433
- if (!(0, shared_1.isTsDocument)(document))
437
+ if (!isSemanticDocument(document))
434
438
  return;
435
439
  return worker(token, () => {
436
440
  return doHover(document.uri, position);
437
441
  });
438
442
  },
439
443
  provideImplementation(document, position, token) {
440
- if (!(0, shared_1.isTsDocument)(document))
444
+ if (!isSemanticDocument(document))
441
445
  return;
442
446
  return worker(token, () => {
443
447
  return findImplementations(document.uri, position);
444
448
  });
445
449
  },
446
450
  provideReferences(document, position, referenceContext, token) {
447
- if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
451
+ if (!isSemanticDocument(document, true))
448
452
  return;
449
453
  return worker(token, () => {
450
454
  return findReferences(document.uri, position, referenceContext);
451
455
  });
452
456
  },
453
457
  provideFileReferences(document, token) {
454
- if (!(0, shared_1.isTsDocument)(document) && !(0, shared_1.isJsonDocument)(document))
458
+ if (!isSemanticDocument(document, true))
455
459
  return;
456
460
  return worker(token, () => {
457
461
  return findFileReferences(document.uri);
458
462
  });
459
463
  },
460
464
  provideDocumentHighlights(document, position, token) {
461
- if (!(0, shared_1.isTsDocument)(document))
465
+ if (!isSemanticDocument(document))
462
466
  return;
463
467
  return worker(token, () => {
464
468
  return findDocumentHighlights(document.uri, position);
465
469
  });
466
470
  },
467
471
  provideDocumentSemanticTokens(document, range, legend, token) {
468
- if (!(0, shared_1.isTsDocument)(document))
472
+ if (!isSemanticDocument(document))
469
473
  return;
470
474
  return worker(token, () => {
471
475
  return getDocumentSemanticTokens(document.uri, range, legend);
@@ -482,20 +486,48 @@ function create(ts) {
482
486
  });
483
487
  },
484
488
  provideSelectionRanges(document, positions, token) {
485
- if (!(0, shared_1.isTsDocument)(document))
489
+ if (!isSemanticDocument(document))
486
490
  return;
487
491
  return worker(token, () => {
488
492
  return getSelectionRanges(document.uri, positions);
489
493
  });
490
494
  },
491
495
  provideSignatureHelp(document, position, context, token) {
492
- if (!(0, shared_1.isTsDocument)(document))
496
+ if (!isSemanticDocument(document))
493
497
  return;
494
498
  return worker(token, () => {
495
499
  return getSignatureHelp(document.uri, position, context);
496
500
  });
497
501
  },
498
502
  };
503
+ function isSemanticDocument(document, withJson = false) {
504
+ const virtualScript = getVirtualScriptByUri(document.uri);
505
+ if (virtualScript) {
506
+ return true;
507
+ }
508
+ if (withJson && (0, shared_1.isJsonDocument)(document)) {
509
+ return true;
510
+ }
511
+ return (0, shared_1.isTsDocument)(document);
512
+ }
513
+ function getVirtualScriptByUri(uri) {
514
+ const [virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(uri);
515
+ if (virtualCode && sourceFile.generated?.languagePlugin.typescript) {
516
+ const { getScript, getExtraScripts } = sourceFile.generated?.languagePlugin.typescript;
517
+ const sourceFileName = context.env.typescript.uriToFileName(sourceFile.id);
518
+ if (getScript(sourceFile.generated.code)?.code === virtualCode) {
519
+ return {
520
+ fileName: sourceFileName,
521
+ code: virtualCode,
522
+ };
523
+ }
524
+ for (const extraScript of getExtraScripts?.(sourceFileName, sourceFile.generated.code) ?? []) {
525
+ if (extraScript.code === virtualCode) {
526
+ return extraScript;
527
+ }
528
+ }
529
+ }
530
+ }
499
531
  async function worker(token, callback) {
500
532
  let oldSysVersion = await sys.sync?.();
501
533
  let result = await callback();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-typescript",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
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",
@@ -37,13 +37,13 @@
37
37
  "vscode-uri": "^3.0.8"
38
38
  },
39
39
  "peerDependencies": {
40
- "@volar/language-service": "~2.0",
41
- "@volar/typescript": "~2.0"
40
+ "@volar/language-service": "~2.0.1",
41
+ "@volar/typescript": "~2.0.1"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "@volar/language-service": {
45
45
  "optional": true
46
46
  }
47
47
  },
48
- "gitHead": "bc83e2d244f494e30f6f789b766e54eeaa0e7a01"
48
+ "gitHead": "6927645293abcc249e7a39c98e52b9f5a2c08469"
49
49
  }