1- import { ResourceSaveOptions } from '@theia/core/lib/common/resource' ;
2- import { Readable } from '@theia/core/lib/common/stream' ;
31import URI from '@theia/core/lib/common/uri' ;
42import { injectable } from '@theia/core/shared/inversify' ;
53import {
@@ -11,14 +9,13 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service';
119import {
1210 FileOperationError ,
1311 FileOperationResult ,
14- FileStat ,
1512} from '@theia/filesystem/lib/common/files' ;
1613import * as PQueue from 'p-queue' ;
1714
1815@injectable ( )
1916export class FileResourceResolver extends TheiaFileResourceResolver {
2017 override async resolve ( uri : URI ) : Promise < WriteQueuedFileResource > {
21- let stat : FileStat | undefined ;
18+ let stat ;
2219 try {
2320 stat = await this . fileService . resolve ( uri ) ;
2421 } catch ( e ) {
@@ -37,6 +34,7 @@ export class FileResourceResolver extends TheiaFileResourceResolver {
3734 ) ;
3835 }
3936 return new WriteQueuedFileResource ( uri , this . fileService , {
37+ isReadonly : stat ?. isReadonly ?? false ,
4038 shouldOverwrite : ( ) => this . shouldOverwrite ( uri ) ,
4139 shouldOpenAsText : ( error ) => this . shouldOpenAsText ( uri , error ) ,
4240 } ) ;
@@ -52,23 +50,32 @@ class WriteQueuedFileResource extends FileResource {
5250 options : FileResourceOptions
5351 ) {
5452 super ( uri , fileService , options ) ;
53+ const originalDoWrite = this [ 'doWrite' ] ;
54+ this [ 'doWrite' ] = ( content , options ) =>
55+ this . writeQueue . add ( ( ) => originalDoWrite . bind ( this ) ( content , options ) ) ;
56+ const originalSaveStream = this [ 'saveStream' ] ;
57+ if ( originalSaveStream ) {
58+ this [ 'saveStream' ] = ( content , options ) =>
59+ this . writeQueue . add ( ( ) =>
60+ originalSaveStream . bind ( this ) ( content , options )
61+ ) ;
62+ }
63+ const originalSaveContents = this [ 'saveContents' ] ;
64+ if ( originalSaveContents ) {
65+ this [ 'saveContents' ] = ( content , options ) =>
66+ this . writeQueue . add ( ( ) =>
67+ originalSaveContents . bind ( this ) ( content , options )
68+ ) ;
69+ }
5570 const originalSaveContentChanges = this [ 'saveContentChanges' ] ;
5671 if ( originalSaveContentChanges ) {
57- this [ 'saveContentChanges' ] = ( changes , options ) => {
58- return this . writeQueue . add ( ( ) =>
72+ this [ 'saveContentChanges' ] = ( changes , options ) =>
73+ this . writeQueue . add ( ( ) =>
5974 originalSaveContentChanges . bind ( this ) ( changes , options )
6075 ) ;
61- } ;
6276 }
6377 }
6478
65- protected override async doWrite (
66- content : string | Readable < string > ,
67- options ?: ResourceSaveOptions
68- ) : Promise < void > {
69- return this . writeQueue . add ( ( ) => super . doWrite ( content , options ) ) ;
70- }
71-
7279 protected override async isInSync ( ) : Promise < boolean > {
7380 // Let all the write operations finish to update the version (mtime) before checking whether the resource is in sync.
7481 // https://github.com/eclipse-theia/theia/issues/12327
0 commit comments