1- import type { VirtualCode } from '@volar/language-core' ;
1+ import type { CodeInformation , Mapping , VirtualCode } from '@volar/language-core' ;
22import { computed , signal } from 'alien-signals' ;
33import type * as ts from 'typescript' ;
44import { allCodeFeatures } from '../plugins' ;
@@ -8,38 +8,23 @@ import { computedSfc } from './computedSfc';
88import { computedVueSfc } from './computedVueSfc' ;
99
1010export class VueVirtualCode implements VirtualCode {
11- // sources
11+ readonly id = 'main' ;
12+ readonly sfc : ReturnType < typeof computedSfc > ;
1213
13- id = 'main' ;
14-
15- private _snapshot = signal < ts . IScriptSnapshot > ( undefined ! ) ;
16-
17- // computeds
18-
19- private _vueSfc = computedVueSfc ( this . plugins , this . fileName , this . languageId , this . _snapshot ) ;
20- private _sfc = computedSfc ( this . ts , this . plugins , this . fileName , this . _snapshot , this . _vueSfc ) ;
21- private _embeddedCodes = computedEmbeddedCodes ( this . plugins , this . fileName , this . _sfc ) ;
22- private _mappings = computed ( ( ) => {
23- const snapshot = this . _snapshot ( ) ;
24- return [ {
25- sourceOffsets : [ 0 ] ,
26- generatedOffsets : [ 0 ] ,
27- lengths : [ snapshot . getLength ( ) ] ,
28- data : allCodeFeatures ,
29- } ] ;
30- } ) ;
31-
32- // others
14+ private _snapshot : {
15+ ( ) : ts . IScriptSnapshot ;
16+ ( value : ts . IScriptSnapshot ) : void ;
17+ } ;
18+ private _vueSfc : ReturnType < typeof computedVueSfc > ;
19+ private _embeddedCodes : ReturnType < typeof computedEmbeddedCodes > ;
20+ private _mappings : ( ) => Mapping < CodeInformation > [ ] ;
3321
3422 get snapshot ( ) {
3523 return this . _snapshot ( ) ;
3624 }
3725 get vueSfc ( ) {
3826 return this . _vueSfc ( ) ;
3927 }
40- get sfc ( ) {
41- return this . _sfc ;
42- }
4328 get embeddedCodes ( ) {
4429 return this . _embeddedCodes ( ) ;
4530 }
@@ -55,7 +40,19 @@ export class VueVirtualCode implements VirtualCode {
5540 public plugins : VueLanguagePluginReturn [ ] ,
5641 public ts : typeof import ( 'typescript' ) ,
5742 ) {
58- this . _snapshot ( initSnapshot ) ;
43+ this . _snapshot = signal ( initSnapshot ) ;
44+ this . _vueSfc = computedVueSfc ( this . plugins , this . fileName , this . languageId , this . _snapshot ) ;
45+ this . sfc = computedSfc ( this . ts , this . plugins , this . fileName , this . _snapshot , this . _vueSfc ) ;
46+ this . _embeddedCodes = computedEmbeddedCodes ( this . plugins , this . fileName , this . sfc ) ;
47+ this . _mappings = computed ( ( ) => {
48+ const snapshot = this . _snapshot ( ) ;
49+ return [ {
50+ sourceOffsets : [ 0 ] ,
51+ generatedOffsets : [ 0 ] ,
52+ lengths : [ snapshot . getLength ( ) ] ,
53+ data : allCodeFeatures ,
54+ } ] ;
55+ } ) ;
5956 }
6057
6158 update ( newSnapshot : ts . IScriptSnapshot ) {
0 commit comments