1
- import { ResourceSaveOptions } from '@theia/core/lib/common/resource' ;
2
- import { Readable } from '@theia/core/lib/common/stream' ;
3
1
import URI from '@theia/core/lib/common/uri' ;
4
2
import { injectable } from '@theia/core/shared/inversify' ;
5
3
import {
@@ -11,14 +9,13 @@ import { FileService } from '@theia/filesystem/lib/browser/file-service';
11
9
import {
12
10
FileOperationError ,
13
11
FileOperationResult ,
14
- FileStat ,
15
12
} from '@theia/filesystem/lib/common/files' ;
16
13
import * as PQueue from 'p-queue' ;
17
14
18
15
@injectable ( )
19
16
export class FileResourceResolver extends TheiaFileResourceResolver {
20
17
override async resolve ( uri : URI ) : Promise < WriteQueuedFileResource > {
21
- let stat : FileStat | undefined ;
18
+ let stat ;
22
19
try {
23
20
stat = await this . fileService . resolve ( uri ) ;
24
21
} catch ( e ) {
@@ -37,6 +34,7 @@ export class FileResourceResolver extends TheiaFileResourceResolver {
37
34
) ;
38
35
}
39
36
return new WriteQueuedFileResource ( uri , this . fileService , {
37
+ isReadonly : stat ?. isReadonly ?? false ,
40
38
shouldOverwrite : ( ) => this . shouldOverwrite ( uri ) ,
41
39
shouldOpenAsText : ( error ) => this . shouldOpenAsText ( uri , error ) ,
42
40
} ) ;
@@ -52,23 +50,32 @@ class WriteQueuedFileResource extends FileResource {
52
50
options : FileResourceOptions
53
51
) {
54
52
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
+ }
55
70
const originalSaveContentChanges = this [ 'saveContentChanges' ] ;
56
71
if ( originalSaveContentChanges ) {
57
- this [ 'saveContentChanges' ] = ( changes , options ) => {
58
- return this . writeQueue . add ( ( ) =>
72
+ this [ 'saveContentChanges' ] = ( changes , options ) =>
73
+ this . writeQueue . add ( ( ) =>
59
74
originalSaveContentChanges . bind ( this ) ( changes , options )
60
75
) ;
61
- } ;
62
76
}
63
77
}
64
78
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
-
72
79
protected override async isInSync ( ) : Promise < boolean > {
73
80
// Let all the write operations finish to update the version (mtime) before checking whether the resource is in sync.
74
81
// https://github.com/eclipse-theia/theia/issues/12327
0 commit comments