@@ -25,7 +25,6 @@ export function decorateLanguageServiceHost(
2525 const resolveModuleNames = languageServiceHost . resolveModuleNames ?. bind ( languageServiceHost ) ;
2626 const getScriptSnapshot = languageServiceHost . getScriptSnapshot . bind ( languageServiceHost ) ;
2727 const getScriptKind = languageServiceHost . getScriptKind ?. bind ( languageServiceHost ) ;
28- const getScriptFileNames = languageServiceHost . getScriptFileNames ?. bind ( languageServiceHost ) ;
2928
3029 // path completion
3130 if ( readDirectory ) {
@@ -52,43 +51,12 @@ export function decorateLanguageServiceHost(
5251 const getCanonicalFileName = languageServiceHost . useCaseSensitiveFileNames ?.( )
5352 ? ( fileName : string ) => fileName
5453 : ( fileName : string ) => fileName . toLowerCase ( ) ;
55- const moduleResolutionCache = ts . createModuleResolutionCache (
54+ const moduleResolutionCache = languageServiceHost . getModuleResolutionCache ?. ( ) ?? ts . createModuleResolutionCache (
5655 languageServiceHost . getCurrentDirectory ( ) ,
5756 getCanonicalFileName ,
5857 languageServiceHost . getCompilationSettings ( ) ,
5958 ) ;
6059
61- let moduleResolutionProjectVersion : string | undefined ;
62- let moduleResolutionProjectFileNames : Set < string > | undefined ;
63- const tryClearModuleResolutionCache = ( ) => {
64- const projectVersion = languageServiceHost . getProjectVersion ?.( ) ;
65- const scriptFileNames = getScriptFileNames ?.( ) ;
66- const canonicalScriptFileNames = scriptFileNames ?. map ( getCanonicalFileName ) ;
67- const filesUnchanged = Boolean (
68- canonicalScriptFileNames
69- && moduleResolutionProjectFileNames
70- && canonicalScriptFileNames . length === moduleResolutionProjectFileNames . size
71- && canonicalScriptFileNames . every ( name => moduleResolutionProjectFileNames ?. has ( name ) ) ,
72- ) ;
73-
74- if ( projectVersion === moduleResolutionProjectVersion && ( ! scriptFileNames || filesUnchanged ) ) {
75- return ;
76- }
77-
78- moduleResolutionProjectVersion = projectVersion ;
79-
80- if ( ! scriptFileNames ) {
81- moduleResolutionProjectFileNames = undefined ;
82- moduleResolutionCache . clear ( ) ;
83- return ;
84- }
85-
86- if ( ! filesUnchanged ) {
87- moduleResolutionCache . clear ( ) ;
88- }
89- moduleResolutionProjectFileNames = new Set ( canonicalScriptFileNames ?? [ ] ) ;
90- } ;
91-
9260 if ( resolveModuleNameLiterals ) {
9361 languageServiceHost . resolveModuleNameLiterals = (
9462 moduleLiterals ,
@@ -107,7 +75,6 @@ export function decorateLanguageServiceHost(
10775 options ,
10876 ) ;
10977 try {
110- tryClearModuleResolutionCache ( ) ;
11178 if ( moduleLiterals . every ( name => ! pluginExtensions . some ( ext => name . text . endsWith ( ext ) ) ) ) {
11279 return resolveModuleNameLiterals (
11380 moduleLiterals ,
@@ -144,7 +111,6 @@ export function decorateLanguageServiceHost(
144111 options ,
145112 containingSourceFile ,
146113 ) => {
147- tryClearModuleResolutionCache ( ) ;
148114 if ( moduleNames . every ( name => ! pluginExtensions . some ( ext => name . endsWith ( ext ) ) ) ) {
149115 return resolveModuleNames (
150116 moduleNames ,
0 commit comments