@@ -48,7 +48,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
4848 const scope = createMemo ( ( ) => sdk ( ) . directory )
4949 const path = createPathHelpers ( scope )
5050
51- const inflight = new Map < string , Promise < void > > ( )
51+ const inflight = new Map < string , { promise : Promise < void > ; silent : boolean } > ( )
5252
5353 const [ store , setStore ] = createStore < {
5454 file : Record < string , FileState >
@@ -139,7 +139,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
139139 )
140140 }
141141
142- const setLoadError = ( file : string , message : string , notFound = false ) => {
142+ const setLoadError = ( file : string , message : string , notFound = false , silent = false ) => {
143143 if ( notFound ) removeFileContentBytes ( file )
144144 setStore (
145145 "file" ,
@@ -154,14 +154,17 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
154154 draft . content = undefined
155155 } ) ,
156156 )
157+
158+ if ( silent || ( notFound && extensions . files . opened ( ) . includes ( file ) ) ) return
159+
157160 showToast ( {
158161 variant : "error" ,
159162 title : language . t ( "toast.file.loadFailed.title" ) ,
160163 description : message ,
161164 } )
162165 }
163166
164- const load = ( input : string , options ?: { force ?: boolean } ) => {
167+ const load = ( input : string , options ?: { force ?: boolean ; silent ?: boolean } ) => {
165168 const file = path . normalize ( input )
166169
167170 if ( ! file ) return Promise . resolve ( )
@@ -174,9 +177,14 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
174177
175178 if ( ! options ?. force && current ?. loaded ) return Promise . resolve ( )
176179
180+ const silent = Boolean ( options ?. silent )
177181 const pending = inflight . get ( key )
178182
179- if ( pending ) return pending
183+ if ( pending ) {
184+ if ( ! silent ) pending . silent = false
185+
186+ return pending . promise
187+ }
180188
181189 setLoading ( file )
182190
@@ -186,7 +194,12 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
186194 ? { path : getFilename ( file ) , location : { directory : getDirectory ( file ) } }
187195 : { path : file , location : { directory } }
188196
189- const promise = serverSDK . api . file
197+ const entry = {
198+ silent,
199+ promise : Promise . resolve ( ) ,
200+ }
201+
202+ entry . promise = serverSDK . api . file
190203 . read ( request )
191204 . then ( ( data ) => {
192205 if ( scope ( ) !== directory ) return
@@ -201,15 +214,16 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
201214 file ,
202215 formatServerError ( e , language . t , language . t ( "error.chain.unknown" ) ) ,
203216 isFileNotFoundError ( e ) ,
217+ entry . silent ,
204218 )
205219 } )
206220 . finally ( ( ) => {
207221 inflight . delete ( key )
208222 } )
209223
210- inflight . set ( key , promise )
224+ inflight . set ( key , entry )
211225
212- return promise
226+ return entry . promise
213227 }
214228
215229 // Lists the parent directory instead of reading the file, so checking a path a message names transfers no content.
@@ -253,7 +267,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
253267 hasFile : ( file ) => Boolean ( store . file [ file ] ) ,
254268 isOpen : ( file ) => extensions . files . opened ( ) . includes ( file ) ,
255269 loadFile : ( file ) => {
256- void load ( file , { force : true } )
270+ void load ( file , { force : true , silent : true } )
257271 } ,
258272 node : tree . node ,
259273 isDirLoaded : tree . isLoaded ,
0 commit comments