@@ -75,12 +75,18 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
75
75
monaco . languages . typescript . typescriptDefaults . addExtraLib ( libPromiseModel . getValue ( ) , libPromiseUrl . toString ( ) ) ;
76
76
monaco . languages . typescript . typescriptDefaults . addExtraLib ( libDtsModel . getValue ( ) , libDtsUrl . toString ( ) ) ;
77
77
78
+ const scriptSnapshots = new Map < string , ts . IScriptSnapshot > ( ) ;
79
+
78
80
const host : LanguageServiceHost = {
79
81
readFile ( fileName ) {
80
- return modelsMap . value . get ( fileName ) ?. getValue ( ) ;
82
+ return modelsMap . value . get ( fileName ) ?. getValue ( )
83
+ ?? localMap . get ( fileName ) ?. getValue ( )
84
+ ?? nodeModulesMap . get ( fileName ) ?. getValue ( ) ;
81
85
} ,
82
86
fileExists ( fileName ) {
83
- return modelsMap . value . has ( fileName ) ;
87
+ return modelsMap . value . has ( fileName )
88
+ || localMap . has ( fileName )
89
+ || nodeModulesMap . has ( fileName ) ;
84
90
} ,
85
91
getCompilationSettings ( ) : ts . CompilerOptions {
86
92
console . log ( 'getCompilationSettings' ) ;
@@ -112,16 +118,15 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
112
118
} ,
113
119
getScriptSnapshot ( fileName : string ) : ts . IScriptSnapshot | undefined {
114
120
console . log ( 'getScriptSnapshot' , fileName ) ;
115
- if ( localMap . has ( fileName ) ) {
116
- return ts . ScriptSnapshot . fromString ( localMap . get ( fileName ) ! . getValue ( ) ) ;
117
- }
118
- if ( nodeModulesMap . has ( fileName ) ) {
119
- return ts . ScriptSnapshot . fromString ( nodeModulesMap . get ( fileName ) ! . getValue ( ) ) ;
120
- }
121
- if ( modelsMap . value . has ( fileName ) ) {
122
- return ts . ScriptSnapshot . fromString ( modelsMap . value . get ( fileName ) ! . getValue ( ) ) ;
121
+ let scriptSnapshot = scriptSnapshots . get ( fileName ) ;
122
+ if ( ! scriptSnapshot || scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) !== this . readFile ( fileName ) ) {
123
+ const fileContent = this . readFile ( fileName ) ;
124
+ if ( fileContent !== undefined ) {
125
+ scriptSnapshot = ts . ScriptSnapshot . fromString ( fileContent ) ;
126
+ scriptSnapshots . set ( fileName , scriptSnapshot ) ;
127
+ }
123
128
}
124
- return undefined ;
129
+ return scriptSnapshot ;
125
130
} ,
126
131
getCurrentDirectory ( ) : string {
127
132
console . log ( 'getCurrentDirectory' ) ;
0 commit comments