@@ -53,20 +53,14 @@ function getFileRegistryKey(
5353 return JSON . stringify ( values ) ;
5454}
5555
56- export interface _Plugin < T > extends LanguagePlugin < T , VueVirtualCode > {
57- getCanonicalFileName : ( fileName : string ) => string ;
58- pluginContext : Parameters < VueLanguagePlugin > [ 0 ] ;
59- }
60-
6156export function createVueLanguagePlugin < T > (
6257 ts : typeof import ( 'typescript' ) ,
6358 asFileName : ( scriptId : T ) => string ,
64- useCaseSensitiveFileNames : boolean ,
6559 getProjectVersion : ( ) => string ,
66- getScriptFileNames : ( ) => string [ ] | Set < string > ,
60+ isRootFile : ( fileName : string ) => boolean ,
6761 compilerOptions : ts . CompilerOptions ,
68- vueCompilerOptions : VueCompilerOptions ,
69- ) : _Plugin < T > {
62+ vueCompilerOptions : VueCompilerOptions
63+ ) : LanguagePlugin < T , VueVirtualCode > {
7064 const pluginContext : Parameters < VueLanguagePlugin > [ 0 ] = {
7165 modules : {
7266 '@vue/compiler-dom' : vueCompilerOptions . target < 3
@@ -85,16 +79,10 @@ export function createVueLanguagePlugin<T>(
8579 const vueSfcPlugin = useVueFilePlugin ( pluginContext ) ;
8680 const vitePressSfcPlugin = useMdFilePlugin ( pluginContext ) ;
8781 const petiteVueSfcPlugin = useHtmlFilePlugin ( pluginContext ) ;
88- const getCanonicalFileName = useCaseSensitiveFileNames
89- ? ( fileName : string ) => fileName
90- : ( fileName : string ) => fileName . toLowerCase ( ) ;
9182
92- let canonicalRootFileNames = new Set < string > ( ) ;
9383 let canonicalRootFileNamesVersion : string | undefined ;
9484
9585 return {
96- getCanonicalFileName,
97- pluginContext,
9886 getLanguageId ( scriptId ) {
9987 if ( vueCompilerOptions . extensions . some ( ext => asFileName ( scriptId ) . endsWith ( ext ) ) ) {
10088 return 'vue' ;
@@ -109,13 +97,11 @@ export function createVueLanguagePlugin<T>(
10997 createVirtualCode ( scriptId , languageId , snapshot ) {
11098 if ( languageId === 'vue' || languageId === 'markdown' || languageId === 'html' || languageId === 'typescriptreact-vtx' ) {
11199 const fileName = asFileName ( scriptId ) ;
112- const projectVersion = getProjectVersion ( ) ;
113- if ( projectVersion !== canonicalRootFileNamesVersion ) {
114- canonicalRootFileNames = new Set ( [ ...getScriptFileNames ( ) ] . map ( getCanonicalFileName ) ) ;
115- canonicalRootFileNamesVersion = projectVersion ;
116- }
117- if ( ! pluginContext . globalTypesHolder && canonicalRootFileNames . has ( getCanonicalFileName ( fileName ) ) ) {
118- pluginContext . globalTypesHolder = fileName ;
100+ if ( ! pluginContext . globalTypesHolder && getProjectVersion ( ) !== canonicalRootFileNamesVersion ) {
101+ canonicalRootFileNamesVersion = getProjectVersion ( ) ;
102+ if ( isRootFile ( fileName ) ) {
103+ pluginContext . globalTypesHolder = fileName ;
104+ }
119105 }
120106 const fileRegistry = getFileRegistry ( pluginContext . globalTypesHolder === fileName ) ;
121107 const code = fileRegistry . get ( fileName ) ;
0 commit comments