@@ -27,7 +27,7 @@ export function createCheckerByJsonConfigBase(
2727 checkerOptions : MetaCheckerOptions = { }
2828) {
2929 rootDir = rootDir . replace ( windowsPathReg , '/' ) ;
30- return createCheckerWorker (
30+ return baseCreate (
3131 ts ,
3232 ( ) => vue . createParsedCommandLineByJson ( ts , ts . sys , rootDir , json ) ,
3333 checkerOptions ,
@@ -42,7 +42,7 @@ export function createCheckerBase(
4242 checkerOptions : MetaCheckerOptions = { }
4343) {
4444 tsconfig = tsconfig . replace ( windowsPathReg , '/' ) ;
45- return createCheckerWorker (
45+ return baseCreate (
4646 ts ,
4747 ( ) => vue . createParsedCommandLine ( ts , ts . sys , tsconfig ) ,
4848 checkerOptions ,
@@ -51,75 +51,28 @@ export function createCheckerBase(
5151 ) ;
5252}
5353
54- function createCheckerWorker (
54+ export function baseCreate (
5555 ts : typeof import ( 'typescript' ) ,
56- loadParsedCommandLine : ( ) => vue . ParsedCommandLine ,
56+ getCommandLine : ( ) => vue . ParsedCommandLine ,
5757 checkerOptions : MetaCheckerOptions ,
5858 rootPath : string ,
5959 globalComponentName : string
6060) {
61-
62- /**
63- * Original Host
64- */
65-
66- let parsedCommandLine = loadParsedCommandLine ( ) ;
67- let fileNames = parsedCommandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
61+ let commandLine = getCommandLine ( ) ;
62+ let fileNames = commandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
6863 let projectVersion = 0 ;
6964
70- const scriptSnapshots = new Map < string , ts . IScriptSnapshot > ( ) ;
7165 const projectHost : TypeScriptProjectHost = {
7266 getCurrentDirectory : ( ) => rootPath ,
7367 getProjectVersion : ( ) => projectVersion . toString ( ) ,
74- getCompilationSettings : ( ) => parsedCommandLine . options ,
68+ getCompilationSettings : ( ) => commandLine . options ,
7569 getScriptFileNames : ( ) => fileNames ,
76- getProjectReferences : ( ) => parsedCommandLine . projectReferences ,
77- getScriptSnapshot : fileName => {
78- if ( ! scriptSnapshots . has ( fileName ) ) {
79- const fileText = ts . sys . readFile ( fileName ) ;
80- if ( fileText !== undefined ) {
81- scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( fileText ) ) ;
82- }
83- }
84- return scriptSnapshots . get ( fileName ) ;
85- } ,
70+ getProjectReferences : ( ) => commandLine . projectReferences ,
8671 } ;
87-
88- return {
89- ...baseCreate ( ts , projectHost , parsedCommandLine . vueOptions , checkerOptions , globalComponentName ) ,
90- updateFile ( fileName : string , text : string ) {
91- fileName = fileName . replace ( windowsPathReg , '/' ) ;
92- scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( text ) ) ;
93- projectVersion ++ ;
94- } ,
95- deleteFile ( fileName : string ) {
96- fileName = fileName . replace ( windowsPathReg , '/' ) ;
97- fileNames = fileNames . filter ( f => f !== fileName ) ;
98- projectVersion ++ ;
99- } ,
100- reload ( ) {
101- parsedCommandLine = loadParsedCommandLine ( ) ;
102- fileNames = parsedCommandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
103- this . clearCache ( ) ;
104- } ,
105- clearCache ( ) {
106- scriptSnapshots . clear ( ) ;
107- projectVersion ++ ;
108- } ,
109- } ;
110- }
111-
112- export function baseCreate (
113- ts : typeof import ( 'typescript' ) ,
114- projectHost : TypeScriptProjectHost ,
115- vueCompilerOptions : vue . VueCompilerOptions ,
116- checkerOptions : MetaCheckerOptions ,
117- globalComponentName : string
118- ) {
11972 const globalComponentSnapshot = ts . ScriptSnapshot . fromString ( '<script setup lang="ts"></script>' ) ;
120- const metaSnapshots : Record < string , ts . IScriptSnapshot > = { } ;
73+ const scriptSnapshots = new Map < string , ts . IScriptSnapshot | undefined > ( ) ;
74+ const metaSnapshots = new Map < string , ts . IScriptSnapshot > ( ) ;
12175 const getScriptFileNames = projectHost . getScriptFileNames ;
122- const getScriptSnapshot = projectHost . getScriptSnapshot ;
12376 projectHost . getScriptFileNames = ( ) => {
12477 const names = getScriptFileNames ( ) ;
12578 return [
@@ -129,20 +82,6 @@ export function baseCreate(
12982 getMetaFileName ( globalComponentName ) ,
13083 ] ;
13184 } ;
132- projectHost . getScriptSnapshot = fileName => {
133- if ( isMetaFileName ( fileName ) ) {
134- if ( ! metaSnapshots [ fileName ] ) {
135- metaSnapshots [ fileName ] = ts . ScriptSnapshot . fromString ( getMetaScriptContent ( fileName ) ) ;
136- }
137- return metaSnapshots [ fileName ] ;
138- }
139- else if ( fileName === globalComponentName ) {
140- return globalComponentSnapshot ;
141- }
142- else {
143- return getScriptSnapshot ( fileName ) ;
144- }
145- } ;
14685
14786 const vueLanguagePlugin = vue . createVueLanguagePlugin2 < string > (
14887 ts ,
@@ -153,7 +92,7 @@ export function baseCreate(
15392 ts . sys . useCaseSensitiveFileNames
15493 ) ,
15594 projectHost . getCompilationSettings ( ) ,
156- vueCompilerOptions
95+ commandLine . vueOptions
15796 ) ;
15897 const language = vue . createLanguage (
15998 [
@@ -166,7 +105,30 @@ export function baseCreate(
166105 ] ,
167106 new vue . FileMap ( ts . sys . useCaseSensitiveFileNames ) ,
168107 fileName => {
169- const snapshot = projectHost . getScriptSnapshot ( fileName ) ;
108+ let snapshot = scriptSnapshots . get ( fileName ) ;
109+
110+ if ( fileName === globalComponentName ) {
111+ snapshot = globalComponentSnapshot ;
112+ }
113+ else if ( isMetaFileName ( fileName ) ) {
114+ if ( ! metaSnapshots . has ( fileName ) ) {
115+ metaSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( getMetaScriptContent ( fileName ) ) ) ;
116+ }
117+ snapshot = metaSnapshots . get ( fileName ) ;
118+ }
119+ else {
120+ if ( ! scriptSnapshots . has ( fileName ) ) {
121+ const fileText = ts . sys . readFile ( fileName ) ;
122+ if ( fileText !== undefined ) {
123+ scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( fileText ) ) ;
124+ }
125+ else {
126+ scriptSnapshots . set ( fileName , undefined ) ;
127+ }
128+ }
129+ snapshot = scriptSnapshots . get ( fileName ) ;
130+ }
131+
170132 if ( snapshot ) {
171133 language . scripts . set ( fileName , snapshot ) ;
172134 }
@@ -182,7 +144,7 @@ export function baseCreate(
182144 const getScriptKind = languageServiceHost . getScriptKind ?. bind ( languageServiceHost ) ;
183145 languageServiceHost . getScriptKind = fileName => {
184146 const scriptKind = getScriptKind ! ( fileName ) ;
185- if ( vueCompilerOptions . extensions . some ( ext => fileName . endsWith ( ext ) ) ) {
147+ if ( commandLine . vueOptions . extensions . some ( ext => fileName . endsWith ( ext ) ) ) {
186148 if ( scriptKind === ts . ScriptKind . JS ) {
187149 return ts . ScriptKind . TS ;
188150 }
@@ -199,6 +161,25 @@ export function baseCreate(
199161 return {
200162 getExportNames,
201163 getComponentMeta,
164+ updateFile ( fileName : string , text : string ) {
165+ fileName = fileName . replace ( windowsPathReg , '/' ) ;
166+ scriptSnapshots . set ( fileName , ts . ScriptSnapshot . fromString ( text ) ) ;
167+ projectVersion ++ ;
168+ } ,
169+ deleteFile ( fileName : string ) {
170+ fileName = fileName . replace ( windowsPathReg , '/' ) ;
171+ fileNames = fileNames . filter ( f => f !== fileName ) ;
172+ projectVersion ++ ;
173+ } ,
174+ reload ( ) {
175+ commandLine = getCommandLine ( ) ;
176+ fileNames = commandLine . fileNames . map ( path => path . replace ( windowsPathReg , '/' ) ) ;
177+ this . clearCache ( ) ;
178+ } ,
179+ clearCache ( ) {
180+ scriptSnapshots . clear ( ) ;
181+ projectVersion ++ ;
182+ } ,
202183 __internal__ : {
203184 tsLs,
204185 } ,
@@ -210,7 +191,7 @@ export function baseCreate(
210191
211192 function getMetaFileName ( fileName : string ) {
212193 return (
213- vueCompilerOptions . extensions . some ( ext => fileName . endsWith ( ext ) )
194+ commandLine . vueOptions . extensions . some ( ext => fileName . endsWith ( ext ) )
214195 ? fileName
215196 : fileName . substring ( 0 , fileName . lastIndexOf ( '.' ) )
216197 ) + '.meta.ts' ;
@@ -229,7 +210,7 @@ interface ComponentMeta<T> {
229210 exposed: ComponentExposed<T>;
230211};
231212
232- ${ vueCompilerOptions . target < 3 ? vue2TypeHelpersCode : typeHelpersCode }
213+ ${ commandLine . vueOptions . target < 3 ? vue2TypeHelpersCode : typeHelpersCode }
233214` . trim ( ) ;
234215 return code ;
235216 }
@@ -321,11 +302,11 @@ ${vueCompilerOptions.target < 3 ? vue2TypeHelpersCode : typeHelpersCode}
321302
322303 // fill defaults
323304 const printer = ts . createPrinter ( checkerOptions . printer ) ;
324- const snapshot = projectHost . getScriptSnapshot ( componentPath ) ! ;
305+ const snapshot = language . scripts . get ( componentPath ) ?. snapshot ! ;
325306
326307 const vueFile = language . scripts . get ( componentPath ) ?. generated ?. root ;
327308 const vueDefaults = vueFile && exportName === 'default'
328- ? ( vueFile instanceof vue . VueVirtualCode ? readVueComponentDefaultProps ( vueFile , printer , ts , vueCompilerOptions ) : { } )
309+ ? ( vueFile instanceof vue . VueVirtualCode ? readVueComponentDefaultProps ( vueFile , printer , ts , commandLine . vueOptions ) : { } )
329310 : { } ;
330311 const tsDefaults = ! vueFile ? readTsComponentDefaultProps (
331312 componentPath . substring ( componentPath . lastIndexOf ( '.' ) + 1 ) , // ts | js | tsx | jsx
0 commit comments