1
- import type { VirtualCode } from '@volar/language-core' ;
1
+ import type { CodeInformation , Mapping , VirtualCode } from '@volar/language-core' ;
2
2
import { computed , signal } from 'alien-signals' ;
3
3
import type * as ts from 'typescript' ;
4
4
import { allCodeFeatures } from '../plugins' ;
@@ -8,38 +8,23 @@ import { computedSfc } from './computedSfc';
8
8
import { computedVueSfc } from './computedVueSfc' ;
9
9
10
10
export class VueVirtualCode implements VirtualCode {
11
- // sources
11
+ readonly id = 'main' ;
12
+ readonly sfc : ReturnType < typeof computedSfc > ;
12
13
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 > [ ] ;
33
21
34
22
get snapshot ( ) {
35
23
return this . _snapshot ( ) ;
36
24
}
37
25
get vueSfc ( ) {
38
26
return this . _vueSfc ( ) ;
39
27
}
40
- get sfc ( ) {
41
- return this . _sfc ;
42
- }
43
28
get embeddedCodes ( ) {
44
29
return this . _embeddedCodes ( ) ;
45
30
}
@@ -55,7 +40,19 @@ export class VueVirtualCode implements VirtualCode {
55
40
public plugins : VueLanguagePluginReturn [ ] ,
56
41
public ts : typeof import ( 'typescript' ) ,
57
42
) {
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
+ } ) ;
59
56
}
60
57
61
58
update ( newSnapshot : ts . IScriptSnapshot ) {
0 commit comments